socket.h
Go to the documentation of this file.
1 /*
2  * RoboPeak Project
3  * HAL Layer - Socket Interface
4  * Copyright 2009 - 2013 RoboPeak Project
5  */
6 
7 #pragma once
8 
9 #include <vector>
10 
11 namespace rp{ namespace net {
12 
14 {
15 
16 public:
18  ADDRESS_TYPE_UNSPEC = 0,
19  ADDRESS_TYPE_INET = 1,
20  ADDRESS_TYPE_INET6 = 2,
21  };
22 
23 public:
24 
25 
26 
27  SocketAddress();
28  SocketAddress(const char * addrString, int port, address_type_t = ADDRESS_TYPE_INET);
29  // do not use this function, internal usage
30  SocketAddress(void * platform_data);
32 
33  SocketAddress & operator = (const SocketAddress &);
34 
35  virtual ~SocketAddress();
36 
37  virtual int getPort() const;
38  virtual u_result setPort(int port);
39 
40  virtual u_result setAddressFromString(const char * address_string, address_type_t = ADDRESS_TYPE_INET);
41  virtual u_result getAddressAsString(char * buffer, size_t buffersize) const;
42 
43  virtual address_type_t getAddressType() const;
44 
45  virtual u_result getRawAddress(_u8 * buffer, size_t bufferSize) const;
46 
47  const void * getPlatformData() const {
48  return _platform_data;
49  }
50 
51  virtual void setLoopbackAddress(address_type_t = ADDRESS_TYPE_INET);
52  virtual void setBroadcastAddressIPv4();
53  virtual void setAnyAddress(address_type_t = ADDRESS_TYPE_INET);
54 
55 public:
56  static size_t LoopUpHostName(const char * hostname, const char * sevicename, std::vector<SocketAddress> &addresspool , bool performDNS = true, address_type_t = ADDRESS_TYPE_INET);
57 
58 protected:
60 };
61 
62 
63 
64 class SocketBase
65 {
66 public:
68  SOCKET_FAMILY_INET = 0,
69  SOCKET_FAMILY_INET6 = 1,
70  SOCKET_FAMILY_RAW = 2,
71  };
72 
73 
75  SOCKET_DIR_RD = 0x1,
76  SOCKET_DIR_WR = 0x2,
77  SOCKET_DIR_BOTH = (SOCKET_DIR_RD | SOCKET_DIR_WR),
78  };
79 
80  enum {
81  DEFAULT_SOCKET_TIMEOUT = 10000, //10sec
82  };
83 
84  virtual ~SocketBase() {}
85  virtual void dispose() = 0;
86  virtual u_result bind(const SocketAddress & ) = 0;
87 
88  virtual u_result getLocalAddress(SocketAddress & ) = 0;
89  virtual u_result setTimeout(_u32 timeout, socket_direction_mask msk = SOCKET_DIR_BOTH) = 0;
90 
91  virtual u_result waitforSent(_u32 timeout = DEFAULT_SOCKET_TIMEOUT) = 0;
92  virtual u_result waitforData(_u32 timeout = DEFAULT_SOCKET_TIMEOUT) = 0;
93 protected:
94  SocketBase() {}
95 };
96 
97 
99 {
100 public:
101 
102  enum {
103  MAX_BACKLOG = 128,
104  };
105 
106  static StreamSocket * CreateSocket(socket_family_t family = SOCKET_FAMILY_INET);
107 
108  virtual u_result connect(const SocketAddress & pairAddress) = 0;
109 
110  virtual u_result listen(int backlog = MAX_BACKLOG) = 0;
111  virtual StreamSocket * accept(SocketAddress * pairAddress = NULL) = 0;
112  virtual u_result waitforIncomingConnection(_u32 timeout = DEFAULT_SOCKET_TIMEOUT) = 0;
113 
114  virtual u_result send(const void * buffer, size_t len) = 0;
115 
116  virtual u_result recv(void *buf, size_t len, size_t & recv_len) = 0;
117 
118  virtual u_result getPeerAddress(SocketAddress & ) = 0;
119 
120  virtual u_result shutdown(socket_direction_mask mask) = 0;
121 
122  virtual u_result enableKeepAlive(bool enable = true) = 0;
123 
124  virtual u_result enableNoDelay(bool enable = true) = 0;
125 
126 protected:
127  virtual ~StreamSocket() {} // use dispose();
129 };
130 
132 {
133 
134 public:
135 
136  static DGramSocket * CreateSocket(socket_family_t family = SOCKET_FAMILY_INET);
137 
138 
139 
140  virtual u_result sendTo(const SocketAddress & target, const void * buffer, size_t len) = 0;
141 
142  virtual u_result recvFrom(void *buf, size_t len, size_t & recv_len, SocketAddress * sourceAddr = NULL) = 0;
143 
144 
145 protected:
146  virtual ~DGramSocket() {} // use dispose();
147 
149 };
150 
151 }}
ROSCPP_DECL uint32_t getPort()
virtual ~StreamSocket()
Definition: socket.h:127
uint8_t _u8
Definition: rptypes.h:63
const void * getPlatformData() const
Definition: socket.h:47
#define _single_thread
Definition: types.h:84
virtual ~SocketBase()
Definition: socket.h:84
void * _platform_data
Definition: socket.h:59
uint32_t _u32
Definition: rptypes.h:69
virtual ~DGramSocket()
Definition: socket.h:146
ROSCONSOLE_DECL void shutdown()
uint32_t u_result
Definition: rptypes.h:100


rplidar_ros
Author(s):
autogenerated on Wed Mar 20 2019 07:54:15