proxygen
UDPAcceptor Class Reference
Inheritance diagram for UDPAcceptor:

Public Member Functions

 UDPAcceptor (EventBase *evb)
 
void onListenStarted () noexceptoverride
 
void onListenStopped () noexceptoverride
 
void onDataAvailable (std::shared_ptr< folly::AsyncUDPSocket > socket, const folly::SocketAddress &client, std::unique_ptr< folly::IOBuf > data, bool) noexceptoverride
 
 UDPAcceptor (EventBase *evb, int n, bool changePortForWrites)
 
void onListenStarted () noexceptoverride
 
void onListenStopped () noexceptoverride
 
void onDataAvailable (std::shared_ptr< folly::AsyncUDPSocket > socket, const folly::SocketAddress &client, std::unique_ptr< folly::IOBuf > data, bool truncated) noexceptoverride
 
void sendPong (std::shared_ptr< folly::AsyncUDPSocket > socket) noexcept
 

Private Attributes

EventBase *const evb_ {nullptr}
 
const int n_ {-1}
 
bool changePortForWrites_ {true}
 
folly::SocketAddress lastClient_
 
std::string lastMsg_
 

Detailed Description

Definition at line 94 of file AsyncUDPSocketGSOTest.cpp.

Constructor & Destructor Documentation

UDPAcceptor::UDPAcceptor ( EventBase evb)
inline

Definition at line 96 of file AsyncUDPSocketGSOTest.cpp.

96 : evb_(evb) {}
EventBase *const evb_
UDPAcceptor::UDPAcceptor ( EventBase evb,
int  n,
bool  changePortForWrites 
)
inline

Definition at line 42 of file AsyncUDPSocketTest.cpp.

43  : evb_(evb), n_(n), changePortForWrites_(changePortForWrites) {}
EventBase *const evb_

Member Function Documentation

void UDPAcceptor::onDataAvailable ( std::shared_ptr< folly::AsyncUDPSocket socket,
const folly::SocketAddress client,
std::unique_ptr< folly::IOBuf data,
bool  truncated 
)
inlineoverridenoexcept

Definition at line 49 of file AsyncUDPSocketTest.cpp.

References data, and folly::netops::socket().

53  {
54  lastClient_ = client;
55  lastMsg_ = data->clone()->moveToFbString().toStdString();
56 
57  auto len = data->computeChainDataLength();
58  VLOG(4) << "Worker " << n_ << " read " << len << " bytes "
59  << "(trun:" << truncated << ") from " << client.describe() << " - "
60  << lastMsg_;
61 
63  }
std::string lastMsg_
std::unique_ptr< IOBuf > clone() const
Definition: IOBuf.cpp:527
std::string describe() const
folly::SocketAddress lastClient_
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
std::size_t computeChainDataLength() const
Definition: IOBuf.cpp:501
void sendPong(std::shared_ptr< folly::AsyncUDPSocket > socket) noexcept
void UDPAcceptor::onDataAvailable ( std::shared_ptr< folly::AsyncUDPSocket socket,
const folly::SocketAddress client,
std::unique_ptr< folly::IOBuf data,
bool   
)
inlineoverridenoexcept

Definition at line 102 of file AsyncUDPSocketGSOTest.cpp.

References folly::IOBuf::clone().

106  {
107  // send pong
108  socket->write(client, data->clone());
109  }
std::unique_ptr< IOBuf > clone() const
Definition: IOBuf.cpp:527
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
void UDPAcceptor::onListenStarted ( )
inlineoverridenoexcept

Definition at line 45 of file AsyncUDPSocketTest.cpp.

45 {}
void UDPAcceptor::onListenStarted ( )
inlineoverridenoexcept

Definition at line 98 of file AsyncUDPSocketGSOTest.cpp.

98 {}
void UDPAcceptor::onListenStopped ( )
inlineoverridenoexcept

Definition at line 47 of file AsyncUDPSocketTest.cpp.

47 {}
void UDPAcceptor::onListenStopped ( )
inlineoverridenoexcept

Definition at line 100 of file AsyncUDPSocketGSOTest.cpp.

100 {}
void UDPAcceptor::sendPong ( std::shared_ptr< folly::AsyncUDPSocket socket)
inlinenoexcept

Definition at line 65 of file AsyncUDPSocketTest.cpp.

References folly::IOBuf::copyBuffer(), evb_, and folly::netops::socket().

65  {
66  try {
67  auto writeSocket = socket;
69  writeSocket = std::make_shared<folly::AsyncUDPSocket>(evb_);
70  writeSocket->setReuseAddr(false);
71  writeSocket->bind(folly::SocketAddress("127.0.0.1", 0));
72  }
73  writeSocket->write(lastClient_, folly::IOBuf::copyBuffer(lastMsg_));
74  } catch (const std::exception& ex) {
75  VLOG(4) << "Failed to send PONG " << ex.what();
76  }
77  }
std::string lastMsg_
folly::SocketAddress lastClient_
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
EventBase *const evb_
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
Definition: IOBuf.h:1587

Member Data Documentation

bool UDPAcceptor::changePortForWrites_ {true}
private

Definition at line 83 of file AsyncUDPSocketTest.cpp.

EventBase *const UDPAcceptor::evb_ {nullptr}
private

Definition at line 112 of file AsyncUDPSocketGSOTest.cpp.

folly::SocketAddress UDPAcceptor::lastClient_
private

Definition at line 85 of file AsyncUDPSocketTest.cpp.

std::string UDPAcceptor::lastMsg_
private

Definition at line 86 of file AsyncUDPSocketTest.cpp.

const int UDPAcceptor::n_ {-1}
private

Definition at line 81 of file AsyncUDPSocketTest.cpp.


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