From f764cf8d3176b1c46f59ea58b872b2aef835240b Mon Sep 17 00:00:00 2001 From: Adam Ierymenko Date: Wed, 28 May 2014 12:17:43 -0700 Subject: Make UDP send and receive buffers as big as possible to reduce packet loss. --- node/SocketManager.cpp | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'node') diff --git a/node/SocketManager.cpp b/node/SocketManager.cpp index f9459cea..076afa07 100644 --- a/node/SocketManager.cpp +++ b/node/SocketManager.cpp @@ -242,6 +242,20 @@ SocketManager::SocketManager( #endif { + int bs = 1048576; + while (bs >= 65536) { + int tmpbs = bs; + if (setsockopt(s,SOL_SOCKET,SO_RCVBUF,&tmpbs,sizeof(tmpbs)) == 0) + break; + bs -= 16384; + } + bs = 1048576; + while (bs >= 65536) { + int tmpbs = bs; + if (setsockopt(s,SOL_SOCKET,SO_SNDBUF,&tmpbs,sizeof(tmpbs)) == 0) + break; + bs -= 16384; + } #ifdef __WINDOWS__ BOOL f; f = TRUE; setsockopt(s,IPPROTO_IPV6,IPV6_V6ONLY,(const char *)&f,sizeof(f)); @@ -302,6 +316,20 @@ SocketManager::SocketManager( #endif { + int bs = 1048576; + while (bs >= 65536) { + int tmpbs = bs; + if (setsockopt(s,SOL_SOCKET,SO_RCVBUF,&tmpbs,sizeof(tmpbs)) == 0) + break; + bs -= 16384; + } + bs = 1048576; + while (bs >= 65536) { + int tmpbs = bs; + if (setsockopt(s,SOL_SOCKET,SO_SNDBUF,&tmpbs,sizeof(tmpbs)) == 0) + break; + bs -= 16384; + } #ifdef __WINDOWS__ BOOL f; f = FALSE; setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(const char *)&f,sizeof(f)); -- cgit v1.2.3