24 #if defined __linux__ || defined __linux
26 #include <sys/socket.h>
28 #if defined(M_TCPOK) && !defined(ANDROID)
29 #include <netinet/in.h>
31 #include <linux/tcp.h>
33 #include <netinet/in.h>
34 #include <netinet/tcp.h>
36 #include <netinet/tcp.h>
38 #define TCP_THIN_LINEAR_TIMEOUTS 16
40 #define TCP_THIN_DUPACK 17
47 #include "net/sdltcpnet.h"
52 #if !defined(__native_client__) \
53 && (defined(TCP_THIN_LINEAR_TIMEOUTS) \
54 || defined(TCP_THIN_DUPACK))
56 struct TCPsocketHack
final
70 IPaddress remoteAddress;
71 IPaddress localAddress;
90 SDLNet_TCP_Close(socket);
96 return SDLNet_TCP_Send(sock,
data, len);
101 return SDL_GetError();
107 return SDLNet_ResolveHost(address, host, port);
113 #if !defined(__native_client__) \
114 && (defined(TCP_THIN_LINEAR_TIMEOUTS) \
115 || defined(TCP_THIN_DUPACK))
116 if ((sock !=
nullptr) && (ip !=
nullptr))
118 const TCPsocketHack *
const hack
119 =
reinterpret_cast<const TCPsocketHack *
>(sock);
124 const IPaddress &addr =
hack->remoteAddress;
125 if (addr.host == ip->host && addr.port == ip->port)
128 #ifdef TCP_THIN_LINEAR_TIMEOUTS
129 if (setsockopt(
hack->channel, IPPROTO_TCP,
130 TCP_THIN_LINEAR_TIMEOUTS, &val,
sizeof(val)) != 0)
132 logger->
log_r(
"error on set TCP_THIN_LINEAR_TIMEOUTS");
135 #ifdef TCP_THIN_DUPACK
136 if (setsockopt(
hack->channel, IPPROTO_TCP,
137 TCP_THIN_DUPACK, &val,
sizeof(val)) != 0)
153 return SDLNet_AllocSocketSet(maxsockets);
160 return SDLNet_TCP_AddSocket(set, sock);
167 PRAGMACLANG5(GCC diagnostic ignored
"-Wzero-as-null-pointer-constant")
170 return SDLNet_SocketReady(sock);
177 return SDLNet_CheckSockets(set, timeout);
182 return SDLNet_TCP_Recv(sock,
data, maxlen);
189 return SDLNet_TCP_DelSocket(set, sock);
195 SDLNet_FreeSocketSet(set);
200 return SDLNet_TCP_Accept(sock);
void log_r(const char *const log_text,...)
#define A_DELETE_COPY(func)
#define PRAGMACLANG5(str)
#define PRAGMACLANG6GCC(str)
bool hack(InputEvent &event)
int delSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock)
::SDLNet_SocketSet SocketSet
int send(const TcpNet::Socket sock, const void *const data, const int len)
int resolveHost(IPaddress *const address, const char *const host, const Uint16 port)
void freeSocketSet(const TcpNet::SocketSet set)
int socketReady(const TcpNet::Socket sock)
TcpNet::Socket open(IPaddress *const ip)
int addSocket(const TcpNet::SocketSet set, const TcpNet::Socket sock)
SocketSet allocSocketSet(const int maxsockets)
int checkSockets(const TcpNet::SocketSet set, const Uint32 timeout)
void closeSocket(const TcpNet::Socket socket)
int recv(const TcpNet::Socket sock, void *const data, const int maxlen)
TcpNet::Socket accept(const TcpNet::Socket sock)