Commit cb0fc3dc authored by Dongyi Ye's avatar Dongyi Ye Committed by Facebook GitHub Bot

Add pause/resumeAcceptingNew

Summary:
The current `pauseAccepting` and `resumeAccepting` will direct operate on the underlying udp socket to pause/resume read any packet. However this makes it hard to make similar behavior as TCP, which stop/pause the listening socket but still serving the accepted socket.
As for UDP the bookkeeping is usually done at upper layer. this change will allowed the `AsyncUDPServerSocket` inform its callback that pause/resume new peer "connection".

Reviewed By: yfeldblum

Differential Revision: D24483859

fbshipit-source-id: ed10eaf3e9ef140112002303e37a73eff7d40943
parent 25fe3ce3
......@@ -66,6 +66,20 @@ class AsyncUDPServerSocket : private AsyncUDPSocket::ReadCallback,
*/
virtual void onListenResumed() noexcept {}
/**
* Invoked when the server socket can still read but need to inform the
* callback object that it should not process read from new client address.
* It is invoked in each acceptors/listeners event base thread.
*/
virtual void onAcceptNewPeerPaused() noexcept {}
/**
* Invoked when need to inform the callback object that it can resume
* process read from new client address. It is invoked in each
* acceptors/listeners event base thread.
*/
virtual void onAcceptNewPeerResumed() noexcept {}
/**
* Invoked when a new packet is received
*/
......@@ -185,6 +199,19 @@ class AsyncUDPServerSocket : private AsyncUDPSocket::ReadCallback,
}
}
/**
* Inform the callback object that it should not process read from new client
* address.
*/
void pauseAcceptingNewPeer() {
for (auto& listener : listeners_) {
auto callback = listener.second;
listener.first->runInEventBaseThread(
[callback]() mutable { callback->onAcceptNewPeerPaused(); });
}
}
/**
* Starts accepting datagrams once again.
*/
......@@ -198,6 +225,19 @@ class AsyncUDPServerSocket : private AsyncUDPSocket::ReadCallback,
}
}
/**
* Inform the callback object that it can process read from new client address
* now.
*/
void resumeAcceptingNewPeer() {
for (auto& listener : listeners_) {
auto callback = listener.second;
listener.first->runInEventBaseThread(
[callback]() mutable { callback->onAcceptNewPeerResumed(); });
}
}
void setEventCallback(EventRecvmsgCallback* cb) {
eventCb_ = cb;
applyEventCallback();
......
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