- added some special ways to configure how sockets work on a system for testing

This commit is contained in:
Mark Vejvoda 2011-11-27 00:07:55 +00:00
parent fbb3f0b8e5
commit da854f103b
3 changed files with 58 additions and 0 deletions

View File

@ -2595,6 +2595,19 @@ int glestMain(int argc, char** argv) {
Config &config = Config::getInstance();
setupGameItemPaths(argc, argv, &config);
Socket::disableNagle = config.getBool("DisableNagle","false");
if(Socket::disableNagle) {
printf("*WARNING users wants to disable the socket nagle algorithm.\n");
}
Socket::DEFAULT_SOCKET_SENDBUF_SIZE = config.getInt("DefaultSocketSendBufferSize",intToStr(Socket::DEFAULT_SOCKET_SENDBUF_SIZE).c_str());
if(Socket::DEFAULT_SOCKET_SENDBUF_SIZE >= 0) {
printf("*WARNING users wants to set default socket send buffer size to: %d\n",Socket::DEFAULT_SOCKET_SENDBUF_SIZE);
}
Socket::DEFAULT_SOCKET_RECVBUF_SIZE = config.getInt("DefaultSocketReceiveBufferSize",intToStr(Socket::DEFAULT_SOCKET_RECVBUF_SIZE).c_str());
if(Socket::DEFAULT_SOCKET_RECVBUF_SIZE >= 0) {
printf("*WARNING users wants to set default socket receive buffer size to: %d\n",Socket::DEFAULT_SOCKET_RECVBUF_SIZE);
}
shutdownFadeSoundMilliseconds = config.getInt("ShutdownFadeSoundMilliseconds",intToStr(shutdownFadeSoundMilliseconds).c_str());
string userData = config.getString("UserData_Root","");

View File

@ -130,6 +130,10 @@ public:
Socket();
virtual ~Socket();
static bool disableNagle;
static int DEFAULT_SOCKET_SENDBUF_SIZE;
static int DEFAULT_SOCKET_RECVBUF_SIZE;
//virtual void simpleTask(BaseThread *callingThread);
static int getBroadCastPort() { return broadcast_portno; }

View File

@ -47,6 +47,7 @@
#endif
#include <netinet/tcp.h>
#include <string.h>
#include <sys/stat.h>
#include <time.h>
@ -62,6 +63,10 @@ using namespace Shared::Util;
namespace Shared{ namespace Platform{
bool Socket::disableNagle = false;
int Socket::DEFAULT_SOCKET_SENDBUF_SIZE = -1;
int Socket::DEFAULT_SOCKET_RECVBUF_SIZE = -1;
int Socket::broadcast_portno = 61357;
int ServerSocket::ftpServerPort = 61358;
int ServerSocket::maxPlayerCount = -1;
@ -816,6 +821,42 @@ Socket::Socket() {
int set = 1;
setsockopt(sock, SOL_SOCKET, SO_NOSIGPIPE, (void *)&set, sizeof(int));
#endif
/* Disable the Nagle (TCP No Delay) algorithm */
if(Socket::disableNagle == true) {
int flag = 1;
int ret = setsockopt( sock, IPPROTO_TCP, TCP_NODELAY, (char *)&flag, sizeof(flag) );
if (ret == -1) {
printf("Couldn't setsockopt(TCP_NODELAY)\n");
}
}
if(Socket::DEFAULT_SOCKET_SENDBUF_SIZE >= 0) {
int bufsize = 0;
socklen_t optlen = sizeof(bufsize);
int ret = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, &bufsize, &optlen);
printf("Original setsockopt(SO_SNDBUF) = [%d] new will be [%d]\n",bufsize,Socket::DEFAULT_SOCKET_SENDBUF_SIZE);
ret = setsockopt( sock, SOL_SOCKET, SO_SNDBUF, (char *) &Socket::DEFAULT_SOCKET_SENDBUF_SIZE, sizeof( int ) );
if (ret == -1) {
printf("Couldn't setsockopt(SO_SNDBUF) [%d]\n",Socket::DEFAULT_SOCKET_SENDBUF_SIZE);
}
}
if(Socket::DEFAULT_SOCKET_RECVBUF_SIZE >= 0) {
int bufsize = 0;
socklen_t optlen = sizeof(bufsize);
int ret = getsockopt(sock, SOL_SOCKET, SO_RCVBUF, &bufsize, &optlen);
printf("Original setsockopt(SO_RCVBUF) = [%d] new will be [%d]\n",bufsize,Socket::DEFAULT_SOCKET_RECVBUF_SIZE);
ret = setsockopt( sock, SOL_SOCKET, SO_RCVBUF, (char *) &Socket::DEFAULT_SOCKET_RECVBUF_SIZE, sizeof( int ) );
if (ret == -1) {
printf("Couldn't setsockopt(SO_RCVBUF) [%d]\n",Socket::DEFAULT_SOCKET_RECVBUF_SIZE);
}
}
}
float Socket::getThreadedPingMS(std::string host) {