From 76a4de976ad66df26aedd949a2c62e19d88ceb30 Mon Sep 17 00:00:00 2001 From: Christopher Dykes Date: Wed, 10 Aug 2016 13:15:18 -0700 Subject: [PATCH] Don't attempt to call getsockname before binding an async socket Summary: With WinSock, calling `getsockname` on a socket before it's been bound will always result in an error, so make sure to bind the socket first. Reviewed By: yfeldblum Differential Revision: D3698112 fbshipit-source-id: e9efe05323b242add3808ee1a6fec2593beb04ac --- folly/io/async/AsyncServerSocket.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/folly/io/async/AsyncServerSocket.cpp b/folly/io/async/AsyncServerSocket.cpp index ee1239d5..cbabc6f4 100644 --- a/folly/io/async/AsyncServerSocket.cpp +++ b/folly/io/async/AsyncServerSocket.cpp @@ -392,11 +392,6 @@ void AsyncServerSocket::bind(uint16_t port) { &v6only, sizeof(v6only))); } - SocketAddress address; - address.setFromLocalAddress(s); - - sockets_.emplace_back(eventBase_, s, this, address.getFamily()); - // Bind to the socket if (fsp::bind(s, res->ai_addr, res->ai_addrlen) != 0) { folly::throwSystemError( @@ -406,6 +401,11 @@ void AsyncServerSocket::bind(uint16_t port) { " family ", SocketAddress::getFamilyNameFrom(res->ai_addr, "")); } + + SocketAddress address; + address.setFromLocalAddress(s); + + sockets_.emplace_back(eventBase_, s, this, address.getFamily()); }; const int kNumTries = 25; -- 2.34.1