Add mk_utils_get_somaxconn function
authorandroid <android@box.(none)>
Sat, 20 Mar 2010 19:02:00 +0000 (16:02 -0300)
committerandroid <android@box.(none)>
Sat, 20 Mar 2010 19:02:00 +0000 (16:02 -0300)
src/include/utils.h
src/socket.c
src/utils.c

index b3551a3..0304cb3 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <sys/types.h>
 #include <sys/stat.h>
+#include <sys/sysctl.h>
 #include <unistd.h>
 
 #define TRUE 1
@@ -30,6 +31,8 @@
 #define MK_UTILS_INT2MKP_BUFFER_LEN 16    /* Maximum buffer length when
                                            * converting an int to mk_pointer */
 
+#define MK_UTILS_SOMAXCONN_DEFAULT 1024   /* Default for SOMAXCONN value */
+
 #include "request.h"
 #include "memory.h"
 
@@ -92,4 +95,6 @@ void mk_utils_trace(const char *component, int color, const char *function,
                     char *file, int line, const char* format, ...);
 #endif
 
+int mk_utils_get_somaxconn();
+
 #endif
index 60aadf6..ae34443 100644 (file)
@@ -171,7 +171,7 @@ int mk_socket_server(int port, char *listen_addr)
      * The queue limit is given by /proc/sys/net/core/somaxconn
      * we need to add a dynamic function to get that value on fly
      */
-    if ((listen(fd, 1024)) != 0) {
+    if ((listen(fd, mk_utils_get_somaxconn())) != 0) {
         perror("listen");
         exit(1);
     }
index cb93468..3bbea4e 100644 (file)
@@ -310,3 +310,21 @@ void mk_utils_trace(const char *component, int color, const char *function,
     fprintf( stderr, "%s\n", ANSI_RESET);
 }
 #endif
+
+/* Get SOMAXCONN value. Based on sysctl manpage */
+int mk_utils_get_somaxconn() {
+       int size;
+    int name[] = { CTL_NET, NET_CORE, NET_CORE_SOMAXCONN };
+    int value;
+    size_t value_len;
+    
+       size = sizeof(name) / sizeof(name[0]);
+    value_len = sizeof(value);
+
+    if (sysctl(name, size, &value, &value_len, NULL, 0)) {
+        perror("sysctl");
+        return MK_UTILS_SOMAXCONN_DEFAULT;
+    }
+    return value;
+}