diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-04-08 21:59:05 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-04-08 21:59:05 +0300 |
commit | 02215574dc2b24eeef9c4ab55776334856bfbaf5 (patch) | |
tree | 05281f260ec07bbcd7732a7c228a826e585fbe66 | |
parent | d63e4325051520c42349216c32c3390c61df2543 (diff) | |
download | plus-02215574dc2b24eeef9c4ab55776334856bfbaf5.tar.gz plus-02215574dc2b24eeef9c4ab55776334856bfbaf5.tar.bz2 plus-02215574dc2b24eeef9c4ab55776334856bfbaf5.tar.xz plus-02215574dc2b24eeef9c4ab55776334856bfbaf5.zip |
add hack to avoid SDL_net limitations and add linux sockopts thin options.
-rw-r--r-- | src/net/sdltcpnet.cpp | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/net/sdltcpnet.cpp b/src/net/sdltcpnet.cpp index 28cac3aa3..6ad350002 100644 --- a/src/net/sdltcpnet.cpp +++ b/src/net/sdltcpnet.cpp @@ -20,8 +20,23 @@ #include "net/sdltcpnet.h" +#if defined __linux__ || defined __linux +#include <sys/socket.h> +#include <linux/tcp.h> +#include <netdb.h> +#endif + #include "debug.h" +// because actual struct is hidden in SDL_net we reinroducing it here +struct TCPsocketHack { + int ready; + int channel; + IPaddress remoteAddress; + IPaddress localAddress; + int sflag; +}; + void TcpNet::init() { SDLNet_Init(); @@ -52,9 +67,40 @@ int TcpNet::resolveHost(IPaddress *address, const char *host, Uint16 port) return SDLNet_ResolveHost(address, host, port); } +#include "logger.h" + TcpNet::Socket TcpNet::open(IPaddress *ip) { - return SDLNet_TCP_Open(ip); + TcpNet::Socket sock = SDLNet_TCP_Open(ip); + if (sock && ip) + { + TCPsocketHack *hack = reinterpret_cast<TCPsocketHack *>(sock); + // here we using some magic to compare TCPsocket and own padding + // because actual struct TCPsocket not in headers + if (hack) + { + const IPaddress &addr = hack->remoteAddress; + if (addr.host == ip->host && addr.port == ip->port) + { + const int val = 1; +#ifdef TCP_THIN_LINEAR_TIMEOUTS + if (setsockopt(hack->channel, IPPROTO_TCP, + TCP_THIN_LINEAR_TIMEOUTS, &val, sizeof(val))) + { + logger->log1("error on set TCP_THIN_LINEAR_TIMEOUTS"); + } +#endif +#ifdef TCP_THIN_DUPACK + if (setsockopt(hack->channel, IPPROTO_TCP, + TCP_THIN_DUPACK, &val, sizeof(val))) + { + logger->log1("error on set TCP_THIN_DUPACK"); + } +#endif + } + } + } + return sock; } TcpNet::SocketSet TcpNet::allocSocketSet(int maxsockets) |