11 #ifndef __DSL_SOCKETS3_H__
12 #define __DSL_SOCKETS3_H__
14 #include <drift/Mutex.h>
26 #define MAX_SOCKETS 1024
28 #define DS3_MAX_HOSTLEN 40
29 #define DS3_MAX_SERVLEN 8
35 char last_error[128] = { 0 };
40 char remote_ip[DS3_MAX_HOSTLEN] = { 0 };
41 char local_ip[DS3_MAX_HOSTLEN] = { 0 };
47 bool nonblocking =
false;
50 void * userPtr = NULL;
57 set<D_SOCKET *> socks;
70 DS3_SSL_METHOD_TLS1_2 = 1,
71 DS3_SSL_METHOD_TLS1_1 = 2,
74 #if !defined(NO_DTLS1)
91 void pUpdateError(
DSL_SOCKET * sock,
int serrno,
const char * errstr);
93 unsigned int avail_flags = 0;
94 unsigned int enabled_flags = 0;
97 virtual int pRecv(
DSL_SOCKET * sock,
char * buf, uint32 bufsize);
98 virtual int pPeek(
DSL_SOCKET * sock,
char * buf, uint32 bufsize);
99 virtual int pSend(
DSL_SOCKET * sock,
const char * buf, uint32 bufsize);
100 virtual int pSelect_Read(
DSL_SOCKET * sock, timeval * timeo);
103 bool free_mutex =
false;
104 typedef std::set<DSL_SOCKET *> knownSocketList;
105 knownSocketList sockets;
107 addrinfo * pResolve(
DSL_SOCKET * sock,
const char * host,
int port);
108 void pFreeAddrInfo(addrinfo * ai);
115 virtual bool IsSupported(
unsigned int flag);
116 virtual bool IsEnabled(
unsigned int flag);
117 virtual void Silent(
bool bSilent);
119 virtual int GetLastError(
D_SOCKET * sock=NULL);
120 virtual const char * GetLastErrorString(
D_SOCKET * sock=NULL);
130 virtual DSL_SOCKET * Create(
int family = PF_INET,
int type = SOCK_STREAM,
int proto = IPPROTO_TCP, uint32 flags=0);
132 virtual bool IsKnownSocket(
DSL_SOCKET * sock);
134 virtual int GetFamilyHint(
const char * host,
int port);
135 virtual bool Connect(
DSL_SOCKET * sock,
const char * host,
int port);
136 virtual bool Connect(
DSL_SOCKET * sock, sockaddr * addr,
size_t addrlen);
137 virtual bool ConnectWithTimeout(
DSL_SOCKET * sock,
const char * host,
int port, uint32 timeout);
144 virtual int Send(
DSL_SOCKET * sock,
const char * data,
int datalen = -1,
bool doloop =
true);
149 virtual int Recv(
DSL_SOCKET * sock,
char * buf, uint32 bufsize);
154 virtual int RecvLine(
DSL_SOCKET * sock,
char * buf,
int bufsize);
159 virtual int Peek(
DSL_SOCKET * sock,
char * buf, uint32 bufsize);
161 virtual int Select_Read(
DSL_SOCKET * sock, timeval * timeo);
162 virtual int Select_Read(
DSL_SOCKET * sock, uint32 millisec);
163 virtual int Select_Write(
DSL_SOCKET * sock, timeval * timeo);
164 virtual int Select_Write(
DSL_SOCKET * sock, uint32 millisec);
171 virtual DSL_SOCKET * Accept(
DSL_SOCKET * s, sockaddr *addr, socklen_t *addrlen, uint32 flags=0);
173 virtual bool Bind(
DSL_SOCKET * sock,
int port);
174 virtual bool BindToAddr(
DSL_SOCKET * sock,
const char * host,
int port);
175 virtual bool Listen(
DSL_SOCKET * s,
int backlog=5);
177 virtual int SendTo(
DSL_SOCKET * sock,
const char * host,
int port,
const char * buf,
int datalen = -1);
178 virtual int RecvFrom(
DSL_SOCKET * sock,
char * host, uint32 hostSize,
int * port,
char * buf, uint32 bufsize);
179 virtual int RecvLineFrom(
DSL_SOCKET * sock,
char * host, uint32 hostSize,
int * port,
char * buf, uint32 bufsize);
180 virtual int PeekFrom(
DSL_SOCKET * sock,
char * host, uint32 hostSize,
int * port,
char * buf, uint32 bufsize);
182 virtual int SetRecvTimeout(
DSL_SOCKET * sock, uint32 millisec);
183 virtual int SetSendTimeout(
DSL_SOCKET * sock, uint32 millisec);
185 virtual bool IsNonBlocking(
DSL_SOCKET * sock);
186 virtual void SetNonBlocking(
DSL_SOCKET * sock,
bool non_blocking=
true);
187 virtual int SetReuseAddr(
DSL_SOCKET * sock,
bool reuse_addr=
true);
188 virtual int SetLinger(
DSL_SOCKET * sock,
bool linger,
unsigned short timeo=30);
189 virtual int SetNoDelay(
DSL_SOCKET * sock,
bool no_delay=
true);
190 virtual int SetKeepAlive(
DSL_SOCKET * sock,
bool ka=
true);
191 virtual int SetBroadcast(
DSL_SOCKET * sock,
bool broadcast=
true);
192 virtual bool DisableUDPConnReset(
DSL_SOCKET * sock,
bool noconnreset);
194 virtual std::string GetHostIP(
const char * host,
int type=SOCK_STREAM,
int proto=IPPROTO_TCP);
201 virtual int pRecv(
DSL_SOCKET * sock,
char * buf, uint32 bufsize) = 0;
202 virtual int pPeek(
DSL_SOCKET * sock,
char * buf, uint32 bufsize) = 0;
203 virtual int pSend(
DSL_SOCKET * sock,
const char * buf, uint32 bufsize) = 0;
204 virtual void pCloseSSL(
DSL_SOCKET * sock) = 0;
205 virtual int pSelect_Read(
DSL_SOCKET * sock, timeval * timeo) {
return DSL_Sockets3_Base::pSelect_Read(sock, timeo); }
209 virtual bool EnableSSL(
const char * cert_fn,
DS3_SSL_METHOD method) = 0;
210 virtual bool SwitchToSSL_Server(
DSL_SOCKET * sock) = 0;
211 virtual bool SwitchToSSL_Client(
DSL_SOCKET * sock) = 0;
214 #if defined(ENABLE_OPENSSL)
215 #define DSL_Sockets3 DSL_Sockets3_OpenSSL
216 #elif defined(ENABLE_GNUTLS)
217 #define DSL_Sockets3 DSL_Sockets3_GnuTLS
219 #define DSL_Sockets3 DSL_Sockets3_Base
223 #define RL3_CLOSED -3
224 #define RL3_LINETOOLONG -2
225 #define RL3_NOLINE -1
227 #define DS3_FLAG_SSL 0x00000001
228 #define DS3_FLAG_ZIP 0x00000002
230 #define DSL_Sockets DSL_Sockets3
@ DS3_SSL_METHOD_TLS1_0
this is the minimum you should use
@ DS3_SSL_METHOD_DTLS1
Datagram TLS, consider this untested.
@ DS3_SSL_METHOD_TLS
Attempt highest TLS version, falling back to lower versions to 1.0.