X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fio%2Fasync%2FAsyncServerSocket.cpp;h=8a70d77cc188701d60875ee0bde36386f8721fe0;hb=b669462b65cacda010d6dca11bc56f9aee768ebc;hp=6b2b9466ee22aa4d53ef5e9661c0b5b6839c0d46;hpb=ed8c80a0e0988e4ce687f51ca832a00e4a6b7930;p=folly.git diff --git a/folly/io/async/AsyncServerSocket.cpp b/folly/io/async/AsyncServerSocket.cpp index 6b2b9466..8a70d77c 100644 --- a/folly/io/async/AsyncServerSocket.cpp +++ b/folly/io/async/AsyncServerSocket.cpp @@ -90,8 +90,7 @@ void AsyncServerSocket::RemoteAcceptor::stop( } void AsyncServerSocket::RemoteAcceptor::messageAvailable( - QueueMessage&& msg) { - + QueueMessage&& msg) noexcept { switch (msg.type) { case MessageType::MSG_NEW_CONN: { @@ -183,7 +182,9 @@ int AsyncServerSocket::stopAccepting(int shutdownFlags) { VLOG(10) << "AsyncServerSocket::stopAccepting " << this << handler.socket_; } - assert(eventBase_ == nullptr || eventBase_->isInEventBaseThread()); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); + } // When destroy is called, unregister and close the socket immediately. accepting_ = false; @@ -245,7 +246,7 @@ void AsyncServerSocket::destroy() { void AsyncServerSocket::attachEventBase(EventBase *eventBase) { assert(eventBase_ == nullptr); - assert(eventBase->isInEventBaseThread()); + eventBase->dcheckIsInEventBaseThread(); eventBase_ = eventBase; for (auto& handler : sockets_) { @@ -255,7 +256,7 @@ void AsyncServerSocket::attachEventBase(EventBase *eventBase) { void AsyncServerSocket::detachEventBase() { assert(eventBase_ != nullptr); - assert(eventBase_->isInEventBaseThread()); + eventBase_->dcheckIsInEventBaseThread(); assert(!accepting_); eventBase_ = nullptr; @@ -265,7 +266,9 @@ void AsyncServerSocket::detachEventBase() { } void AsyncServerSocket::useExistingSockets(const std::vector& fds) { - assert(eventBase_ == nullptr || eventBase_->isInEventBaseThread()); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); + } if (sockets_.size() > 0) { throw std::invalid_argument( @@ -281,6 +284,13 @@ void AsyncServerSocket::useExistingSockets(const std::vector& fds) { SocketAddress address; address.setFromLocalAddress(fd); +#if __linux__ + if (noTransparentTls_) { + // Ignore return value, errors are ok + setsockopt(fd, SOL_SOCKET, SO_NO_TRANSPARENT_TLS, nullptr, 0); + } +#endif + setupSocket(fd, address.getFamily()); sockets_.emplace_back(eventBase_, fd, this, address.getFamily()); sockets_.back().changeHandlerFD(fd); @@ -298,6 +308,7 @@ void AsyncServerSocket::bindSocket( sockaddr_storage addrStorage; address.getAddress(&addrStorage); sockaddr* saddr = reinterpret_cast(&addrStorage); + if (fsp::bind(fd, saddr, address.getActualSize()) != 0) { if (!isExistingSocket) { closeNoInt(fd); @@ -307,6 +318,13 @@ void AsyncServerSocket::bindSocket( address.describe()); } +#if __linux__ + if (noTransparentTls_) { + // Ignore return value, errors are ok + setsockopt(fd, SOL_SOCKET, SO_NO_TRANSPARENT_TLS, nullptr, 0); + } +#endif + // If we just created this socket, update the EventHandler and set socket_ if (!isExistingSocket) { sockets_.emplace_back(eventBase_, fd, this, address.getFamily()); @@ -314,7 +332,9 @@ void AsyncServerSocket::bindSocket( } void AsyncServerSocket::bind(const SocketAddress& address) { - assert(eventBase_ == nullptr || eventBase_->isInEventBaseThread()); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); + } // useExistingSocket() may have been called to initialize socket_ already. // However, in the normal case we need to create a new socket now. @@ -413,6 +433,13 @@ void AsyncServerSocket::bind(uint16_t port) { SocketAddress::getFamilyNameFrom(res->ai_addr, "")); } +#if __linux__ + if (noTransparentTls_) { + // Ignore return value, errors are ok + setsockopt(s, SOL_SOCKET, SO_NO_TRANSPARENT_TLS, nullptr, 0); + } +#endif + SocketAddress address; address.setFromLocalAddress(s); @@ -484,7 +511,9 @@ void AsyncServerSocket::bind(uint16_t port) { } void AsyncServerSocket::listen(int backlog) { - assert(eventBase_ == nullptr || eventBase_->isInEventBaseThread()); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); + } // Start listening for (auto& handler : sockets_) { @@ -518,7 +547,9 @@ std::vector AsyncServerSocket::getAddresses() void AsyncServerSocket::addAcceptCallback(AcceptCallback *callback, EventBase *eventBase, uint32_t maxAtOnce) { - assert(eventBase_ == nullptr || eventBase_->isInEventBaseThread()); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); + } // If this is the first accept callback and we are supposed to be accepting, // start accepting once the callback is installed. @@ -564,7 +595,9 @@ void AsyncServerSocket::addAcceptCallback(AcceptCallback *callback, void AsyncServerSocket::removeAcceptCallback(AcceptCallback *callback, EventBase *eventBase) { - assert(eventBase_ == nullptr || eventBase_->isInEventBaseThread()); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); + } // Find the matching AcceptCallback. // We just do a simple linear search; we don't expect removeAcceptCallback() @@ -627,7 +660,9 @@ void AsyncServerSocket::removeAcceptCallback(AcceptCallback *callback, } void AsyncServerSocket::startAccepting() { - assert(eventBase_ == nullptr || eventBase_->isInEventBaseThread()); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); + } accepting_ = true; if (callbacks_.empty()) { @@ -645,7 +680,9 @@ void AsyncServerSocket::startAccepting() { } void AsyncServerSocket::pauseAccepting() { - assert(eventBase_ == nullptr || eventBase_->isInEventBaseThread()); + if (eventBase_) { + eventBase_->dcheckIsInEventBaseThread(); + } accepting_ = false; for (auto& handler : sockets_) { handler. unregisterHandler(); @@ -1002,7 +1039,8 @@ void AsyncServerSocket::backoffTimeoutExpired() { // the backoff timeout. assert(accepting_); // We can't be detached from the EventBase without being paused - assert(eventBase_ != nullptr && eventBase_->isInEventBaseThread()); + assert(eventBase_ != nullptr); + eventBase_->dcheckIsInEventBaseThread(); // If all of the callbacks were removed, we shouldn't re-enable accepts if (callbacks_.empty()) { @@ -1032,6 +1070,4 @@ void AsyncServerSocket::backoffTimeoutExpired() { } } - - -} // folly +} // namespace folly