proxygen
folly::ZeroCopyTestServer Class Reference

#include <ZeroCopy.h>

Inheritance diagram for folly::ZeroCopyTestServer:
folly::AsyncServerSocket::AcceptCallback

Public Member Functions

 ZeroCopyTestServer (folly::EventBase *evb, int numLoops, size_t bufferSize, bool zeroCopy)
 
void addCallbackToServerSocket (folly::AsyncServerSocket &sock)
 
void connectionAccepted (int fd, const folly::SocketAddress &) noexceptoverride
 
void acceptError (const std::exception &) noexceptoverride
 
- Public Member Functions inherited from folly::AsyncServerSocket::AcceptCallback
virtual ~AcceptCallback ()=default
 
virtual void acceptStarted () noexcept
 
virtual void acceptStopped () noexcept
 

Private Attributes

folly::EventBaseevb_
 
int numLoops_
 
size_t bufferSize_
 
bool zeroCopy_
 
std::unique_ptr< ZeroCopyTestAsyncSocketclient_
 
std::unordered_map< ZeroCopyTestAsyncSocket *, std::shared_ptr< ZeroCopyTestAsyncSocket > > clients_
 

Detailed Description

Definition at line 213 of file ZeroCopy.h.

Constructor & Destructor Documentation

folly::ZeroCopyTestServer::ZeroCopyTestServer ( folly::EventBase evb,
int  numLoops,
size_t  bufferSize,
bool  zeroCopy 
)
inlineexplicit

Definition at line 215 of file ZeroCopy.h.

220  : evb_(evb),
221  numLoops_(numLoops),
222  bufferSize_(bufferSize),
223  zeroCopy_(zeroCopy) {}
folly::EventBase * evb_
Definition: ZeroCopy.h:240

Member Function Documentation

void folly::ZeroCopyTestServer::acceptError ( const std::exception &  ex)
inlineoverridevirtualnoexcept

acceptError() is called if an error occurs while accepting.

The AcceptCallback will remain installed even after an accept error, as the errors are typically somewhat transient, such as being out of file descriptors. The server socket must be explicitly stopped if you wish to stop accepting after an error.

Parameters
exAn exception representing the error.

Implements folly::AsyncServerSocket::AcceptCallback.

Definition at line 237 of file ZeroCopy.h.

237 {}
void folly::ZeroCopyTestServer::addCallbackToServerSocket ( folly::AsyncServerSocket sock)
inline

Definition at line 225 of file ZeroCopy.h.

References folly::AsyncServerSocket::addAcceptCallback(), and folly::ZeroCopyTestAsyncSocket::evb_.

Referenced by folly::ZeroCopyTest::ZeroCopyTest().

225  {
226  sock.addAcceptCallback(this, evb_);
227  }
folly::EventBase * evb_
Definition: ZeroCopy.h:240
virtual void addAcceptCallback(AcceptCallback *callback, EventBase *eventBase, uint32_t maxAtOnce=kDefaultCallbackAcceptAtOnce)
void folly::ZeroCopyTestServer::connectionAccepted ( int  fd,
const folly::SocketAddress clientAddr 
)
inlineoverridevirtualnoexcept

connectionAccepted() is called whenever a new client connection is received.

The AcceptCallback will remain installed after connectionAccepted() returns.

Parameters
fdThe newly accepted client socket. The AcceptCallback assumes ownership of this socket, and is responsible for closing it when done. The newly accepted file descriptor will have already been put into non-blocking mode.
clientAddrA reference to a SocketAddress struct containing the client's address. This struct is only guaranteed to remain valid until connectionAccepted() returns.

Implements folly::AsyncServerSocket::AcceptCallback.

Definition at line 229 of file ZeroCopy.h.

References folly::ZeroCopyTestAsyncSocket::bufferSize_, folly::ZeroCopyTestAsyncSocket::evb_, folly::ZeroCopyTestAsyncSocket::numLoops_, and folly::ZeroCopyTestAsyncSocket::zeroCopy_.

231  {
232  auto client = std::make_shared<ZeroCopyTestAsyncSocket>(
233  nullptr, evb_, fd, numLoops_, bufferSize_, zeroCopy_);
234  clients_[client.get()] = client;
235  }
std::unordered_map< ZeroCopyTestAsyncSocket *, std::shared_ptr< ZeroCopyTestAsyncSocket > > clients_
Definition: ZeroCopy.h:248
folly::EventBase * evb_
Definition: ZeroCopy.h:240

Member Data Documentation

size_t folly::ZeroCopyTestServer::bufferSize_
private

Definition at line 242 of file ZeroCopy.h.

std::unique_ptr<ZeroCopyTestAsyncSocket> folly::ZeroCopyTestServer::client_
private

Definition at line 244 of file ZeroCopy.h.

std::unordered_map< ZeroCopyTestAsyncSocket*, std::shared_ptr<ZeroCopyTestAsyncSocket> > folly::ZeroCopyTestServer::clients_
private

Definition at line 248 of file ZeroCopy.h.

folly::EventBase* folly::ZeroCopyTestServer::evb_
private

Definition at line 240 of file ZeroCopy.h.

int folly::ZeroCopyTestServer::numLoops_
private

Definition at line 241 of file ZeroCopy.h.

bool folly::ZeroCopyTestServer::zeroCopy_
private

Definition at line 243 of file ZeroCopy.h.


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