aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2017-09-01 16:29:35 +0000
committerDimitry Andric <dim@FreeBSD.org>2017-09-01 16:29:35 +0000
commit50640c91565c298232ed5d2dacc018dd0e11116c (patch)
tree64b32180a933e08bbfb4b9eb2e01c7181f034c38
parentf9cfece4e841319f868ef5eac1d5350c35f2bf19 (diff)
downloadsrc-50640c91565c298232ed5d2dacc018dd0e11116c.tar.gz
src-50640c91565c298232ed5d2dacc018dd0e11116c.zip
Vendor import of lldb release_50 branch r312293:vendor/lldb/lldb-release_500-r312559vendor/lldb/lldb-release_50-r312293
Notes
Notes: svn path=/vendor/lldb/dist/; revision=323098 svn path=/vendor/lldb/lldb-release_500-r312559/; revision=323244; tag=vendor/lldb/lldb-release_500-r312559
-rw-r--r--source/Host/common/TCPSocket.cpp11
-rw-r--r--unittests/Host/SocketTest.cpp11
2 files changed, 19 insertions, 3 deletions
diff --git a/source/Host/common/TCPSocket.cpp b/source/Host/common/TCPSocket.cpp
index a7af93f10a7f..f896944bb1b3 100644
--- a/source/Host/common/TCPSocket.cpp
+++ b/source/Host/common/TCPSocket.cpp
@@ -198,9 +198,14 @@ Status TCPSocket::Listen(llvm::StringRef name, int backlog) {
::setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, option_value_p,
sizeof(option_value));
- address.SetPort(port);
-
- int err = ::bind(fd, &address.sockaddr(), address.GetLength());
+ SocketAddress listen_address = address;
+ if(!listen_address.IsLocalhost())
+ listen_address.SetToAnyAddress(address.GetFamily(), port);
+ else
+ listen_address.SetPort(port);
+
+ int err =
+ ::bind(fd, &listen_address.sockaddr(), listen_address.GetLength());
if (-1 != err)
err = ::listen(fd, backlog);
diff --git a/unittests/Host/SocketTest.cpp b/unittests/Host/SocketTest.cpp
index d8fdc593ed46..59f59fc0ada7 100644
--- a/unittests/Host/SocketTest.cpp
+++ b/unittests/Host/SocketTest.cpp
@@ -220,3 +220,14 @@ TEST_F(SocketTest, UDPConnect) {
EXPECT_TRUE(error.Success());
EXPECT_TRUE(socket_up->IsValid());
}
+
+TEST_F(SocketTest, TCPListen0GetPort) {
+ Socket *server_socket;
+ Predicate<uint16_t> port_predicate;
+ port_predicate.SetValue(0, eBroadcastNever);
+ Status err =
+ Socket::TcpListen("10.10.12.3:0", false, server_socket, &port_predicate);
+ std::unique_ptr<TCPSocket> socket_up((TCPSocket*)server_socket);
+ EXPECT_TRUE(socket_up->IsValid());
+ EXPECT_NE(socket_up->GetLocalPortNumber(), 0);
+}