Forráskód Böngészése

client, server: limit TCP send buffer where we do scheduling, or it is pointless to do because the
socket's send buffer may grow very large

ambrop7 15 éve
szülő
commit
023c1245bf
6 módosított fájl, 37 hozzáadás és 0 törlés
  1. 5 0
      client/StreamPeerIO.c
  2. 2 0
      client/StreamPeerIO.h
  3. 5 0
      server/server.c
  4. 2 0
      server/server.h
  5. 14 0
      system/BSocket.c
  6. 9 0
      system/BSocket.h

+ 5 - 0
client/StreamPeerIO.c

@@ -409,6 +409,11 @@ int init_io (StreamPeerIO *pio, sslsocket *sock)
 {
     ASSERT(!pio->sock)
     
+    // limit socket send buffer, else our scheduling is pointless
+    if (BSocket_SetSendBuffer(&sock->sock, STREAMPEERIO_SOCKET_SEND_BUFFER) < 0) {
+        BLog(BLOG_WARNING, "BSocket_SetSendBuffer failed");
+    }
+    
     // init receiving
     StreamRecvInterface *source_interface;
     if (pio->ssl) {

+ 2 - 0
client/StreamPeerIO.h

@@ -51,6 +51,8 @@
 #include <client/PasswordListener.h>
 #include <client/PasswordSender.h>
 
+#define STREAMPEERIO_SOCKET_SEND_BUFFER 1
+
 /**
  * Callback function invoked when an error occurs with the peer connection.
  * The object has entered default state.

+ 5 - 0
server/server.c

@@ -1491,6 +1491,11 @@ void process_packet_hello (struct client_data *client, uint8_t *data, int data_l
     
     client_log(client, BLOG_INFO, "received hello");
     
+    // limit socket send buffer, else our scheduling is pointless
+    if (BSocket_SetSendBuffer(&client->sock, CLIENT_SOCKET_SEND_BUFFER) < 0) {
+        BLog(BLOG_WARNING, "BSocket_SetSendBuffer failed");
+    }
+    
     // set client state to complete
     client->initstatus = INITSTATUS_COMPLETE;
     

+ 2 - 0
server/server.h

@@ -50,6 +50,8 @@
 #define CLIENT_PEER_FLOW_BUFFER_MIN_PACKETS 10
 // after how long of not hearing anything from the client we disconnect it
 #define CLIENT_NO_DATA_TIME_LIMIT 30000
+// SO_SNDBFUF socket option for clients
+#define CLIENT_SOCKET_SEND_BUFFER 1
 
 // maxiumum listen addresses
 #define MAX_LISTEN_ADDRS 16

+ 14 - 0
system/BSocket.c

@@ -1642,3 +1642,17 @@ int BSocket_SockFd (BSocket *bs)
     
     return bs->socket;
 }
+
+int BSocket_SetSendBuffer (BSocket *bs, int buf_size)
+{
+    ASSERT(buf_size > 0)
+    DebugObject_Access(&bs->d_obj);
+    
+    if (setsockopt(bs->socket, SOL_SOCKET, SO_SNDBUF, (void *)&buf_size, sizeof(buf_size)) < 0) {
+        bs->error = translate_error(errno);
+        return -1;
+    }
+    
+    bs->error = BSOCKET_ERROR_NONE;
+    return 0;
+}

+ 9 - 0
system/BSocket.h

@@ -460,4 +460,13 @@ BReactor * BSocket_Reactor (BSocket *bs);
  */
 int BSocket_SockFd (BSocket *bs);
 
+/**
+ * Sets the socket's send buffer (SO_SNDBUF).
+ * 
+ * @param bs the object
+ * @param buf_size buffer size in bytes. Must be >0.
+ * @return 0 for success, -1 for failure
+ */
+int BSocket_SetSendBuffer (BSocket *bs, int buf_size);
+
 #endif