From 023744f6cd8c7d79333def7e77060c859cc35cd1 Mon Sep 17 00:00:00 2001 From: Dan Melnic Date: Tue, 22 Oct 2019 16:36:37 -0700 Subject: [PATCH] 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 --- folly/io/async/AsyncServerSocket.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/folly/io/async/AsyncServerSocket.cpp b/folly/io/async/AsyncServerSocket.cpp index 1c9f3edf6f0..1a35ce7d438 100644 --- a/folly/io/async/AsyncServerSocket.cpp +++ b/folly/io/async/AsyncServerSocket.cpp @@ -374,17 +374,15 @@ void AsyncServerSocket::bind( if (ipAddresses.empty()) { throw std::invalid_argument("No ip addresses were provided"); } - if (!sockets_.empty()) { - throw std::invalid_argument( - "Cannot call bind on a AsyncServerSocket " - "that already has a socket."); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); } for (const IPAddress& ipAddress : ipAddresses) { SocketAddress address(ipAddress.toFullyQualified(), port); auto fd = createSocket(address.getFamily()); - bindSocket(fd, address, false); + bindSocket(fd, address, !sockets_.empty()); } if (sockets_.size() == 0) { throw std::runtime_error(