Fix some bugs when testing opensds ansible
[stor4nfv.git] / src / ceph / src / msg / async / net_handler.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- 
2 // vim: ts=8 sw=2 smarttab
3 /*
4  * Ceph - scalable distributed file system
5  *
6  * Copyright (C) 2014 UnitedStack <haomai@unitedstack.com>
7  *
8  * Author: Haomai Wang <haomaiwang@gmail.com>
9  *
10  * This is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU Lesser General Public
12  * License version 2.1, as published by the Free Software
13  * Foundation.  See file COPYING.
14  *
15  */
16
17 #ifndef CEPH_COMMON_NET_UTILS_H
18 #define CEPH_COMMON_NET_UTILS_H
19 #include "common/config.h"
20
21 namespace ceph {
22   class NetHandler {
23     int generic_connect(const entity_addr_t& addr, const entity_addr_t& bind_addr, bool nonblock);
24
25     CephContext *cct;
26    public:
27     int create_socket(int domain, bool reuse_addr=false);
28     explicit NetHandler(CephContext *c): cct(c) {}
29     int set_nonblock(int sd);
30     void set_close_on_exec(int sd);
31     int set_socket_options(int sd, bool nodelay, int size);
32     int connect(const entity_addr_t &addr, const entity_addr_t& bind_addr);
33     
34     /**
35      * Try to reconnect the socket.
36      *
37      * @return    0         success
38      *            > 0       just break, and wait for event
39      *            < 0       need to goto fail
40      */
41     int reconnect(const entity_addr_t &addr, int sd);
42     int nonblock_connect(const entity_addr_t &addr, const entity_addr_t& bind_addr);
43     void set_priority(int sd, int priority, int domain);
44   };
45 }
46
47 #endif