Commit 76a4de97 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot 0

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
parent c326c636
...@@ -392,11 +392,6 @@ void AsyncServerSocket::bind(uint16_t port) { ...@@ -392,11 +392,6 @@ void AsyncServerSocket::bind(uint16_t port) {
&v6only, sizeof(v6only))); &v6only, sizeof(v6only)));
} }
SocketAddress address;
address.setFromLocalAddress(s);
sockets_.emplace_back(eventBase_, s, this, address.getFamily());
// Bind to the socket // Bind to the socket
if (fsp::bind(s, res->ai_addr, res->ai_addrlen) != 0) { if (fsp::bind(s, res->ai_addr, res->ai_addrlen) != 0) {
folly::throwSystemError( folly::throwSystemError(
...@@ -406,6 +401,11 @@ void AsyncServerSocket::bind(uint16_t port) { ...@@ -406,6 +401,11 @@ void AsyncServerSocket::bind(uint16_t port) {
" family ", " family ",
SocketAddress::getFamilyNameFrom(res->ai_addr, "<unknown>")); SocketAddress::getFamilyNameFrom(res->ai_addr, "<unknown>"));
} }
SocketAddress address;
address.setFromLocalAddress(s);
sockets_.emplace_back(eventBase_, s, this, address.getFamily());
}; };
const int kNumTries = 25; const int kNumTries = 25;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment