From 33aea9001ac4238b08ffa4e0d685a38b258b3641 Mon Sep 17 00:00:00 2001 From: Vince Harron Date: Tue, 31 Mar 2015 00:27:10 +0000 Subject: [PATCH] Increate backlog of lldb-platform's listener socket lldb-platform's listener socket only had a backlog of one connection. That means that if more than one client connected simultaneously, the connection would be refused. The test suite can be run remotely with dozens of threads connecting simultaneously. Raised this limit to 100 to effectively eliminate lost connections. Test Plan: run tests against a remote target Differential Revision: http://reviews.llvm.org/D8696 llvm-svn: 233652 --- lldb/include/lldb/Host/Socket.h | 7 ++++++- lldb/source/Host/common/Socket.cpp | 9 +++++++-- lldb/tools/lldb-server/lldb-platform.cpp | 7 ++++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/lldb/include/lldb/Host/Socket.h b/lldb/include/lldb/Host/Socket.h index ee85f85fcaf2..f4599b5ab87b 100644 --- a/lldb/include/lldb/Host/Socket.h +++ b/lldb/include/lldb/Host/Socket.h @@ -56,7 +56,12 @@ public: // Initialize a Tcp Socket object in listening mode. listen and accept are implemented // separately because the caller may wish to manipulate or query the socket after it is // initialized, but before entering a blocking accept. - static Error TcpListen(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket, Predicate* predicate); + static Error TcpListen( + llvm::StringRef host_and_port, + bool child_processes_inherit, + Socket *&socket, + Predicate* predicate, + int backlog = 5); static Error TcpConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket); static Error UdpConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&send_socket, Socket *&recv_socket); static Error UnixDomainConnect(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket); diff --git a/lldb/source/Host/common/Socket.cpp b/lldb/source/Host/common/Socket.cpp index b5559fffb45d..3bcd934acedb 100644 --- a/lldb/source/Host/common/Socket.cpp +++ b/lldb/source/Host/common/Socket.cpp @@ -167,7 +167,12 @@ Error Socket::TcpConnect(llvm::StringRef host_and_port, bool child_processes_inh return error; } -Error Socket::TcpListen(llvm::StringRef host_and_port, bool child_processes_inherit, Socket *&socket, Predicate* predicate) +Error Socket::TcpListen( + llvm::StringRef host_and_port, + bool child_processes_inherit, + Socket *&socket, + Predicate* predicate, + int backlog) { std::unique_ptr listen_socket; NativeSocket listen_sock = kInvalidSocketValue; @@ -209,7 +214,7 @@ Error Socket::TcpListen(llvm::StringRef host_and_port, bool child_processes_inhe return error; } - err = ::listen (listen_sock, 1); + err = ::listen (listen_sock, backlog); if (err == -1) { // TODO: On Windows, use WSAGetLastError() diff --git a/lldb/tools/lldb-server/lldb-platform.cpp b/lldb/tools/lldb-server/lldb-platform.cpp index 47007ba03ded..2135633a06a6 100644 --- a/lldb/tools/lldb-server/lldb-platform.cpp +++ b/lldb/tools/lldb-server/lldb-platform.cpp @@ -253,7 +253,12 @@ main_platform (int argc, char *argv[]) Socket *socket = nullptr; printf ("Listening for a connection from %s...\n", listen_host_port.c_str()); const bool children_inherit_listen_socket = false; - error = Socket::TcpListen(listen_host_port.c_str(), children_inherit_listen_socket, socket, NULL); + + // the test suite makes many connections in parallel, let's not miss any. + // The highest this should get reasonably is a function of the number + // of target CPUs. For now, let's just use 100 + const int backlog = 100; + error = Socket::TcpListen(listen_host_port.c_str(), children_inherit_listen_socket, socket, NULL, backlog); if (error.Fail()) { printf("error: %s\n", error.AsCString());