Commit 023744f6 authored by Dan Melnic's avatar Dan Melnic Committed by Facebook Github Bot

Allow AsyncServerSocket::bind to be called for multiple addrs (same as for port bind)

Summary: Allow AsyncServerSocket::bind to be called for multiple addrs (same as for port bind)

Reviewed By: yfeldblum

Differential Revision: D18046496

fbshipit-source-id: efde498fbaa02357d7c66905b8c1e5e839062076
parent 8f2abf77
...@@ -374,17 +374,15 @@ void AsyncServerSocket::bind( ...@@ -374,17 +374,15 @@ void AsyncServerSocket::bind(
if (ipAddresses.empty()) { if (ipAddresses.empty()) {
throw std::invalid_argument("No ip addresses were provided"); throw std::invalid_argument("No ip addresses were provided");
} }
if (!sockets_.empty()) { if (eventBase_) {
throw std::invalid_argument( eventBase_->dcheckIsInEventBaseThread();
"Cannot call bind on a AsyncServerSocket "
"that already has a socket.");
} }
for (const IPAddress& ipAddress : ipAddresses) { for (const IPAddress& ipAddress : ipAddresses) {
SocketAddress address(ipAddress.toFullyQualified(), port); SocketAddress address(ipAddress.toFullyQualified(), port);
auto fd = createSocket(address.getFamily()); auto fd = createSocket(address.getFamily());
bindSocket(fd, address, false); bindSocket(fd, address, !sockets_.empty());
} }
if (sockets_.size() == 0) { if (sockets_.size() == 0) {
throw std::runtime_error( throw std::runtime_error(
......
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