[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[or-cvs] r14101: Combine common code in set_max_file_descriptors(): all that (in tor/trunk: . src/common)
Author: nickm
Date: 2008-03-18 11:11:52 -0400 (Tue, 18 Mar 2008)
New Revision: 14101
Modified:
tor/trunk/
tor/trunk/src/common/compat.c
Log:
r18927@catbus: nickm | 2008-03-18 11:11:49 -0400
Combine common code in set_max_file_descriptors(): all that varies from platform to platform in the no-getrlimit() case is the connection limit and the platform name.
Property changes on: tor/trunk
___________________________________________________________________
svk:merge ticket from /tor/trunk [r18927] on 8246c3cf-6607-4228-993b-4d95d33730f1
Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c 2008-03-18 15:01:40 UTC (rev 14100)
+++ tor/trunk/src/common/compat.c 2008-03-18 15:11:52 UTC (rev 14101)
@@ -765,47 +765,36 @@
int
set_max_file_descriptors(rlim_t limit, int *max_out)
{
-#define DEFAULT_MAX_CONNECTIONS 15000
-#define CYGWIN_MAX_CONNECTIONS 3200
-#define IPHONE_MAX_CONNECTIONS 9999
/* Define some maximum connections values for systems where we cannot
* automatically determine a limit. Re Cygwin, see
* http://archives.seul.org/or/talk/Aug-2006/msg00210.html
* For an iPhone, 9999 should work. For Windows and all other unknown
* systems we use 15000 as the default. */
#ifndef HAVE_GETRLIMIT
+#if defined(CYGWIN) || defined(__CYGWIN__)
+ const char *platform = "Cygwin";
+ const unsigned long MAX_CONNECTIONS = 3200;
+#elif defined(IPHONE)
+ const char *platform = "iPhone";
+ const unsigned long MAX_CONNECTIONS = 9999;
+#elif defined(MS_WINDOWS)
+ const char *platform = "Windows";
+ const unsigned long MAX_CONNECTIONS = 15000;
+#else
+ const char *platform = "unknown platforms with no getrlimit()";
+ const unsigned long MAX_CONNECTIONS = 15000;
+#endif
log_fn(LOG_INFO, LD_NET,
"This platform is missing getrlimit(). Proceeding.");
-#ifdef MS_WINDOWS
- if (limit > DEFAULT_MAX_CONNECTIONS) {
+ if (limit > MAX_CONNECTIONS) {
log_warn(LD_CONFIG,
"We do not support more than %lu file descriptors "
- "on Windows. Tried to raise to %lu.",
- (unsigned long)DEFAULT_MAX_CONNECTIONS, (unsigned long)limit);
+ "on %s. Tried to raise to %lu.",
+ (unsigned long)MAX_CONNECTIONS, platform, (unsigned long)limit);
return -1;
}
- limit = DEFAULT_MAX_CONNECTIONS;
-#elif defined(CYGWIN) || defined(__CYGWIN__)
- if (limit > CYGWIN_MAX_CONNECTIONS) {
- log_warn(LD_CONFIG, "We do not support more than %lu file descriptors "
- "when using Cygwin. Tried to raise to %lu.",
- (unsigned long)CYGWIN_MAX_CONNECTIONS, (unsigned long)limit);
- return -1;
- }
- limit = CYGWIN_MAX_CONNECTIONS;
-#elif defined(IPHONE)
- if (limit > IPHONE_MAX_CONNECTIONS) {
- log_warn(LD_CONFIG, "We do not support more than %lu file descriptors "
- "on iPhone. Tried to raise to %lu.",
- (unsigned long)IPHONE_MAX_CONNECTIONS, (unsigned long)limit);
- return -1;
- }
- limit = IPHONE_MAX_CONNECTIONS;
-#else
- /* Unknown system without getrlimit support. Use the default value.*/
- limit = DEFAULT_MAX_CONNECTIONS;
-#endif
-#else
+ limit = MAX_CONNECTIONS;
+#else /* HAVE_GETRLIMIT */
struct rlimit rlim;
tor_assert(limit > 0);
@@ -848,7 +837,7 @@
bad = 0;
}
}
-#endif
+#endif /* OPEN_MAX */
if (bad) {
log_warn(LD_CONFIG,"Couldn't set maximum number of file descriptors: %s",
strerror(errno));
@@ -857,7 +846,7 @@
}
/* leave some overhead for logs, etc, */
limit = rlim.rlim_cur;
-#endif
+#endif /* HAVE_GETRLIMIT */
if (limit < ULIMIT_BUFFER) {
log_warn(LD_CONFIG,