XTL  0.1
eXtended Template Library
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
socket.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 #include <xtd/xtd.hpp>
8 
9 #if ((XTD_OS_WINDOWS | XTD_OS_MINGW) & XTD_OS)
10  #include <Ws2ipdef.h>
11  #include <ws2tcpip.h>
12  static_assert(_WIN32_WINNT >= 0x600, "unsupported target Windows version");
13  #define poll WSAPoll
14 #endif
15 
16 #if (XTD_OS_MINGW & XTD_OS)
17  #include <mswsock.h>
18 #endif
19 
20 #if ((XTD_OS_LINUX | XTD_OS_CYGWIN | XTD_OS_MSYS) & XTD_OS)
21  #include <sys/socket.h>
22  #include <sys/ioctl.h>
23  #include <netinet/in.h>
24  #include <netinet/udp.h>
25  #include <netinet/tcp.h>
26  #include <arpa/inet.h>
27  #include <poll.h>
28  #include <unistd.h>
29 #endif
30 
31 #include <type_traits>
32 #include <memory>
33 
34 #include <xtd/exception.hpp>
35 #include <xtd/string.hpp>
36 #include <xtd/meta.hpp>
37 #include <xtd/callback.hpp>
38 
39 #if (XTD_COMPILER_MSVC & XTD_COMPILER)
40  #pragma comment(lib, "ws2_32")
41 #endif
42 
43 namespace xtd{
44 
45  namespace socket{
48 #if (!DOXY_INVOKED)
49 #if ((XTD_OS_LINUX | XTD_OS_CYGWIN | XTD_OS_MSYS) & XTD_OS)
50  using SOCKET = int;
51  #define closesocket close
52  #define ioctlsocket ioctl
53 #elif (XTD_OS_WINDOWS & XTD_OS)
54  using POLLFD = pollfd;
55 #elif (XTD_OS_MINGW & XTD_OS)
56  using POLLFD = WSAPOLLFD;
57 #endif
58 #endif
59  class exception : public xtd::crt_exception{
61  public:
64  exception(const source_location& loc, const xtd::string& swhat) : crt_exception(loc, swhat){}
65  exception(const exception& ex) : crt_exception(ex){}
66  explicit exception(exception&& ex) : crt_exception(std::move(ex)){}
68 
69  template <typename _ReturnT, typename _ExpressionT>
70  inline static _ReturnT _throw_if(const xtd::source_location& source, _ReturnT ret, _ExpressionT exp, const char* expstr){
71  if (exp(ret)){
72  throw exception(source, expstr);
73  }
74  return ret;
75  }
76 
77  };
78 
79 #if (!DOXY_INVOKED)
80  namespace _{
81  template <typename _Ty, int level, int optname> class socket_option{
82  public:
83  using value_type = _Ty;
84  static value_type get(SOCKET s){
85  value_type iRet;
86  //mingw & winsock the size parameter is int while it's unsigned int on linux
87  std::remove_pointer<typename get_parameter<4, decltype(getsockopt)>::type>::type iSize = sizeof(value_type);
88  socket::exception::throw_if(getsockopt(s, level, optname, reinterpret_cast<char*>(&iRet), &iSize), [](int i){ return (i<0); });
89  return iRet;
90  }
91  static void set(SOCKET s, value_type newval){
92  socket::exception::throw_if(setsockopt(s, level, optname, reinterpret_cast<char*>(&newval), sizeof(newval)), [](int i){ return (i<0); });
93  }
94  };
95  template <int level, int optname> class socket_option<std::string, level, optname>{
96  public:
97  using value_type = std::string;
98  static value_type get(SOCKET s){
99  value_type iRet;
100  int iSize = 0;
101  socket::exception::throw_if(getsockopt(s, level, optname, reinterpret_cast<char*>(&iRet), &iSize), [](int i){ return (i<0); });
102  return iRet;
103  }
104  static void set(SOCKET s, value_type newval){
105  socket::exception::throw_if(setsockopt(s, level, optname, reinterpret_cast<char*>(&newval), sizeof(newval)), [](int i){ return (i<0); });
106  }
107  };
108 
109 
110  }
111 #endif
112 
114  class ipv4address : public sockaddr_in{
115  public:
117  static const int address_family = AF_INET;
123  ipv4address(const char * sIP, uint16_t iPort){
124  sin_family = AF_INET;
125  sin_addr.s_addr = inet_addr(sIP);
126  sin_port = htons(iPort);
127  }
128  ipv4address(const ipv4address& src){
129  memcpy(this, &src, sizeof(ipv4address));
130  }
131  ipv4address& operator=(const ipv4address& src){
132  if (&src != this) memcpy(this, &src, sizeof(ipv4address));
133  return *this;
134  }
135  };
136 
138  class ipv6address : public sockaddr_in6{
139  public:
141  static const int address_family = AF_INET6;
142  TODO("Implement proper ipv6 address");
143  };
144 
146  enum class socket_type{
147  stream = SOCK_STREAM,
148  datagram = SOCK_DGRAM,
149  raw = SOCK_RAW,
150  };
151 
153  enum class socket_protocol{
154  ip = IPPROTO_IP,
155  icmp = IPPROTO_ICMP,
156  tcp = IPPROTO_TCP,
157  udp = IPPROTO_UDP,
158  ipv6 = IPPROTO_IPV6,
159  };
160  NOTE("add more socket protocols as needed defined in netinet/in.h")
161 
162 
163  TODO("Refactor out socket::serializer into something more universal")
165  template <typename> class serializer;
166 
167 #if ((XTD_OS_WINDOWS | XTD_OS_MINGW) & XTD_OS)
168 
172  class winsock_initializer sealed{
173  public:
174  //singleton getter method
175  static winsock_initializer &get(){
176  static winsock_initializer oInit;
177  return oInit;
178  }
179  winsock_initializer(const winsock_initializer&) = delete;
180  winsock_initializer& operator=(const winsock_initializer&) = delete;
181  private:
182  winsock_initializer(){
183  WSADATA oData;
184  crt_exception::throw_if(WSAStartup(0x202, &oData), [](int err){ return 0 != err; });
185  if (oData.wVersion != 0x202) throw crt_exception(here(), "Invalid winsock version");
186  }
187 
188  ~winsock_initializer(){ WSACleanup(); }
189  };
190 #endif
191 
192 
193 #if (!DOXY_INVOKED)
194  template<typename _AddressT, socket_type, socket_protocol, template<class> class ... _Policies> class socket_base;
195 
196 
197  template<typename _AddressT, socket_type _ST, socket_protocol _PR, template<class> class _HeadT, template<class> class ..._TailT>
198  class socket_base<_AddressT, _ST, _PR, _HeadT, _TailT...> : public _HeadT<socket_base<_AddressT, _ST, _PR, _TailT...> >{
199  public:
200  template<typename ... _ArgsT> explicit socket_base(_ArgsT &&...oArgs) : _HeadT<socket_base<_AddressT, _ST, _PR, _TailT...> >(std::forward<_ArgsT>(oArgs)...){}
201  };
202 #endif
203 
207  template<typename _AddressT, socket_type _SocketT, socket_protocol _Protocol>
208  class socket_base<_AddressT, _SocketT, _Protocol>{
209  public:
210 
213  using unique_ptr = std::unique_ptr<socket_base>;
214  using shared_ptr = std::shared_ptr<socket_base>;
215  using address_type = _AddressT;
217 
220  static constexpr socket_type type = _SocketT;
221  static constexpr socket_protocol protocol = _Protocol;
223 
225  ~socket_base(){ close(); }
226 
229  socket_base() : _Socket(0){
230 #if ((XTD_OS_WINDOWS | XTD_OS_MINGW) & XTD_OS)
231  winsock_initializer::get();
232 #endif
233  _Socket = xtd::crt_exception::throw_if(::socket(address_type::address_family, (int)type, (int)protocol), [](SOCKET s){ return static_cast<SOCKET>(-1) == s; });
234  }
235 
236  explicit socket_base(socket_base&& src) : _Socket(src._Socket){
237  src._Socket = 0;
238  }
239 
240 
241  explicit socket_base(SOCKET newval) : _Socket(newval){}
242 
243  socket_base(const socket_base&) = delete;
245 
247  socket_base& operator=(const socket_base&) = delete;
248 
254  socket_base& operator=(socket_base&& src){
255  std::swap(_Socket, src._Socket);
256  return *this;
257  }
258 
263  operator SOCKET() const{ return _Socket; }
264 
265 
270  template <typename _Ty> void write(const _Ty& data){
271  serializer<_Ty>::write(*this, data);
272  }
273 
278  template <typename _Ty> void read(_Ty& data){
279  serializer<_Ty>::read(*this, data);
280  }
281 
286  template <typename _Ty> _Ty read(){
287  _Ty data;
288  serializer<_Ty>::read(*this, data);
289  return data;
290  }
291 
295  void close(){
296  if (!_Socket){
297  return;
298  }
299  ::closesocket(_Socket);
300  _Socket = -1;
301  }
302 
307  void set_blocking(bool blocking){
308  uint32_t val = (blocking ? 0 : 1);
309  xtd::crt_exception::throw_if(ioctlsocket(_Socket, FIONBIO, &val), [](int i){ return i < 0; });
310  }
311 
315  bool is_valid() const{ return -1 != _Socket; }
316 
317  protected:
319  SOCKET _Socket;
320 
321  };
322 
323 
325  template <typename _SuperT>
326  class polling_socket : public _SuperT{
327  public:
329  callback<void()> read_event;
331  callback<void()> write_event;
333  callback<void()> disconnect_event;
335  callback<void()> error_event;
337  void poll(int Timeout){
338  class pollfd oPoll;
339  oPoll.events = POLLIN | POLLOUT;
340  oPoll.fd = _SuperT::_Socket;
341  oPoll.revents = 0;
342  if (0 == xtd::crt_exception::throw_if(::poll(&oPoll, 1, Timeout), [](int i){ return i < 0; })){
343  return;
344  }
345  if (oPoll.revents & POLLERR){
346  error_event();
347  }
348  if (oPoll.revents & POLLHUP){
350  }
351  if (oPoll.revents & POLLIN){
352  read_event();
353  }
354  if (oPoll.revents & POLLOUT){
355  write_event();
356  }
357  }
359  template<typename ... _ArgTs>
360  explicit polling_socket(_ArgTs &&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
361 
362 #if ((XTD_OS_WINDOWS | XTD_OS_MINGW) & XTD_OS)
363  int poll(POLLFD *ufds, unsigned int nfds, int timeout){ return ::WSAPoll(ufds, nfds, timeout); }
364 #endif
365  };
366 
367 
369  template <typename _SuperT>
370  class bindable_socket : public _SuperT{
371  public:
372 
374  template<typename ... _ArgTs>
375  explicit bindable_socket(_ArgTs &&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
376 
378  void bind(const typename _SuperT::address_type& addr){
379  exception::throw_if(::bind(_SuperT::_Socket, reinterpret_cast<const sockaddr*>(&addr), sizeof(typename _SuperT::address_type)), [](int i){ return i < 0; });
380  }
381  };
382 
383 
385  template <typename _SuperT>
386  class connectable_socket : public _SuperT{
387  public:
388 
390  template<typename ... _ArgTs>
391  explicit connectable_socket(_ArgTs &&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
392 
394  void connect(const typename _SuperT::address_type& addr){
395  exception::throw_if(::connect(_SuperT::_Socket, reinterpret_cast<const sockaddr*>(&addr), sizeof(typename _SuperT::address_type)), [](int i){ return i < 0; });
396  }
397  };
398 
399 
401  template <typename _SuperT>
402  class listening_socket : public _SuperT{
403  public:
404 
406  template<typename ... _ArgTs>
407  explicit listening_socket(_ArgTs &&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
408 
410  void listen(int Backlog = SOMAXCONN){
411  exception::throw_if(::listen(_SuperT::_Socket, Backlog), [](int i){ return i < 0; });
412  }
413 
415  template <typename _ReturnT>
416  _ReturnT accept(){
417  return _ReturnT(exception::throw_if(::accept(_SuperT::_Socket, nullptr, nullptr), [](SOCKET s){ return (s <= 0); }));
418  }
419  };
420 
422  template <typename _SuperT>
423  class socket_options : public _SuperT{
424  public:
425 
427  template<typename ... _ArgTs>
428  explicit socket_options(_ArgTs&&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
429 
431  bool keep_alive() const{ return (_::socket_option<int, SOL_SOCKET, SO_KEEPALIVE>::get(_SuperT::_Socket) ? true : false); }
433  void keep_alive(bool newval){ _::socket_option<int, SOL_SOCKET, SO_KEEPALIVE>::set(_SuperT::_Socket, newval); }
434  TODO("Add more SOL_SOCKET options");
435  };
436 
438  template <typename _SuperT>
439  class ip_options : public _SuperT{
440  public:
441 
443  template<typename ... _ArgTs>
444  explicit ip_options(_ArgTs&&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
445 #if ((XTD_OS_MINGW | XTD_OS_WINDOWS) & XTD_OS)
446  bool dont_fragment() const{ return (_::socket_option<int, IPPROTO_IP, IP_DONTFRAGMENT>::get(_SuperT::_Socket) ? true : false); }
449  void dont_fragment(bool newval){ _::socket_option<int, IPPROTO_IP, IP_DONTFRAGMENT>::set(_SuperT::_Socket, newval); }
450 #endif
451  TODO("Add more IPPROTO_IP options");
452  };
453 
455  template <typename _SuperT>
456  class tcp_options : public _SuperT{
457  public:
458 
460  template<typename ... _ArgTs>
461  explicit tcp_options(_ArgTs&&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
462 
464  bool no_delay() const{ return (_::socket_option<int, IPPROTO_TCP, TCP_NODELAY>::get(_SuperT::_Socket) ? true : false); }
466  void no_delay(bool newval){ _::socket_option<int, IPPROTO_TCP, TCP_NODELAY>::set(_SuperT::_Socket, newval); }
467  TODO("Add more IPPROTO_TCP options");
468  };
469 
471  template <typename _SuperT>
472  class udp_options : public _SuperT{
473  public:
474 
476  template<typename ... _ArgTs>
477  explicit udp_options(_ArgTs&&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
478 
479 #if ((XTD_OS_MINGW | XTD_OS_WINDOWS) & XTD_OS)
480  bool no_checksum() const{ return (_::socket_option<int, IPPROTO_UDP, UDP_NOCHECKSUM>::get(_SuperT::_Socket) ? true : false); }
483  void no_checksum(bool newval){ _::socket_option<int, IPPROTO_UDP, UDP_NOCHECKSUM>::set(_SuperT::_Socket, newval); }
484 #endif
485  TODO("Add more IPPROTO_UDP options");
486  };
487 
488 
490  template <typename _SuperT>
491  class selectable_socket : public _SuperT{
492  public:
494  template<typename ... _ArgTs>
495  explicit selectable_socket(_ArgTs&&...oArgs) : _SuperT(std::forward<_ArgTs>(oArgs)...){}
496 
498  xtd::callback<void()> onRead;
500  xtd::callback<void()> onWrite;
502  xtd::callback<void()> onError;
503 
505  bool select(int WaitMS){
506  timeval tv;
507  fd_set fdRead;
508  fd_set fdWrite;
509  fd_set fdErr;
510  FD_ZERO(&fdRead);
511  FD_ZERO(&fdWrite);
512  FD_ZERO(&fdErr);
513  FD_SET((SOCKET)*this, &fdRead);
514  FD_SET((SOCKET)*this, &fdWrite);
515  FD_SET((SOCKET)*this, &fdErr);
516  tv.tv_sec = WaitMS / 1000;
517  WaitMS %= 1000;
518  tv.tv_usec = WaitMS / 1000;
519 #if (XTD_OS_MINGW & XTD_OS)
520  auto iRet = xtd::crt_exception::throw_if(::select(1 + (SOCKET)*this, &fdRead, &fdWrite, &fdErr, reinterpret_cast<PTIMEVAL>(&tv)), [](int i){return i < 0; });
521 #else
522  auto iRet = xtd::crt_exception::throw_if(::select(1 + (SOCKET)*this, &fdRead, &fdWrite, &fdErr, &tv), [](int i){return i < 0; });
523 #endif
524  if (0 == iRet){
525  return false;
526  }
527  if (FD_ISSET((SOCKET)*this, &fdErr)){
528  onError();
529  }
530  if (FD_ISSET((SOCKET)*this, &fdRead)){
531  onRead();
532  }
533  if (FD_ISSET((SOCKET)*this, &fdWrite)){
534  onWrite();
535  }
536  return true;
537  }
538  };
539 
540 #if (!DOXY_INVOKED)
541  TODO("Get rid of these")
542  template <typename _Ty>
543  class serializer{
544  public:
545 
546  template <typename _SocketT>
547  static void write(_SocketT& oSocket, const _Ty& src){
548  static_assert(std::is_pod<_Ty>::value, "no acceptable specialization for type");
549  exception::throw_if(::send(oSocket, reinterpret_cast<const char*>(&src), sizeof(_Ty), 0), [](int i){ return i <= 0; });
550  }
551 
552  template <typename _SocketT>
553  static void read(_SocketT& oSocket, _Ty& src){
554  static_assert(std::is_pod<_Ty>::value, "no acceptable specialization for type");
555  exception::throw_if(::recv(oSocket, reinterpret_cast<char*>(&src), sizeof(_Ty), 0), [](int i){ return i <= 0; });
556  }
557  };
558 
559 
560  template <typename _Ty>
561  class NON_POD_Vector_Serializer{
562  public:
563 
564  template <typename _SocketT>
565  static void write(_SocketT& oSocket, const std::vector<_Ty>& src){
566  serializer<typename std::vector<_Ty>::size_type>::write(oSocket, src.size());
567  for (const auto & oItem : src){
568  serializer<_Ty>::write(oSocket, oItem);
569  }
570  }
571 
572  template <typename _SocketT>
573  static void read(_SocketT& oSocket, std::vector<_Ty>& src){
574  typename std::vector<_Ty>::size_type count;
575  serializer<typename std::vector<_Ty>::size_type>::read(oSocket, count);
576  for (; count; --count){
577  _Ty newval;
578  serializer<_Ty>::read(oSocket, newval);
579  src.push_back(newval);
580  }
581  }
582  };
583 
584 
585  template <typename _Ty>
586  class POD_Vector_Serializer{
587  public:
588 
589  template <typename _SocketT >
590  static void write(_SocketT& oSocket, const std::vector<_Ty>& src){
591  serializer<typename std::vector<_Ty>::size_type>::write(oSocket, src.size());
592  send(oSocket, reinterpret_cast<const char*>(&src[0]), (int)(sizeof(_Ty) * src.size()), 0);
593  }
594 
595  template <typename _SocketT>
596  static void read(_SocketT& oSocket, std::vector<_Ty>& src){
597  typename std::vector<_Ty>::size_type count;
598  serializer<typename std::vector<_Ty>::size_type>::read(oSocket, count);
599  src.resize(count);
600  recv(oSocket, reinterpret_cast<char*>(&src[0]), (int)(sizeof(_Ty) * count), 0);
601  }
602 
603  };
604 
605 
606  template <typename _Ty>
607  class serializer<std::vector<_Ty>> : public std::conditional<std::is_pod<_Ty>::value, POD_Vector_Serializer<_Ty>, NON_POD_Vector_Serializer<_Ty>>::type{};
608 #endif
609  using ipv4_tcp_stream = socket_base<ipv4address, socket_type::stream, socket_protocol::tcp, socket_options, ip_options, tcp_options, connectable_socket, bindable_socket, listening_socket, selectable_socket>;
612  using ipv4_udp_socket = socket_base<ipv4address, socket_type::datagram, socket_protocol::udp, socket_options, ip_options, udp_options>;
614 
615  }
616 
617 }
ipv6 Internet Protocol v6
bindable_socket(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:375
exception(const exception &ex)
constructors
Definition: socket.hpp:65
Socket properties.
Definition: socket.hpp:423
Serializes data on a socket.
Definition: socket.hpp:165
exception(exception &&ex)
constructors
Definition: socket.hpp:66
bool select(int WaitMS)
begin the select to wait for an event or timeout
Definition: socket.hpp:505
callback< void()> disconnect_event
callback event fires when socket becomes disconnected
Definition: socket.hpp:333
tcp Transmission Control Protocol
IP based socket properties.
Definition: socket.hpp:439
template meta-programming utilities
IPv6 address wrapper around sockaddr_in6.
Definition: socket.hpp:138
callback< void()> read_event
callback event fires when data is ready to read data
Definition: socket.hpp:329
_Ty read()
reads data from the connected socket
Definition: socket.hpp:286
std::shared_ptr< socket_base > shared_ptr
typedefs
Definition: socket.hpp:214
exception(const source_location &loc, const xtd::string &swhat)
constructors
Definition: socket.hpp:64
callback< void()> error_event
callback event fires when an error occurs
Definition: socket.hpp:335
socket_base< ipv4address, socket_type::stream, socket_protocol::tcp, socket_options, ip_options, tcp_options, connectable_socket, bindable_socket, listening_socket, selectable_socket > ipv4_tcp_stream
General purpose IPV4 client and server socket type.
Definition: socket.hpp:610
void listen(int Backlog=SOMAXCONN)
begins listening on the socket
Definition: socket.hpp:410
selectable_socket(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:495
polling_socket(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:360
void connect(const typename _SuperT::address_type &addr)
initiates connection to a socket
Definition: socket.hpp:394
ip Internet Protocol v4
std::unique_ptr< socket_base > unique_ptr
typedefs
Definition: socket.hpp:213
xtd::callback< void()> onWrite
callback event fired when socket is ready to write
Definition: socket.hpp:500
_ReturnT accept()
accepts an incoming connection request
Definition: socket.hpp:416
Server side listening behavior.
Definition: socket.hpp:402
socket_type
socket communication styles
Definition: socket.hpp:146
Server side binding behavior.
Definition: socket.hpp:370
void bind(const typename _SuperT::address_type &addr)
binds the socket to an address and port
Definition: socket.hpp:378
UDP socket properties.
Definition: socket.hpp:472
connectable_socket(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:391
static const int address_family
ipv6 address family
Definition: socket.hpp:141
Polling behavior policy.
Definition: socket.hpp:326
TCP based socket properties.
Definition: socket.hpp:456
ipv4address(const char *sIP, uint16_t iPort)
constructor
Definition: socket.hpp:123
static const int address_family
ipv4 address familt
Definition: socket.hpp:117
void read(_Ty &data)
reads data from the connected socket
Definition: socket.hpp:278
udp User Datagram Protocol
bool keep_alive() const
gets the SO_KEEPALIVE property
Definition: socket.hpp:431
xtd::callback< void()> onError
callback event fired when a socket error occurs
Definition: socket.hpp:502
Async IO select behavior.
Definition: socket.hpp:491
specializations of std::basic_string for advanced and common string handling
host, target and build configurations and settings Various components are purpose built for specific ...
Client side connecting behavior.
Definition: socket.hpp:386
#define throw_if(_test, _expression)
Simplifies use of exception::_throw_if.
Definition: exception.hpp:22
void write(const _Ty &data)
writes data to the connected socket
Definition: socket.hpp:270
ip_options(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:444
datagram unreliable connectionless broadcast
generic and special purpose exceptions
icmp Internet Control Message Protocol
xtd::callback< void()> onRead
callback event fired when data is ready to be read
Definition: socket.hpp:498
Single producer - multiple subscriber callback.
socket_base & operator=(socket_base &&src)
move assignment
Definition: socket.hpp:254
raw interface level data
socket_protocol
IP based protocols.
Definition: socket.hpp:153
tcp_options(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:461
SOCKET _Socket
OS/CRT inner SOCKET that is being managed by this wrapper.
Definition: socket.hpp:319
Represents an socket error.
Definition: socket.hpp:60
stream reliable FIFO stream on a remote socket
void poll(int Timeout)
begins polling the socket for events for a period of Timeout
Definition: socket.hpp:337
listening_socket(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:407
udp_options(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:477
bool no_delay() const
gets the TCP_NODELAY property
Definition: socket.hpp:464
void no_delay(bool newval)
sets the TCP_NODELAY property
Definition: socket.hpp:466
IPv4 address wrapper around sockaddr_in.
Definition: socket.hpp:114
void set_blocking(bool blocking)
sets the blocking mode of the socket
Definition: socket.hpp:307
bool is_valid() const
test if the socket is valid
Definition: socket.hpp:315
callback< void()> write_event
callback event fires when socket is ready to write data
Definition: socket.hpp:331
socket_options(_ArgTs &&...oArgs)
ctor
Definition: socket.hpp:428
socket_base< ipv4address, socket_type::datagram, socket_protocol::udp, socket_options, ip_options, udp_options > ipv4_udp_socket
General purpose UDP socket type.
Definition: socket.hpp:612
void keep_alive(bool newval)
sets the SO_KEEPALIVE property
Definition: socket.hpp:433
Contains information about the location of source code Used in error reporting and logging...
c++ wrapper around legacy errno based errors from the CRT
Definition: exception.hpp:94