summaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-04-08 21:59:05 +0300
committerAndrei Karas <akaras@inbox.ru>2013-04-08 21:59:05 +0300
commit02215574dc2b24eeef9c4ab55776334856bfbaf5 (patch)
tree05281f260ec07bbcd7732a7c228a826e585fbe66 /src/net
parentd63e4325051520c42349216c32c3390c61df2543 (diff)
downloadmanaverse-02215574dc2b24eeef9c4ab55776334856bfbaf5.tar.gz
manaverse-02215574dc2b24eeef9c4ab55776334856bfbaf5.tar.bz2
manaverse-02215574dc2b24eeef9c4ab55776334856bfbaf5.tar.xz
manaverse-02215574dc2b24eeef9c4ab55776334856bfbaf5.zip
add hack to avoid SDL_net limitations and add linux sockopts thin options.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/sdltcpnet.cpp48
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)