فهرست منبع

udpgw: add command line option for SO_SNDBUF. Bump default to 1M.

ambrop7 14 سال پیش
والد
کامیت
7809419f5c
2فایلهای تغییر یافته به همراه20 افزوده شده و 4 حذف شده
  1. 18 2
      udpgw/udpgw.c
  2. 2 2
      udpgw/udpgw.h

+ 18 - 2
udpgw/udpgw.c

@@ -117,6 +117,7 @@ struct {
     int udp_mtu;
     int max_clients;
     int max_connections_for_client;
+    int client_socket_sndbuf;
 } options;
 
 // MTUs
@@ -318,6 +319,7 @@ void print_help (const char *name)
         "        [--udp-mtu <bytes>]\n"
         "        [--max-clients <number>]\n"
         "        [--max-connections-for-client <number>]\n"
+        "        [--client-socket-sndbuf <bytes / 0>]\n"
         "Address format is a.b.c.d:port (IPv4) or [addr]:port (IPv6).\n",
         name
     );
@@ -349,6 +351,7 @@ int parse_arguments (int argc, char *argv[])
     options.udp_mtu = DEFAULT_UDP_MTU;
     options.max_clients = DEFAULT_MAX_CLIENTS;
     options.max_connections_for_client = DEFAULT_MAX_CONNECTIONS_FOR_CLIENT;
+    options.client_socket_sndbuf = CLIENT_DEFAULT_SOCKET_SEND_BUFFER;
     
     int i;
     for (i = 1; i < argc; i++) {
@@ -472,6 +475,17 @@ int parse_arguments (int argc, char *argv[])
             }
             i++;
         }
+        else if (!strcmp(arg, "--client-socket-sndbuf")) {
+            if (1 >= argc - i) {
+                fprintf(stderr, "%s: requires an argument\n", arg);
+                return 0;
+            }
+            if ((options.client_socket_sndbuf = atoi(argv[i + 1])) < 0) {
+                fprintf(stderr, "%s: wrong argument\n", arg);
+                return 0;
+            }
+            i++;
+        }
         else {
             fprintf(stderr, "unknown option: %s\n", arg);
             return 0;
@@ -529,8 +543,10 @@ void listener_handler (BListener *listener)
     }
     
     // limit socket send buffer, else our scheduling is pointless
-    if (!BConnection_SetSendBuffer(&client->con, CLIENT_SOCKET_SEND_BUFFER)) {
-        BLog(BLOG_WARNING, "BConnection_SetSendBuffer failed");
+    if (options.client_socket_sndbuf > 0) {
+        if (!BConnection_SetSendBuffer(&client->con, options.client_socket_sndbuf)) {
+            BLog(BLOG_WARNING, "BConnection_SetSendBuffer failed");
+        }
     }
     
     // init connection interfaces

+ 2 - 2
udpgw/udpgw.h

@@ -44,5 +44,5 @@
 // how long after nothing has been received to disconnect a client
 #define CLIENT_DISCONNECT_TIMEOUT 20000
 
-// SO_SNDBFUF socket option for clients
-#define CLIENT_SOCKET_SEND_BUFFER 4096
+// SO_SNDBFUF socket option for clients, 0 to not set
+#define CLIENT_DEFAULT_SOCKET_SEND_BUFFER 1048576