socket_client_pos.hpp
Go to the documentation of this file.
1 
10 /*****************************************************************************
11 ** Ifdefs
12 *****************************************************************************/
13 
14 #ifndef ECL_DEVICES_SOCKET_CLIENT_POS_HPP_
15 #define ECL_DEVICES_SOCKET_CLIENT_POS_HPP_
16 
17 /*****************************************************************************
18 ** Cross platform
19 *****************************************************************************/
20 
21 #include <ecl/config/ecl.hpp>
22 #ifndef ECL_IS_APPLE
23 #ifdef ECL_IS_POSIX
24 
25 
26 /*****************************************************************************
27 ** Includes
28 *****************************************************************************/
29 
30 #include <arpa/inet.h> // inet_addr()
31 #include <errno.h>
32 #include <string>
33 #include <sys/ioctl.h> // used in remaining()
34 #include <sys/socket.h>
39 #include "traits.hpp"
40 
41 /*****************************************************************************
42 ** Namespaces
43 *****************************************************************************/
44 
45 namespace ecl {
46 
47 /*****************************************************************************
48 ** Interface [SocketClient]
49 *****************************************************************************/
64 class SocketClient {
65 public:
66  /*********************
67  ** C&D
68  **********************/
69  SocketClient() : is_open(false), error_handler(NoError) {};
81  SocketClient(const std::string &host_name, const unsigned int &port_number = 5555);
82  virtual ~SocketClient() { close(); }
84  /*********************
85  ** Configuration
86  **********************/
98  bool open( const std::string &hostname, const unsigned int& port_number );
99  void close();
101  bool open() const { return is_open; }
102 
103  /*********************
104  ** Writing
105  **********************/
114  long write(const char &c);
115 
124  long write(const char *s, unsigned long n);
125 
132  void flush() {}
133 
134  /*********************
135  ** Reading
136  **********************/
144  long remaining();
153  long read(char &c);
173  long read(char *s, const unsigned long &n);
186  long peek(char*s, const unsigned long &n);
187 
191  const Error& error() const { return error_handler; }
192 
193 private:
194  std::string hostname;
195  int port;
196  int socket_fd;
197  bool is_open;
198  ecl::Error error_handler;
199 };
200 
201 /*****************************************************************************
202 ** Traits [Serial]
203 *****************************************************************************/
209 template <>
210 class is_sink<SocketClient> : public True {};
211 
217 template <>
218 class is_source<SocketClient> : public True {};
219 
225 template <>
226 class is_sourcesink<SocketClient> : public True {};
227 
228 } // namespace ecl
229 
230 #endif /* ECL_IS_POSIX */
231 #endif /* !ECL_IS_APPLE */
232 
233 #endif /* ECL_DEVICES_SOCKET_CLIENT_POS_HPP_ */
ecl::Error
socket_connection_status.hpp
Various connection status flags.
socket_error_handler_pos.hpp
Defines error handlers for posix sockets.
ecl::NoError
NoError
True
Bool< true > True
standard_exception.hpp
macros.hpp
ecl
Embedded control libraries.


ecl_devices
Author(s): Daniel Stonier
autogenerated on Wed Mar 2 2022 00:16:45