summaryrefslogtreecommitdiff
path: root/src/common/socket.c
diff options
context:
space:
mode:
authorFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-06-09 23:44:52 +0000
committerFlavioJS <FlavioJS@54d463be-8e91-2dee-dedb-b68131a5f0ec>2008-06-09 23:44:52 +0000
commitd43aab71e6d7eccc1d7710c351c708da388f3388 (patch)
treef29227320da4e26b7453c2b45b95aa99e345057d /src/common/socket.c
parent7f489214eb8c2f99e4ecbf5bef1ea64b761478cf (diff)
downloadhercules-d43aab71e6d7eccc1d7710c351c708da388f3388.tar.gz
hercules-d43aab71e6d7eccc1d7710c351c708da388f3388.tar.bz2
hercules-d43aab71e6d7eccc1d7710c351c708da388f3388.tar.xz
hercules-d43aab71e6d7eccc1d7710c351c708da388f3388.zip
* Added experimental code to set the socket limit at runtime.
git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@12803 54d463be-8e91-2dee-dedb-b68131a5f0ec
Diffstat (limited to 'src/common/socket.c')
-rw-r--r--src/common/socket.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/common/socket.c b/src/common/socket.c
index 9b48f0401..7addc271b 100644
--- a/src/common/socket.c
+++ b/src/common/socket.c
@@ -32,6 +32,10 @@
#ifndef SIOCGIFCONF
#include <sys/sockio.h> // SIOCGIFCONF on Solaris, maybe others? [Shinomori]
#endif
+
+ #ifdef HAVE_SETRLIMIT
+ #include <sys/resource.h>
+ #endif
#endif
/////////////////////////////////////////////////////////////////////
@@ -1200,6 +1204,23 @@ void socket_init(void)
return;
}
}
+#elif defined(HAVE_SETRLIMIT)
+ {// set socket limit to FD_SETSIZE
+ struct rlimit rlp;
+ if( 0 == getrlimit(RLIMIT_NOFILE, &rlp) )
+ {
+ rlp.rlim_cur = FD_SETSIZE;
+ if( 0 != setrlimit(RLIMIT_NOFILE, &rlp) )
+ {// failed, try setting the maximum too (permission to change system limits is required)
+ rlp.rlim_max = FD_SETSIZE;
+ if( 0 != setrlimit(RLIMIT_NOFILE, &rlp) )
+ {// failed
+ getrlimit(RLIMIT_NOFILE, &rlp);
+ ShowWarning("socket_init: %s - failed to set socket limit to %d (current limit %d).\n", strerror(errno), FD_SETSIZE, (int)rlp.rlim_cur);
+ }
+ }
+ }
+ }
#endif
// Get initial local ips