Commit e2a71713 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Correctly bind to the wildcard address in AsyncServerSocket::bind

Summary: Because Windows disagrees with everything else about how to specify that you want the wildcard address. It's done with an empty string on Windows, but `nullptr` everywhere else.

Reviewed By: yfeldblum

Differential Revision: D4216970

fbshipit-source-id: b5dc136946d9677a96be3252e44d383a6abca800
parent cc97c6ea
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <folly/io/async/AsyncServerSocket.h> #include <folly/io/async/AsyncServerSocket.h>
#include <folly/FileUtil.h> #include <folly/FileUtil.h>
#include <folly/Portability.h>
#include <folly/SocketAddress.h> #include <folly/SocketAddress.h>
#include <folly/String.h> #include <folly/String.h>
#include <folly/detail/SocketFastOpen.h> #include <folly/detail/SocketFastOpen.h>
...@@ -370,7 +371,10 @@ void AsyncServerSocket::bind(uint16_t port) { ...@@ -370,7 +371,10 @@ void AsyncServerSocket::bind(uint16_t port) {
hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV; hints.ai_flags = AI_PASSIVE | AI_NUMERICSERV;
snprintf(sport, sizeof(sport), "%u", port); snprintf(sport, sizeof(sport), "%u", port);
if (getaddrinfo(nullptr, sport, &hints, &res0)) { // On Windows the value we need to pass to bind to all available
// addresses is an empty string. Everywhere else, it's nullptr.
constexpr const char* kWildcardNode = kIsWindows ? "" : nullptr;
if (getaddrinfo(kWildcardNode, sport, &hints, &res0)) {
throw std::invalid_argument( throw std::invalid_argument(
"Attempted to bind address to socket with " "Attempted to bind address to socket with "
"bad getaddrinfo"); "bad getaddrinfo");
......
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