proxygen
|
#include <AsyncUDPServerSocket.h>
Classes | |
class | Callback |
Public Member Functions | |
AsyncUDPServerSocket (EventBase *evb, size_t sz=1500) | |
~AsyncUDPServerSocket () override | |
void | bind (const folly::SocketAddress &addy) |
void | setReusePort (bool reusePort) |
folly::SocketAddress | address () const |
void | getAddress (SocketAddress *a) const override |
void | addListener (EventBase *evb, Callback *callback) |
void | listen () |
int | getFD () const |
void | close () |
EventBase * | getEventBase () const override |
void | pauseAccepting () |
void | resumeAccepting () |
Public Member Functions inherited from folly::AsyncSocketBase | |
virtual | ~AsyncSocketBase ()=default |
Private Types | |
typedef std::pair< EventBase *, Callback * > | Listener |
Private Member Functions | |
void | getReadBuffer (void **buf, size_t *len) noexceptoverride |
void | onDataAvailable (const folly::SocketAddress &clientAddress, size_t len, bool truncated) noexceptoverride |
void | onReadError (const AsyncSocketException &ex) noexceptoverride |
void | onReadClosed () noexceptoverride |
Private Member Functions inherited from folly::AsyncUDPSocket::ReadCallback | |
virtual | ~ReadCallback ()=default |
Private Attributes | |
EventBase *const | evb_ |
const size_t | packetSize_ |
std::shared_ptr< AsyncUDPSocket > | socket_ |
std::vector< Listener > | listeners_ |
uint32_t | nextListener_ |
folly::IOBufQueue | buf_ |
bool | reusePort_ {false} |
UDP server socket
It wraps a UDP socket waiting for packets and distributes them among a set of event loops in round robin fashion.
NOTE: At the moment it is designed to work with single packet protocols in mind. We distribute incoming packets among all the listeners in round-robin fashion. So, any protocol that expects to send/recv more than 1 packet will not work because they will end up with different event base to process.
Definition at line 38 of file AsyncUDPServerSocket.h.
|
private |
Definition at line 240 of file AsyncUDPServerSocket.h.
|
inlineexplicit |
Create a new UDP server socket
Note about packet size - We allocate buffer of packetSize_ size to read. If packet are larger than this value, as per UDP protocol, remaining data is dropped and you get truncated = true
in onDataAvailable callback
Definition at line 86 of file AsyncUDPServerSocket.h.
|
inlineoverride |
Definition at line 89 of file AsyncUDPServerSocket.h.
References close(), and socket_.
Add a listener to the round robin list
Definition at line 119 of file AsyncUDPServerSocket.h.
References listeners_.
|
inline |
Definition at line 107 of file AsyncUDPServerSocket.h.
References socket_.
Referenced by getAddress().
|
inline |
Definition at line 95 of file AsyncUDPServerSocket.h.
References evb_, reusePort_, and socket_.
|
inline |
Definition at line 141 of file AsyncUDPServerSocket.h.
References socket_.
Referenced by ~AsyncUDPServerSocket().
|
inlineoverridevirtual |
Implements folly::AsyncSocketBase.
Definition at line 112 of file AsyncUDPServerSocket.h.
References address().
|
inlineoverridevirtual |
Implements folly::AsyncSocketBase.
Definition at line 147 of file AsyncUDPServerSocket.h.
References evb_.
Referenced by wangle::AsyncUDPServerSocketFactory::ThreadSafeDestructor::operator()().
|
inline |
Definition at line 136 of file AsyncUDPServerSocket.h.
References socket_.
|
inlineoverrideprivatevirtualnoexcept |
Invoked when the socket becomes readable and we want buffer to write to.
NOTE: From socket we will end up reading at most len
bytes and if there were more bytes in datagram, we will end up dropping them.
Implements folly::AsyncUDPSocket::ReadCallback.
Definition at line 179 of file AsyncUDPServerSocket.h.
References buf_, packetSize_, and folly::IOBufQueue::preallocate().
|
inline |
Definition at line 123 of file AsyncUDPServerSocket.h.
References listeners_, and socket_.
|
inlineoverrideprivatevirtualnoexcept |
Invoked when a new datagraom is available on the socket. len
is the number of bytes read and truncated
is true if we had to drop few bytes because of running out of buffer space.
Implements folly::AsyncUDPSocket::ReadCallback.
Definition at line 183 of file AsyncUDPServerSocket.h.
References buf_, folly::data(), f, listeners_, folly::gen::move, nextListener_, folly::IOBufQueue::postallocate(), folly::netops::socket(), socket_, folly::IOBufQueue::split(), and folly::WARNING.
|
inlineoverrideprivatevirtualnoexcept |
Invoked when socket is closed and a read callback is registered.
Implements folly::AsyncUDPSocket::ReadCallback.
Definition at line 225 of file AsyncUDPServerSocket.h.
References listeners_.
|
inlineoverrideprivatevirtualnoexcept |
Invoked when there is an error reading from the socket.
NOTE: Since UDP is connectionless, you can still read from the socket. But you have to re-register readCallback yourself after onReadError.
Implements folly::AsyncUDPSocket::ReadCallback.
Definition at line 218 of file AsyncUDPServerSocket.h.
References socket_.
|
inline |
Pauses accepting datagrams on the underlying socket.
Definition at line 154 of file AsyncUDPServerSocket.h.
References listeners_, and socket_.
|
inline |
Starts accepting datagrams once again.
Definition at line 167 of file AsyncUDPServerSocket.h.
References listeners_, and socket_.
|
inline |
|
private |
Definition at line 247 of file AsyncUDPServerSocket.h.
Referenced by getReadBuffer(), and onDataAvailable().
|
private |
Definition at line 234 of file AsyncUDPServerSocket.h.
Referenced by bind(), and getEventBase().
|
private |
Definition at line 241 of file AsyncUDPServerSocket.h.
Referenced by addListener(), listen(), onDataAvailable(), onReadClosed(), pauseAccepting(), and resumeAccepting().
|
private |
Definition at line 244 of file AsyncUDPServerSocket.h.
Referenced by onDataAvailable().
|
private |
Definition at line 235 of file AsyncUDPServerSocket.h.
Referenced by getReadBuffer().
|
private |
Definition at line 249 of file AsyncUDPServerSocket.h.
Referenced by bind(), and setReusePort().
|
private |
Definition at line 237 of file AsyncUDPServerSocket.h.
Referenced by address(), bind(), close(), getFD(), listen(), onDataAvailable(), onReadError(), pauseAccepting(), resumeAccepting(), and ~AsyncUDPServerSocket().