Sorted Socket.
[UnsignedByte.git] / src / Sockets / Socket.cpp
blobfaa741721b682a2472f4d7466e86bba8d635ae3a
1 /** \file Socket.cpp
2 ** \date 2004-02-13
3 ** \author grymse@alhem.net
4 **/
5 /*
6 Copyright (C) 2004-2007 Anders Hedstrom
8 This library is made available under the terms of the GNU GPL.
10 If you would like to use this library in a closed-source application,
11 a separate license agreement is available. For information about
12 the closed-source license agreement for the C++ sockets library,
13 please visit http://www.alhem.net/Sockets/license.html and/or
14 email license@alhem.net.
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 2
19 of the License, or (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #include "Socket.h"
31 #ifdef _WIN32
32 #ifndef __MINGW32__
33 #pragma warning(disable:4786)
34 #endif
35 #include <stdlib.h>
36 #else
37 #include <errno.h>
38 #include <netdb.h>
39 #endif
40 #include <ctype.h>
41 #include <fcntl.h>
43 #include "ISocketHandler.h"
44 #include "Utility.h"
46 #include "SocketAddress.h"
47 #include "SocketHandler.h"
49 #ifdef _DEBUG
50 #define DEB(x) x; fflush(stderr);
51 #else
52 #define DEB(x)
53 #endif
55 #ifdef SOCKETS_NAMESPACE
56 namespace SOCKETS_NAMESPACE {
57 #endif
60 // statics
61 #ifdef _WIN32
62 WSAInitializer Socket::m_winsock_init;
63 #endif
66 Socket::Socket(ISocketHandler& h)
67 //:m_flags(0)
68 :m_handler(h)
69 ,m_socket( INVALID_SOCKET )
70 ,m_bDel(false)
71 ,m_bClose(false)
72 ,m_tCreate(time(NULL))
73 ,m_parent(NULL)
74 ,m_b_disable_read(false)
75 ,m_connected(false)
76 ,m_b_erased_by_handler(false)
77 ,m_tClose(0)
78 ,m_client_remote_address(NULL)
79 ,m_remote_address(NULL)
80 ,m_traffic_monitor(NULL)
81 #ifdef HAVE_OPENSSL
82 ,m_b_enable_ssl(false)
83 ,m_b_ssl(false)
84 ,m_b_ssl_server(false)
85 #endif
86 #ifdef ENABLE_IPV6
87 ,m_ipv6(false)
88 #endif
89 #ifdef ENABLE_POOL
90 ,m_socket_type(0)
91 ,m_bClient(false)
92 ,m_bRetain(false)
93 ,m_bLost(false)
94 #endif
95 #ifdef ENABLE_SOCKS4
96 ,m_bSocks4(false)
97 ,m_socks4_host(h.GetSocks4Host())
98 ,m_socks4_port(h.GetSocks4Port())
99 ,m_socks4_userid(h.GetSocks4Userid())
100 #endif
101 #ifdef ENABLE_DETACH
102 ,m_detach(false)
103 ,m_detached(false)
104 ,m_pThread(NULL)
105 ,m_slave_handler(NULL)
106 #endif
111 Socket::~Socket()
113 Handler().Remove(this);
114 if (m_socket != INVALID_SOCKET
115 #ifdef ENABLE_POOL
116 && !m_bRetain
117 #endif
120 Close();
125 void Socket::Init()
130 void Socket::OnRead()
135 void Socket::OnWrite()
140 void Socket::OnException()
142 // %! exception doesn't always mean something bad happened, this code should be reworked
143 // errno valid here?
144 int err = SoError();
145 Handler().LogError(this, "exception on select", err, StrError(err), LOG_LEVEL_FATAL);
146 SetCloseAndDelete();
150 void Socket::OnDelete()
155 void Socket::OnConnect()
160 void Socket::OnAccept()
165 int Socket::Close()
167 if (m_socket == INVALID_SOCKET) // this could happen
169 Handler().LogError(this, "Socket::Close", 0, "file descriptor invalid", LOG_LEVEL_WARNING);
170 return 0;
172 int n;
173 if ((n = closesocket(m_socket)) == -1)
175 // failed...
176 Handler().LogError(this, "close", Errno, StrError(Errno), LOG_LEVEL_ERROR);
178 Handler().Set(m_socket, false, false, false); // remove from fd_set's
179 Handler().AddList(m_socket, LIST_CALLONCONNECT, false);
180 #ifdef ENABLE_DETACH
181 Handler().AddList(m_socket, LIST_DETACH, false);
182 #endif
183 Handler().AddList(m_socket, LIST_TIMEOUT, false);
184 Handler().AddList(m_socket, LIST_RETRY, false);
185 Handler().AddList(m_socket, LIST_CLOSE, false);
186 m_socket = INVALID_SOCKET;
187 return n;
191 SOCKET Socket::CreateSocket(int af,int type, const std::string& protocol)
193 struct protoent *p = NULL;
194 SOCKET s;
196 #ifdef ENABLE_POOL
197 m_socket_type = type;
198 m_socket_protocol = protocol;
199 #endif
200 if (protocol.size())
202 p = getprotobyname( protocol.c_str() );
203 if (!p)
205 Handler().LogError(this, "getprotobyname", Errno, StrError(Errno), LOG_LEVEL_FATAL);
206 SetCloseAndDelete();
207 return INVALID_SOCKET;
210 int protno = p ? p -> p_proto : 0;
212 s = socket(af, type, protno);
213 if (s == INVALID_SOCKET)
215 Handler().LogError(this, "socket", Errno, StrError(Errno), LOG_LEVEL_FATAL);
216 SetCloseAndDelete();
217 return INVALID_SOCKET;
219 Attach(s);
220 OnOptions(af, type, protno, s);
221 Attach(INVALID_SOCKET);
222 return s;
226 void Socket::Attach(SOCKET s)
228 m_socket = s;
232 SOCKET Socket::GetSocket()
234 return m_socket;
238 void Socket::SetDeleteByHandler(bool x)
240 m_bDel = x;
244 bool Socket::DeleteByHandler()
246 return m_bDel;
250 void Socket::SetCloseAndDelete(bool x)
252 if (x != m_bClose)
254 Handler().AddList(m_socket, LIST_CLOSE, x);
255 m_bClose = x;
256 if (x)
258 m_tClose = time(NULL);
264 bool Socket::CloseAndDelete()
266 return m_bClose;
270 void Socket::SetRemoteAddress(SocketAddress& ad) //struct sockaddr* sa, socklen_t l)
272 m_remote_address = ad.GetCopy();
276 std::auto_ptr<SocketAddress> Socket::GetRemoteSocketAddress()
278 return std::auto_ptr<SocketAddress>(m_remote_address -> GetCopy());
282 ISocketHandler& Socket::Handler() const
284 #ifdef ENABLE_DETACH
285 if (IsDetached())
286 return *m_slave_handler;
287 #endif
288 return m_handler;
292 ISocketHandler& Socket::MasterHandler() const
294 return m_handler;
298 ipaddr_t Socket::GetRemoteIP4()
300 ipaddr_t l = 0;
301 #ifdef ENABLE_IPV6
302 if (m_ipv6)
304 Handler().LogError(this, "GetRemoteIP4", 0, "get ipv4 address for ipv6 socket", LOG_LEVEL_WARNING);
306 #endif
307 if (m_remote_address.get() != NULL)
309 struct sockaddr *p = *m_remote_address;
310 struct sockaddr_in *sa = (struct sockaddr_in *)p;
311 memcpy(&l, &sa -> sin_addr, sizeof(struct in_addr));
313 return l;
317 #ifdef ENABLE_IPV6
318 #ifdef IPPROTO_IPV6
319 struct in6_addr Socket::GetRemoteIP6()
321 if (!m_ipv6)
323 Handler().LogError(this, "GetRemoteIP6", 0, "get ipv6 address for ipv4 socket", LOG_LEVEL_WARNING);
325 struct sockaddr_in6 fail;
326 if (m_remote_address.get() != NULL)
328 struct sockaddr *p = *m_remote_address;
329 memcpy(&fail, p, sizeof(struct sockaddr_in6));
331 else
333 memset(&fail, 0, sizeof(struct sockaddr_in6));
335 return fail.sin6_addr;
337 #endif
338 #endif
341 port_t Socket::GetRemotePort()
343 if (!m_remote_address.get())
345 return 0;
347 return m_remote_address -> GetPort();
351 std::string Socket::GetRemoteAddress()
353 if (!m_remote_address.get())
355 return "";
357 return m_remote_address -> Convert(false);
361 std::string Socket::GetRemoteHostname()
363 if (!m_remote_address.get())
365 return "";
367 return m_remote_address -> Reverse();
371 bool Socket::SetNonblocking(bool bNb)
373 #ifdef _WIN32
374 unsigned long l = bNb ? 1 : 0;
375 int n = ioctlsocket(m_socket, FIONBIO, &l);
376 if (n != 0)
378 Handler().LogError(this, "ioctlsocket(FIONBIO)", Errno, "");
379 return false;
381 return true;
382 #else
383 if (bNb)
385 if (fcntl(m_socket, F_SETFL, O_NONBLOCK) == -1)
387 Handler().LogError(this, "fcntl(F_SETFL, O_NONBLOCK)", Errno, StrError(Errno), LOG_LEVEL_ERROR);
388 return false;
391 else
393 if (fcntl(m_socket, F_SETFL, 0) == -1)
395 Handler().LogError(this, "fcntl(F_SETFL, 0)", Errno, StrError(Errno), LOG_LEVEL_ERROR);
396 return false;
399 return true;
400 #endif
404 bool Socket::SetNonblocking(bool bNb, SOCKET s)
406 #ifdef _WIN32
407 unsigned long l = bNb ? 1 : 0;
408 int n = ioctlsocket(s, FIONBIO, &l);
409 if (n != 0)
411 Handler().LogError(this, "ioctlsocket(FIONBIO)", Errno, "");
412 return false;
414 return true;
415 #else
416 if (bNb)
418 if (fcntl(s, F_SETFL, O_NONBLOCK) == -1)
420 Handler().LogError(this, "fcntl(F_SETFL, O_NONBLOCK)", Errno, StrError(Errno), LOG_LEVEL_ERROR);
421 return false;
424 else
426 if (fcntl(s, F_SETFL, 0) == -1)
428 Handler().LogError(this, "fcntl(F_SETFL, 0)", Errno, StrError(Errno), LOG_LEVEL_ERROR);
429 return false;
432 return true;
433 #endif
437 void Socket::Set(bool bRead, bool bWrite, bool bException)
439 Handler().Set(m_socket, bRead, bWrite, bException);
443 bool Socket::Ready()
445 if (m_socket != INVALID_SOCKET && !CloseAndDelete())
446 return true;
447 return false;
451 void Socket::OnLine(const std::string& )
456 void Socket::OnConnectFailed()
461 Socket *Socket::GetParent()
463 return m_parent;
467 void Socket::SetParent(Socket *x)
469 m_parent = x;
473 port_t Socket::GetPort()
475 Handler().LogError(this, "GetPort", 0, "GetPort only implemented for ListenSocket", LOG_LEVEL_WARNING);
476 return 0;
480 bool Socket::OnConnectRetry()
482 return true;
486 #ifdef ENABLE_RECONNECT
487 void Socket::OnReconnect()
490 #endif
493 time_t Socket::Uptime()
495 return time(NULL) - m_tCreate;
499 #ifdef ENABLE_IPV6
500 void Socket::SetIpv6(bool x)
502 m_ipv6 = x;
506 bool Socket::IsIpv6()
508 return m_ipv6;
510 #endif
513 void Socket::DisableRead(bool x)
515 m_b_disable_read = x;
519 bool Socket::IsDisableRead()
521 return m_b_disable_read;
525 void Socket::SendBuf(const char *,size_t,int)
530 void Socket::Send(const std::string&,int)
535 void Socket::SetConnected(bool x)
537 m_connected = x;
541 bool Socket::IsConnected()
543 return m_connected;
547 #ifdef ENABLE_RECONNECT
548 void Socket::OnDisconnect()
551 #endif
554 void Socket::SetErasedByHandler(bool x)
556 m_b_erased_by_handler = x;
560 bool Socket::ErasedByHandler()
562 return m_b_erased_by_handler;
566 time_t Socket::TimeSinceClose()
568 return time(NULL) - m_tClose;
572 void Socket::SetClientRemoteAddress(SocketAddress& ad)
574 if (!ad.IsValid())
576 Handler().LogError(this, "SetClientRemoteAddress", 0, "remote address not valid", LOG_LEVEL_ERROR);
578 m_client_remote_address = ad.GetCopy();
582 std::auto_ptr<SocketAddress> Socket::GetClientRemoteAddress()
584 if (!m_client_remote_address.get())
586 Handler().LogError(this, "GetClientRemoteAddress", 0, "remote address not yet set", LOG_LEVEL_ERROR);
588 return std::auto_ptr<SocketAddress>(m_client_remote_address -> GetCopy());
592 uint64_t Socket::GetBytesSent(bool)
594 return 0;
598 uint64_t Socket::GetBytesReceived(bool)
600 return 0;
604 #ifdef HAVE_OPENSSL
605 void Socket::OnSSLConnect()
610 void Socket::OnSSLAccept()
615 bool Socket::SSLNegotiate()
617 return false;
621 bool Socket::IsSSL()
623 return m_b_enable_ssl;
627 void Socket::EnableSSL(bool x)
629 m_b_enable_ssl = x;
633 bool Socket::IsSSLNegotiate()
635 return m_b_ssl;
639 void Socket::SetSSLNegotiate(bool x)
641 m_b_ssl = x;
645 bool Socket::IsSSLServer()
647 return m_b_ssl_server;
651 void Socket::SetSSLServer(bool x)
653 m_b_ssl_server = x;
657 void Socket::OnSSLConnectFailed()
662 void Socket::OnSSLAcceptFailed()
665 #endif // HAVE_OPENSSL
668 #ifdef ENABLE_POOL
669 void Socket::CopyConnection(Socket *sock)
671 Attach( sock -> GetSocket() );
672 #ifdef ENABLE_IPV6
673 SetIpv6( sock -> IsIpv6() );
674 #endif
675 SetSocketType( sock -> GetSocketType() );
676 SetSocketProtocol( sock -> GetSocketProtocol() );
678 SetClientRemoteAddress( *sock -> GetClientRemoteAddress() );
679 SetRemoteAddress( *sock -> GetRemoteSocketAddress() );
683 void Socket::SetIsClient()
685 m_bClient = true;
689 void Socket::SetSocketType(int x)
691 m_socket_type = x;
695 int Socket::GetSocketType()
697 return m_socket_type;
701 void Socket::SetSocketProtocol(const std::string& x)
703 m_socket_protocol = x;
707 const std::string& Socket::GetSocketProtocol()
709 return m_socket_protocol;
713 void Socket::SetRetain()
715 if (m_bClient) m_bRetain = true;
719 bool Socket::Retain()
721 return m_bRetain;
725 void Socket::SetLost()
727 m_bLost = true;
731 bool Socket::Lost()
733 return m_bLost;
735 #endif // ENABLE_POOL
738 #ifdef ENABLE_SOCKS4
739 void Socket::OnSocks4Connect()
741 Handler().LogError(this, "OnSocks4Connect", 0, "Use with TcpSocket only");
745 void Socket::OnSocks4ConnectFailed()
747 Handler().LogError(this, "OnSocks4ConnectFailed", 0, "Use with TcpSocket only");
751 bool Socket::OnSocks4Read()
753 Handler().LogError(this, "OnSocks4Read", 0, "Use with TcpSocket only");
754 return true;
758 void Socket::SetSocks4Host(const std::string& host)
760 Utility::u2ip(host, m_socks4_host);
764 bool Socket::Socks4()
766 return m_bSocks4;
770 void Socket::SetSocks4(bool x)
772 m_bSocks4 = x;
776 void Socket::SetSocks4Host(ipaddr_t a)
778 m_socks4_host = a;
782 void Socket::SetSocks4Port(port_t p)
784 m_socks4_port = p;
788 void Socket::SetSocks4Userid(const std::string& x)
790 m_socks4_userid = x;
794 ipaddr_t Socket::GetSocks4Host()
796 return m_socks4_host;
800 port_t Socket::GetSocks4Port()
802 return m_socks4_port;
806 const std::string& Socket::GetSocks4Userid()
808 return m_socks4_userid;
810 #endif // ENABLE_SOCKS4
813 #ifdef ENABLE_DETACH
814 bool Socket::Detach()
816 if (!DeleteByHandler())
817 return false;
818 if (m_pThread)
819 return false;
820 if (m_detached)
821 return false;
822 SetDetach();
823 return true;
827 void Socket::DetachSocket()
829 SetDetached();
830 m_pThread = new SocketThread(this);
831 m_pThread -> SetRelease(true);
835 void Socket::OnDetached()
840 void Socket::SetDetach(bool x)
842 Handler().AddList(m_socket, LIST_DETACH, x);
843 m_detach = x;
847 bool Socket::IsDetach()
849 return m_detach;
853 void Socket::SetDetached(bool x)
855 m_detached = x;
859 const bool Socket::IsDetached() const
861 return m_detached;
865 void Socket::SetSlaveHandler(ISocketHandler *p)
867 m_slave_handler = p;
871 Socket::SocketThread::SocketThread(Socket *p)
872 :Thread(false)
873 ,m_socket(p)
875 // Creator will release
879 Socket::SocketThread::~SocketThread()
881 if (IsRunning())
883 SetRelease(true);
884 SetRunning(false);
885 #ifdef _WIN32
886 Sleep(1000);
887 #else
888 sleep(1);
889 #endif
894 void Socket::SocketThread::Run()
896 SocketHandler h;
897 h.SetSlave();
898 h.Add(m_socket);
899 m_socket -> SetSlaveHandler(&h);
900 m_socket -> OnDetached();
901 while (h.GetCount() && IsRunning())
903 h.Select(0, 500000);
905 // m_socket now deleted oops
906 // yeah oops m_socket delete its socket thread, that means this
907 // so Socket will no longer delete its socket thread, instead we do this:
908 SetDeleteOnExit();
910 #endif // ENABLE_DETACH
913 #ifdef ENABLE_RESOLVER
914 int Socket::Resolve(const std::string& host,port_t port)
916 return Handler().Resolve(this, host, port);
920 #ifdef ENABLE_IPV6
921 int Socket::Resolve6(const std::string& host,port_t port)
923 return Handler().Resolve6(this, host, port);
925 #endif
928 int Socket::Resolve(ipaddr_t a)
930 return Handler().Resolve(this, a);
934 #ifdef ENABLE_IPV6
935 int Socket::Resolve(in6_addr& a)
937 return Handler().Resolve(this, a);
939 #endif
942 void Socket::OnResolved(int,ipaddr_t,port_t)
947 #ifdef ENABLE_IPV6
948 void Socket::OnResolved(int,in6_addr&,port_t)
951 #endif
954 void Socket::OnReverseResolved(int,const std::string&)
959 void Socket::OnResolveFailed(int)
962 #endif // ENABLE_RESOLVER
965 /* IP options */
968 bool Socket::SetIpOptions(const void *p, socklen_t len)
970 #ifdef IP_OPTIONS
971 if (setsockopt(GetSocket(), IPPROTO_IP, IP_OPTIONS, (char *)p, len) == -1)
973 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_OPTIONS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
974 return false;
976 return true;
977 #else
978 Handler().LogError(this, "ip option not available", 0, "IP_OPTIONS", LOG_LEVEL_INFO);
979 return false;
980 #endif
984 #ifdef IP_PKTINFO
985 bool Socket::SetIpPktinfo(bool x)
987 int optval = x ? 1 : 0;
988 if (setsockopt(GetSocket(), IPPROTO_IP, IP_PKTINFO, (char *)&optval, sizeof(optval)) == -1)
990 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_PKTINFO)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
991 return false;
993 return true;
995 #endif
998 #ifdef IP_RECVTOS
999 bool Socket::SetIpRecvTOS(bool x)
1001 int optval = x ? 1 : 0;
1002 if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVTOS, (char *)&optval, sizeof(optval)) == -1)
1004 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVTOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1005 return false;
1007 return true;
1009 #endif
1012 #ifdef IP_RECVTTL
1013 bool Socket::SetIpRecvTTL(bool x)
1015 int optval = x ? 1 : 0;
1016 if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVTTL, (char *)&optval, sizeof(optval)) == -1)
1018 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVTTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1019 return false;
1021 return true;
1023 #endif
1026 #ifdef IP_RECVOPTS
1027 bool Socket::SetIpRecvopts(bool x)
1029 int optval = x ? 1 : 0;
1030 if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVOPTS, (char *)&optval, sizeof(optval)) == -1)
1032 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVOPTS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1033 return false;
1035 return true;
1037 #endif
1040 #ifdef IP_RETOPTS
1041 bool Socket::SetIpRetopts(bool x)
1043 int optval = x ? 1 : 0;
1044 if (setsockopt(GetSocket(), IPPROTO_IP, IP_RETOPTS, (char *)&optval, sizeof(optval)) == -1)
1046 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RETOPTS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1047 return false;
1049 return true;
1051 #endif
1054 bool Socket::SetIpTOS(unsigned char tos)
1056 #ifdef IP_TOS
1057 if (setsockopt(GetSocket(), IPPROTO_IP, IP_TOS, (char *)&tos, sizeof(tos)) == -1)
1059 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1060 return false;
1062 return true;
1063 #else
1064 Handler().LogError(this, "ip option not available", 0, "IP_TOS", LOG_LEVEL_INFO);
1065 return false;
1066 #endif
1070 unsigned char Socket::IpTOS()
1072 unsigned char tos = 0;
1073 #ifdef IP_TOS
1074 socklen_t len = sizeof(tos);
1075 if (getsockopt(GetSocket(), IPPROTO_IP, IP_TOS, (char *)&tos, &len) == -1)
1077 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TOS)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1079 #else
1080 Handler().LogError(this, "ip option not available", 0, "IP_TOS", LOG_LEVEL_INFO);
1081 #endif
1082 return tos;
1086 bool Socket::SetIpTTL(int ttl)
1088 #ifdef IP_TTL
1089 if (setsockopt(GetSocket(), IPPROTO_IP, IP_TTL, (char *)&ttl, sizeof(ttl)) == -1)
1091 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1092 return false;
1094 return true;
1095 #else
1096 Handler().LogError(this, "ip option not available", 0, "IP_TTL", LOG_LEVEL_INFO);
1097 return false;
1098 #endif
1102 int Socket::IpTTL()
1104 int ttl = 0;
1105 #ifdef IP_TTL
1106 socklen_t len = sizeof(ttl);
1107 if (getsockopt(GetSocket(), IPPROTO_IP, IP_TTL, (char *)&ttl, &len) == -1)
1109 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1111 #else
1112 Handler().LogError(this, "ip option not available", 0, "IP_TTL", LOG_LEVEL_INFO);
1113 #endif
1114 return ttl;
1118 bool Socket::SetIpHdrincl(bool x)
1120 #ifdef IP_HDRINCL
1121 int optval = x ? 1 : 0;
1122 if (setsockopt(GetSocket(), IPPROTO_IP, IP_HDRINCL, (char *)&optval, sizeof(optval)) == -1)
1124 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_HDRINCL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1125 return false;
1127 return true;
1128 #else
1129 Handler().LogError(this, "ip option not available", 0, "IP_HDRINCL", LOG_LEVEL_INFO);
1130 return false;
1131 #endif
1135 #ifdef IP_RECVERR
1136 bool Socket::SetIpRecverr(bool x)
1138 int optval = x ? 1 : 0;
1139 if (setsockopt(GetSocket(), IPPROTO_IP, IP_RECVERR, (char *)&optval, sizeof(optval)) == -1)
1141 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_RECVERR)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1142 return false;
1144 return true;
1146 #endif
1149 #ifdef IP_MTU_DISCOVER
1150 bool Socket::SetIpMtudiscover(bool x)
1152 int optval = x ? 1 : 0;
1153 if (setsockopt(GetSocket(), IPPROTO_IP, IP_MTU_DISCOVER, (char *)&optval, sizeof(optval)) == -1)
1155 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MTU_DISCOVER)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1156 return false;
1158 return true;
1160 #endif
1163 #ifdef IP_MTU
1164 int Socket::IpMtu()
1166 int mtu = 0;
1167 socklen_t len = sizeof(mtu);
1168 if (getsockopt(GetSocket(), IPPROTO_IP, IP_MTU, (char *)&mtu, &len) == -1)
1170 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MTU)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1172 return mtu;
1174 #endif
1177 #ifdef IP_ROUTER_ALERT
1178 bool Socket::SetIpRouterAlert(bool x)
1180 int optval = x ? 1 : 0;
1181 if (setsockopt(GetSocket(), IPPROTO_IP, IP_ROUTER_ALERT, (char *)&optval, sizeof(optval)) == -1)
1183 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ROUTER_ALERT)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1184 return false;
1186 return true;
1188 #endif
1191 bool Socket::SetIpMulticastTTL(int ttl)
1193 #ifdef IP_MULTICAST_TTL
1194 if (setsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, sizeof(ttl)) == -1)
1196 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1197 return false;
1199 return true;
1200 #else
1201 Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_TTL", LOG_LEVEL_INFO);
1202 return false;
1203 #endif
1207 int Socket::IpMulticastTTL()
1209 int ttl = 0;
1210 #ifdef IP_MULTICAST_TTL
1211 socklen_t len = sizeof(ttl);
1212 if (getsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_TTL, (char *)&ttl, &len) == -1)
1214 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_TTL)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1216 #else
1217 Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_TTL", LOG_LEVEL_INFO);
1218 #endif
1219 return ttl;
1223 bool Socket::SetMulticastLoop(bool x)
1225 #ifdef IP_MULTICAST_LOOP
1226 int optval = x ? 1 : 0;
1227 if (setsockopt(GetSocket(), IPPROTO_IP, IP_MULTICAST_LOOP, (char *)&optval, sizeof(optval)) == -1)
1229 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_MULTICAST_LOOP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1230 return false;
1232 return true;
1233 #else
1234 Handler().LogError(this, "ip option not available", 0, "IP_MULTICAST_LOOP", LOG_LEVEL_INFO);
1235 return false;
1236 #endif
1240 #ifdef LINUX
1241 bool Socket::IpAddMembership(struct ip_mreqn& ref)
1243 #ifdef IP_ADD_MEMBERSHIP
1244 if (setsockopt(GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreqn)) == -1)
1246 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1247 return false;
1249 return true;
1250 #else
1251 Handler().LogError(this, "ip option not available", 0, "IP_ADD_MEMBERSHIP", LOG_LEVEL_INFO);
1252 return false;
1253 #endif
1255 #endif
1258 bool Socket::IpAddMembership(struct ip_mreq& ref)
1260 #ifdef IP_ADD_MEMBERSHIP
1261 if (setsockopt(GetSocket(), IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreq)) == -1)
1263 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_ADD_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1264 return false;
1266 return true;
1267 #else
1268 Handler().LogError(this, "ip option not available", 0, "IP_ADD_MEMBERSHIP", LOG_LEVEL_INFO);
1269 return false;
1270 #endif
1274 #ifdef LINUX
1275 bool Socket::IpDropMembership(struct ip_mreqn& ref)
1277 #ifdef IP_DROP_MEMBERSHIP
1278 if (setsockopt(GetSocket(), IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreqn)) == -1)
1280 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_DROP_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1281 return false;
1283 return true;
1284 #else
1285 Handler().LogError(this, "ip option not available", 0, "IP_DROP_MEMBERSHIP", LOG_LEVEL_INFO);
1286 return false;
1287 #endif
1289 #endif
1292 bool Socket::IpDropMembership(struct ip_mreq& ref)
1294 #ifdef IP_DROP_MEMBERSHIP
1295 if (setsockopt(GetSocket(), IPPROTO_IP, IP_DROP_MEMBERSHIP, (char *)&ref, sizeof(struct ip_mreq)) == -1)
1297 Handler().LogError(this, "setsockopt(IPPROTO_IP, IP_DROP_MEMBERSHIP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1298 return false;
1300 return true;
1301 #else
1302 Handler().LogError(this, "ip option not available", 0, "IP_DROP_MEMBERSHIP", LOG_LEVEL_INFO);
1303 return false;
1304 #endif
1308 /* SOCKET options */
1311 bool Socket::SetSoReuseaddr(bool x)
1313 #ifdef SO_REUSEADDR
1314 int optval = x ? 1 : 0;
1315 if (setsockopt(GetSocket(), SOL_SOCKET, SO_REUSEADDR, (char *)&optval, sizeof(optval)) == -1)
1317 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_REUSEADDR)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1318 return false;
1320 return true;
1321 #else
1322 Handler().LogError(this, "socket option not available", 0, "SO_REUSEADDR", LOG_LEVEL_INFO);
1323 return false;
1324 #endif
1328 bool Socket::SetSoKeepalive(bool x)
1330 #ifdef SO_KEEPALIVE
1331 int optval = x ? 1 : 0;
1332 if (setsockopt(GetSocket(), SOL_SOCKET, SO_KEEPALIVE, (char *)&optval, sizeof(optval)) == -1)
1334 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_KEEPALIVE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1335 return false;
1337 return true;
1338 #else
1339 Handler().LogError(this, "socket option not available", 0, "SO_KEEPALIVE", LOG_LEVEL_INFO);
1340 return false;
1341 #endif
1345 #ifdef SO_NOSIGPIPE
1346 bool Socket::SetSoNosigpipe(bool x)
1348 int optval = x ? 1 : 0;
1349 if (setsockopt(GetSocket(), SOL_SOCKET, SO_NOSIGPIPE, (char *)&optval, sizeof(optval)) == -1)
1351 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_NOSIGPIPE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1352 return false;
1354 return true;
1356 #endif
1359 bool Socket::SoAcceptconn()
1361 int value = 0;
1362 #ifdef SO_ACCEPTCONN
1363 socklen_t len = sizeof(value);
1364 if (getsockopt(GetSocket(), SOL_SOCKET, SO_ACCEPTCONN, (char *)&value, &len) == -1)
1366 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_ACCEPTCONN)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1368 #else
1369 Handler().LogError(this, "socket option not available", 0, "SO_ACCEPTCONN", LOG_LEVEL_INFO);
1370 #endif
1371 return value ? true : false;
1375 #ifdef SO_BSDCOMPAT
1376 bool Socket::SetSoBsdcompat(bool x)
1378 int optval = x ? 1 : 0;
1379 if (setsockopt(GetSocket(), SOL_SOCKET, SO_BSDCOMPAT, (char *)&optval, sizeof(optval)) == -1)
1381 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BSDCOMPAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1382 return false;
1384 return true;
1386 #endif
1389 #ifdef SO_BINDTODEVICE
1390 bool Socket::SetSoBindtodevice(const std::string& intf)
1392 if (setsockopt(GetSocket(), SOL_SOCKET, SO_BINDTODEVICE, (char *)intf.c_str(), intf.size()) == -1)
1394 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BINDTODEVICE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1395 return false;
1397 return true;
1399 #endif
1402 bool Socket::SetSoBroadcast(bool x)
1404 #ifdef SO_BROADCAST
1405 int optval = x ? 1 : 0;
1406 if (setsockopt(GetSocket(), SOL_SOCKET, SO_BROADCAST, (char *)&optval, sizeof(optval)) == -1)
1408 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_BROADCAST)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1409 return false;
1411 return true;
1412 #else
1413 Handler().LogError(this, "socket option not available", 0, "SO_BROADCAST", LOG_LEVEL_INFO);
1414 return false;
1415 #endif
1419 bool Socket::SetSoDebug(bool x)
1421 #ifdef SO_DEBUG
1422 int optval = x ? 1 : 0;
1423 if (setsockopt(GetSocket(), SOL_SOCKET, SO_DEBUG, (char *)&optval, sizeof(optval)) == -1)
1425 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_DEBUG)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1426 return false;
1428 return true;
1429 #else
1430 Handler().LogError(this, "socket option not available", 0, "SO_DEBUG", LOG_LEVEL_INFO);
1431 return false;
1432 #endif
1436 int Socket::SoError()
1438 int value = 0;
1439 #ifdef SO_ERROR
1440 socklen_t len = sizeof(value);
1441 if (getsockopt(GetSocket(), SOL_SOCKET, SO_ERROR, (char *)&value, &len) == -1)
1443 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_ERROR)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1445 #else
1446 Handler().LogError(this, "socket option not available", 0, "SO_ERROR", LOG_LEVEL_INFO);
1447 #endif
1448 return value ? true : false;
1452 bool Socket::SetSoDontroute(bool x)
1454 #ifdef SO_DONTROUTE
1455 int optval = x ? 1 : 0;
1456 if (setsockopt(GetSocket(), SOL_SOCKET, SO_DONTROUTE, (char *)&optval, sizeof(optval)) == -1)
1458 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_DONTROUTE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1459 return false;
1461 return true;
1462 #else
1463 Handler().LogError(this, "socket option not available", 0, "SO_DONTROUTE", LOG_LEVEL_INFO);
1464 return false;
1465 #endif
1469 bool Socket::SetSoLinger(int onoff, int linger)
1471 #ifdef SO_LINGER
1472 struct linger stl;
1473 stl.l_onoff = onoff;
1474 stl.l_linger = linger;
1475 if (setsockopt(GetSocket(), SOL_SOCKET, SO_LINGER, (char *)&stl, sizeof(stl)) == -1)
1477 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_LINGER)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1478 return false;
1480 return true;
1481 #else
1482 Handler().LogError(this, "socket option not available", 0, "SO_LINGER", LOG_LEVEL_INFO);
1483 return false;
1484 #endif
1488 bool Socket::SetSoOobinline(bool x)
1490 #ifdef SO_OOBINLINE
1491 int optval = x ? 1 : 0;
1492 if (setsockopt(GetSocket(), SOL_SOCKET, SO_OOBINLINE, (char *)&optval, sizeof(optval)) == -1)
1494 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_OOBINLINE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1495 return false;
1497 return true;
1498 #else
1499 Handler().LogError(this, "socket option not available", 0, "SO_OOBINLINE", LOG_LEVEL_INFO);
1500 return false;
1501 #endif
1505 #ifdef SO_PASSCRED
1506 bool Socket::SetSoPasscred(bool x)
1508 int optval = x ? 1 : 0;
1509 if (setsockopt(GetSocket(), SOL_SOCKET, SO_PASSCRED, (char *)&optval, sizeof(optval)) == -1)
1511 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PASSCRED)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1512 return false;
1514 return true;
1516 #endif
1519 #ifdef SO_PEERCRED
1520 bool Socket::SoPeercred(struct ucred& ucr)
1522 if (setsockopt(GetSocket(), SOL_SOCKET, SO_PEERCRED, (char *)&ucr, sizeof(ucr)) == -1)
1524 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PEERCRED)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1525 return false;
1527 return true;
1529 #endif
1532 #ifdef SO_PRIORITY
1533 bool Socket::SetSoPriority(int x)
1535 if (setsockopt(GetSocket(), SOL_SOCKET, SO_PRIORITY, (char *)&x, sizeof(x)) == -1)
1537 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_PRIORITY)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1538 return false;
1540 return true;
1542 #endif
1545 bool Socket::SetSoRcvlowat(int x)
1547 #ifdef SO_RCVLOWAT
1548 if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVLOWAT, (char *)&x, sizeof(x)) == -1)
1550 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVLOWAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1551 return false;
1553 return true;
1554 #else
1555 Handler().LogError(this, "socket option not available", 0, "SO_RCVLOWAT", LOG_LEVEL_INFO);
1556 return false;
1557 #endif
1561 bool Socket::SetSoSndlowat(int x)
1563 #ifdef SO_SNDLOWAT
1564 if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDLOWAT, (char *)&x, sizeof(x)) == -1)
1566 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDLOWAT)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1567 return false;
1569 return true;
1570 #else
1571 Handler().LogError(this, "socket option not available", 0, "SO_SNDLOWAT", LOG_LEVEL_INFO);
1572 return false;
1573 #endif
1577 bool Socket::SetSoRcvtimeo(struct timeval& tv)
1579 #ifdef SO_RCVTIMEO
1580 if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVTIMEO, (char *)&tv, sizeof(tv)) == -1)
1582 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVTIMEO)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1583 return false;
1585 return true;
1586 #else
1587 Handler().LogError(this, "socket option not available", 0, "SO_RCVTIMEO", LOG_LEVEL_INFO);
1588 return false;
1589 #endif
1593 bool Socket::SetSoSndtimeo(struct timeval& tv)
1595 #ifdef SO_SNDTIMEO
1596 if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDTIMEO, (char *)&tv, sizeof(tv)) == -1)
1598 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDTIMEO)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1599 return false;
1601 return true;
1602 #else
1603 Handler().LogError(this, "socket option not available", 0, "SO_SNDTIMEO", LOG_LEVEL_INFO);
1604 return false;
1605 #endif
1609 bool Socket::SetSoRcvbuf(int x)
1611 #ifdef SO_RCVBUF
1612 if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUF, (char *)&x, sizeof(x)) == -1)
1614 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1615 return false;
1617 return true;
1618 #else
1619 Handler().LogError(this, "socket option not available", 0, "SO_RCVBUF", LOG_LEVEL_INFO);
1620 return false;
1621 #endif
1625 int Socket::SoRcvbuf()
1627 int value = 0;
1628 #ifdef SO_RCVBUF
1629 socklen_t len = sizeof(value);
1630 if (getsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUF, (char *)&value, &len) == -1)
1632 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1634 #else
1635 Handler().LogError(this, "socket option not available", 0, "SO_RCVBUF", LOG_LEVEL_INFO);
1636 #endif
1637 return value ? true : false;
1641 #ifdef SO_RCVBUFFORCE
1642 bool Socket::SetSoRcvbufforce(int x)
1644 if (setsockopt(GetSocket(), SOL_SOCKET, SO_RCVBUFFORCE, (char *)&x, sizeof(x)) == -1)
1646 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_RCVBUFFORCE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1647 return false;
1649 return true;
1651 #endif
1654 bool Socket::SetSoSndbuf(int x)
1656 #ifdef SO_SNDBUF
1657 if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUF, (char *)&x, sizeof(x)) == -1)
1659 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1660 return false;
1662 return true;
1663 #else
1664 Handler().LogError(this, "socket option not available", 0, "SO_SNDBUF", LOG_LEVEL_INFO);
1665 return false;
1666 #endif
1670 int Socket::SoSndbuf()
1672 int value = 0;
1673 #ifdef SO_SNDBUF
1674 socklen_t len = sizeof(value);
1675 if (getsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUF, (char *)&value, &len) == -1)
1677 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUF)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1679 #else
1680 Handler().LogError(this, "socket option not available", 0, "SO_SNDBUF", LOG_LEVEL_INFO);
1681 #endif
1682 return value ? true : false;
1686 #ifdef SO_SNDBUFFORCE
1687 bool Socket::SetSoSndbufforce(int x)
1689 if (setsockopt(GetSocket(), SOL_SOCKET, SO_SNDBUFFORCE, (char *)&x, sizeof(x)) == -1)
1691 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_SNDBUFFORCE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1692 return false;
1694 return true;
1696 #endif
1699 #ifdef SO_TIMESTAMP
1700 bool Socket::SetSoTimestamp(bool x)
1702 int optval = x ? 1 : 0;
1703 if (setsockopt(GetSocket(), SOL_SOCKET, SO_TIMESTAMP, (char *)&optval, sizeof(optval)) == -1)
1705 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_TIMESTAMP)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1706 return false;
1708 return true;
1710 #endif
1713 int Socket::SoType()
1715 int value = 0;
1716 #ifdef SO_TYPE
1717 socklen_t len = sizeof(value);
1718 if (getsockopt(GetSocket(), SOL_SOCKET, SO_TYPE, (char *)&value, &len) == -1)
1720 Handler().LogError(this, "setsockopt(SOL_SOCKET, SO_TYPE)", Errno, StrError(Errno), LOG_LEVEL_FATAL);
1722 #else
1723 Handler().LogError(this, "socket option not available", 0, "SO_TYPE", LOG_LEVEL_INFO);
1724 #endif
1725 return value ? true : false;
1729 #ifdef ENABLE_TRIGGERS
1730 void Socket::Subscribe(int id)
1732 Handler().Subscribe(id, this);
1736 void Socket::Unsubscribe(int id)
1738 Handler().Unsubscribe(id, this);
1742 void Socket::OnTrigger(int, const TriggerData&)
1747 void Socket::OnCancelled(int)
1750 #endif
1753 void Socket::SetTimeout(time_t secs)
1755 if (!secs)
1757 Handler().AddList(m_socket, LIST_TIMEOUT, false);
1758 return;
1760 Handler().AddList(m_socket, LIST_TIMEOUT, true);
1761 m_timeout_start = time(NULL);
1762 m_timeout_limit = secs;
1766 void Socket::OnTimeout()
1771 void Socket::OnConnectTimeout()
1776 bool Socket::Timeout(time_t tnow)
1778 if (tnow - m_timeout_start > m_timeout_limit)
1779 return true;
1780 return false;
1784 #ifdef SOCKETS_NAMESPACE
1786 #endif