]> granicus.if.org Git - transmission/commitdiff
(trunk libT) #4165 "__FD_SETSIZE impact on open-file-limit and peer-limit-global...
authorJordan Lee <jordan@transmissionbt.com>
Sat, 16 Apr 2011 22:33:29 +0000 (22:33 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Sat, 16 Apr 2011 22:33:29 +0000 (22:33 +0000)
libtransmission/fdlimit.c

index 810a7c8145a1853e9d5b211b218f93d76ccf50b5..0831a28af7a61bcf7b344cbc660dc503c149104e 100644 (file)
@@ -746,8 +746,20 @@ tr_fdGetFileLimit( tr_session * session )
 void
 tr_fdSetFileLimit( tr_session * session, int limit )
 {
+    int max;
+
+    /* This is a vaguely arbitrary number.
+       It takes announcer.c's MAX_CONCURRENT_TASKS into account,
+       plus extra positions for the listening sockets,
+       plus a few more just to be safe */
+    const int buffer_slots = 128;
+
     ensureSessionFdInfoExists( session );
 
+    max = __FD_SETSIZE - session->fdInfo->socket_limit - buffer_slots;
+    if( limit > max )
+        limit = max;
+
     if( limit != tr_fdGetFileLimit( session ) )
     {
         struct tr_fileset * set = get_fileset( session );