浏览代码

Bug 1732: Optimizing S3 connection buffers for speed

(cherry picked from commit 9625854f7291aea93bc18ec8260aba311464bb25)

https://winscp.net/tracker/1732

Source commit: 3580d615b739f3ca43ffca57135f456edfb6a70b
Martin Prikryl 5 年之前
父节点
当前提交
2de2fdc42b
共有 5 个文件被更改,包括 30 次插入0 次删除
  1. 3 0
      libs/neon/src/ne_request.c
  2. 1 0
      libs/neon/src/ne_session.h
  3. 21 0
      libs/neon/src/ne_socket.c
  4. 3 0
      libs/neon/src/ne_socket.h
  5. 2 0
      source/core/S3FileSystem.cpp

+ 3 - 0
libs/neon/src/ne_request.c

@@ -1650,6 +1650,9 @@ static int do_connect(ne_session *sess, struct host_info *host)
     if (sess->rdtimeout)
 	ne_sock_read_timeout(sess->socket, sess->rdtimeout);
 
+    // WINSCP
+    ne_sock_set_buffers(sess->socket, ne_get_session_flag(sess, SE_SESSFLAG_SNDBUF));
+
     notify_status(sess, ne_status_connected);
     sess->nexthop = host;
 

+ 1 - 0
libs/neon/src/ne_session.h

@@ -106,6 +106,7 @@ typedef enum ne_session_flag_e {
 
     #ifdef WINSCP
     NE_SESSFLAG_LIBERAL_ESCAPING,
+    SE_SESSFLAG_SNDBUF,
     #endif
 
     NE_SESSFLAG_LAST /* enum sentinel value */

+ 21 - 0
libs/neon/src/ne_socket.c

@@ -2008,3 +2008,24 @@ int ne_sock_close(ne_socket *sock)
     ne_free(sock);
     return ret;
 }
+
+// WINSCP
+void do_ne_sock_sndbuf(ne_socket *sock, int opt, unsigned int buf)
+{
+    unsigned int value = 0;
+    int len = sizeof(value);
+    getsockopt(sock->fd, SOL_SOCKET, opt, &value, &len);
+    if (value < buf)
+    {
+        setsockopt(sock->fd, SOL_SOCKET, opt, &buf, sizeof(buf));
+    }
+}
+
+void ne_sock_set_buffers(ne_socket *sock, unsigned int sndbuf)
+{
+    if (sndbuf > 0)
+    {
+        do_ne_sock_sndbuf(sock, SO_SNDBUF, sndbuf);
+        do_ne_sock_sndbuf(sock, SO_RCVBUF, 4 * 1024 * 1024);
+    }
+}

+ 3 - 0
libs/neon/src/ne_socket.h

@@ -307,6 +307,9 @@ int ne_sock_proxy(ne_socket *sock, enum ne_sock_sversion vers,
                   unsigned int port,
                   const char *username, const char *password);
 
+// WINSCP
+void ne_sock_set_buffers(ne_socket *sock, unsigned int sndbuf);
+
 NE_END_DECLS
 
 #endif /* NE_SOCKET_H */

+ 2 - 0
source/core/S3FileSystem.cpp

@@ -185,6 +185,8 @@ void TS3FileSystem::LibS3SessionCallback(ne_session_s * Session, void * Callback
 
   SetNeonTlsInit(Session, FileSystem->InitSslSession);
 
+  ne_set_session_flag(Session, SE_SESSFLAG_SNDBUF, Data->SendBuf);
+
   // Data->Timeout is propagated via timeoutMs parameter of functions like S3_list_service
 
   FileSystem->FNeonSession = Session;