proxygen
folly::AsyncServerSocket::RemoteAcceptor Class Reference
Inheritance diagram for folly::AsyncServerSocket::RemoteAcceptor:
folly::NotificationQueue< MessageT >::Consumer

Public Member Functions

 RemoteAcceptor (AcceptCallback *callback, ConnectionEventCallback *connectionEventCallback)
 
 ~RemoteAcceptor () override=default
 
void start (EventBase *eventBase, uint32_t maxAtOnce, uint32_t maxInQueue)
 
void stop (EventBase *eventBase, AcceptCallback *callback)
 
void messageAvailable (QueueMessage &&message) noexceptoverride
 
NotificationQueue< QueueMessage > * getQueue ()
 

Private Attributes

AcceptCallbackcallback_
 
ConnectionEventCallbackconnectionEventCallback_
 
NotificationQueue< QueueMessagequeue_
 

Additional Inherited Members

- Private Types inherited from folly::NotificationQueue< MessageT >::Consumer
enum  : uint16_t { kDefaultMaxReadAtOnce = 10 }
 
- Private Member Functions inherited from folly::NotificationQueue< MessageT >::Consumer
 Consumer ()
 
virtual void messageAvailable (MessageT &&message) noexcept=0
 
void startConsuming (EventBase *eventBase, NotificationQueue *queue)
 
void startConsumingInternal (EventBase *eventBase, NotificationQueue *queue)
 
void stopConsuming ()
 
bool consumeUntilDrained (size_t *numConsumed=nullptr) noexcept
 
NotificationQueuegetCurrentQueue () const
 
void setMaxReadAtOnce (uint32_t maxAtOnce)
 
uint32_t getMaxReadAtOnce () const
 
EventBasegetEventBase ()
 
void handlerReady (uint16_t events) noexceptoverride
 
template<typename TCallback >
std::unique_ptr< typename NotificationQueue< MessageT >::Consumer, DelayedDestruction::Destructormake (TCallback &&callback)
 
void destroy () override
 
 ~Consumer () override
 
- Private Member Functions inherited from folly::DelayedDestruction
bool getDestroyPending () const
 
 ~DelayedDestruction () override=default
 
 DelayedDestruction ()
 
- Private Member Functions inherited from folly::DelayedDestructionBase
virtual ~DelayedDestructionBase ()=default
 
 DelayedDestructionBase ()
 
uint32_t getDestructorGuardCount () const
 
- Static Private Member Functions inherited from folly::NotificationQueue< MessageT >::Consumer
template<typename TCallback >
static std::unique_ptr< Consumer, DelayedDestruction::Destructormake (TCallback &&callback)
 

Detailed Description

A class to receive notifications to invoke AcceptCallback objects in other EventBase threads.

A RemoteAcceptor object is created for each AcceptCallback that is installed in a separate EventBase thread. The RemoteAcceptor receives notification of new sockets via a NotificationQueue, and then invokes the AcceptCallback.

Definition at line 761 of file AsyncServerSocket.h.

Constructor & Destructor Documentation

folly::AsyncServerSocket::RemoteAcceptor::RemoteAcceptor ( AcceptCallback callback,
ConnectionEventCallback connectionEventCallback 
)
inlineexplicit

Definition at line 763 of file AsyncServerSocket.h.

References folly::pushmi::__adl::noexcept(), start, stop(), and uint32_t.

766  : callback_(callback),
767  connectionEventCallback_(connectionEventCallback) {}
ConnectionEventCallback * connectionEventCallback_
folly::AsyncServerSocket::RemoteAcceptor::~RemoteAcceptor ( )
overridedefault

Member Function Documentation

NotificationQueue<QueueMessage>* folly::AsyncServerSocket::RemoteAcceptor::getQueue ( )
inline

Definition at line 776 of file AsyncServerSocket.h.

Referenced by folly::AsyncServerSocket::dispatchError(), and folly::AsyncServerSocket::dispatchSocket().

776  {
777  return &queue_;
778  }
NotificationQueue< QueueMessage > queue_
void folly::AsyncServerSocket::RemoteAcceptor::messageAvailable ( QueueMessage &&  message)
overridenoexcept

Definition at line 114 of file AsyncServerSocket.cpp.

References folly::AsyncServerSocket::AcceptCallback::acceptError(), callback_, folly::AsyncServerSocket::AcceptCallback::connectionAccepted(), connectionEventCallback_, folly::AsyncServerSocket::MSG_ERROR, folly::AsyncServerSocket::MSG_NEW_CONN, and folly::AsyncServerSocket::ConnectionEventCallback::onConnectionDequeuedByAcceptorCallback().

115  {
116  switch (msg.type) {
120  msg.fd, msg.address);
121  }
122  callback_->connectionAccepted(msg.fd, msg.address);
123  break;
124  }
125  case MessageType::MSG_ERROR: {
126  std::runtime_error ex(msg.msg);
127  callback_->acceptError(ex);
128  break;
129  }
130  default: {
131  LOG(ERROR) << "invalid accept notification message type "
132  << int(msg.type);
133  std::runtime_error ex(
134  "received invalid accept notification message type");
135  callback_->acceptError(ex);
136  }
137  }
138 }
virtual void onConnectionDequeuedByAcceptorCallback(const int socket, const SocketAddress &addr) noexcept=0
virtual void connectionAccepted(int fd, const SocketAddress &clientAddr) noexcept=0
ConnectionEventCallback * connectionEventCallback_
virtual void acceptError(const std::exception &ex) noexcept=0
void folly::AsyncServerSocket::RemoteAcceptor::start ( EventBase eventBase,
uint32_t  maxAtOnce,
uint32_t  maxInQueue 
)

Definition at line 82 of file AsyncServerSocket.cpp.

References queue_, folly::EventBase::runInEventBaseThread(), and folly::NotificationQueue< MessageT >::Consumer::setMaxReadAtOnce().

Referenced by folly::AsyncServerSocket::addAcceptCallback().

85  {
86  setMaxReadAtOnce(maxAtOnce);
87  queue_.setMaxQueueSize(maxInQueue);
88 
89  if (!eventBase->runInEventBaseThread([=]() {
90  callback_->acceptStarted();
91  this->startConsuming(eventBase, &queue_);
92  })) {
93  throw std::invalid_argument(
94  "unable to start waiting on accept "
95  "notification queue in the specified "
96  "EventBase thread");
97  }
98 }
void setMaxReadAtOnce(uint32_t maxAtOnce)
NotificationQueue< QueueMessage > queue_
void folly::AsyncServerSocket::RemoteAcceptor::stop ( EventBase eventBase,
AcceptCallback callback 
)

Definition at line 100 of file AsyncServerSocket.cpp.

References folly::EventBase::runInEventBaseThread().

Referenced by folly::AsyncServerSocket::removeAcceptCallback().

102  {
103  if (!eventBase->runInEventBaseThread([=]() {
104  callback->acceptStopped();
105  delete this;
106  })) {
107  throw std::invalid_argument(
108  "unable to start waiting on accept "
109  "notification queue in the specified "
110  "EventBase thread");
111  }
112 }

Member Data Documentation

AcceptCallback* folly::AsyncServerSocket::RemoteAcceptor::callback_
private

Definition at line 781 of file AsyncServerSocket.h.

Referenced by messageAvailable().

ConnectionEventCallback* folly::AsyncServerSocket::RemoteAcceptor::connectionEventCallback_
private

Definition at line 782 of file AsyncServerSocket.h.

Referenced by messageAvailable().

NotificationQueue<QueueMessage> folly::AsyncServerSocket::RemoteAcceptor::queue_
private

Definition at line 784 of file AsyncServerSocket.h.

Referenced by start().


The documentation for this class was generated from the following files: