proxygen
UDPServer Class Reference

Public Member Functions

 UDPServer (EventBase *evb, folly::SocketAddress addr, int n)
 
void start ()
 
folly::SocketAddress address () const
 
void shutdown ()
 
void pauseAccepting ()
 
void resumeAccepting ()
 
 UDPServer (EventBase *evb, folly::SocketAddress addr, int n)
 
void start ()
 
folly::SocketAddress address () const
 
void shutdown ()
 
void pauseAccepting ()
 
void resumeAccepting ()
 
void setChangePortForWrites (bool changePortForWrites)
 

Private Attributes

EventBase *const evb_ {nullptr}
 
const folly::SocketAddress addr_
 
std::unique_ptr< AsyncUDPServerSocketsocket_
 
std::vector< std::thread > threads_
 
std::vector< folly::EventBaseevbs_
 
std::vector< UDPAcceptoracceptors_
 
bool changePortForWrites_ {true}
 

Detailed Description

Definition at line 115 of file AsyncUDPSocketGSOTest.cpp.

Constructor & Destructor Documentation

UDPServer::UDPServer ( EventBase evb,
folly::SocketAddress  addr,
int  n 
)
inline

Definition at line 117 of file AsyncUDPSocketGSOTest.cpp.

118  : evb_(evb), addr_(addr), evbs_(n) {}
std::vector< folly::EventBase > evbs_
const folly::SocketAddress addr_
EventBase *const evb_
UDPServer::UDPServer ( EventBase evb,
folly::SocketAddress  addr,
int  n 
)
inline

Definition at line 91 of file AsyncUDPSocketTest.cpp.

92  : evb_(evb), addr_(addr), evbs_(n) {}
std::vector< folly::EventBase > evbs_
const folly::SocketAddress addr_
EventBase *const evb_

Member Function Documentation

folly::SocketAddress UDPServer::address ( ) const
inline

Definition at line 126 of file AsyncUDPSocketTest.cpp.

References socket_.

126  {
127  return socket_->address();
128  }
std::unique_ptr< AsyncUDPServerSocket > socket_
folly::SocketAddress UDPServer::address ( ) const
inline

Definition at line 152 of file AsyncUDPSocketGSOTest.cpp.

References socket_.

152  {
153  return socket_->address();
154  }
std::unique_ptr< AsyncUDPServerSocket > socket_
void UDPServer::pauseAccepting ( )
inline

Definition at line 144 of file AsyncUDPSocketTest.cpp.

References socket_.

144  {
145  socket_->pauseAccepting();
146  }
std::unique_ptr< AsyncUDPServerSocket > socket_
void UDPServer::pauseAccepting ( )
inline

Definition at line 170 of file AsyncUDPSocketGSOTest.cpp.

References socket_.

170  {
171  socket_->pauseAccepting();
172  }
std::unique_ptr< AsyncUDPServerSocket > socket_
void UDPServer::resumeAccepting ( )
inline

Definition at line 148 of file AsyncUDPSocketTest.cpp.

References socket_.

148  {
149  socket_->resumeAccepting();
150  }
std::unique_ptr< AsyncUDPServerSocket > socket_
void UDPServer::resumeAccepting ( )
inline

Definition at line 174 of file AsyncUDPSocketGSOTest.cpp.

References socket_.

174  {
175  socket_->resumeAccepting();
176  }
std::unique_ptr< AsyncUDPServerSocket > socket_
void UDPServer::setChangePortForWrites ( bool  changePortForWrites)
inline

Definition at line 153 of file AsyncUDPSocketTest.cpp.

References evb_, and socket_.

153  {
154  changePortForWrites_ = changePortForWrites;
155  }
void UDPServer::shutdown ( )
inline

Definition at line 130 of file AsyncUDPSocketTest.cpp.

References evb_, folly::EventBase::isInEventBaseThread(), socket_, and folly::pushmi::detail::t.

130  {
131  CHECK(evb_->isInEventBaseThread());
132  socket_->close();
133  socket_.reset();
134 
135  for (auto& evb : evbs_) {
136  evb.terminateLoopSoon();
137  }
138 
139  for (auto& t : threads_) {
140  t.join();
141  }
142  }
std::vector< std::thread > threads_
std::unique_ptr< AsyncUDPServerSocket > socket_
bool isInEventBaseThread() const
Definition: EventBase.h:504
std::vector< folly::EventBase > evbs_
EventBase *const evb_
void UDPServer::shutdown ( )
inline

Definition at line 156 of file AsyncUDPSocketGSOTest.cpp.

References evb_, folly::EventBase::isInEventBaseThread(), socket_, and folly::pushmi::detail::t.

156  {
157  CHECK(evb_->isInEventBaseThread());
158  socket_->close();
159  socket_.reset();
160 
161  for (auto& evb : evbs_) {
162  evb.terminateLoopSoon();
163  }
164 
165  for (auto& t : threads_) {
166  t.join();
167  }
168  }
std::vector< std::thread > threads_
std::unique_ptr< AsyncUDPServerSocket > socket_
bool isInEventBaseThread() const
Definition: EventBase.h:504
std::vector< folly::EventBase > evbs_
EventBase *const evb_
void UDPServer::start ( )
inline

Definition at line 94 of file AsyncUDPSocketTest.cpp.

References evb_, i, folly::EventBase::isInEventBaseThread(), folly::gen::move, socket_, and folly::pushmi::detail::t.

94  {
95  CHECK(evb_->isInEventBaseThread());
96 
97  socket_ = std::make_unique<AsyncUDPServerSocket>(evb_, 1500);
98 
99  try {
100  socket_->bind(addr_);
101  VLOG(4) << "Server listening on " << socket_->address().describe();
102  } catch (const std::exception& ex) {
103  LOG(FATAL) << ex.what();
104  }
105 
106  acceptors_.reserve(evbs_.size());
107  threads_.reserve(evbs_.size());
108 
109  // Add numWorkers thread
110  int i = 0;
111  for (auto& evb : evbs_) {
112  acceptors_.emplace_back(&evb, i, changePortForWrites_);
113 
114  std::thread t([&]() { evb.loopForever(); });
115 
116  evb.waitUntilRunning();
117 
118  socket_->addListener(&evb, &acceptors_[i]);
119  threads_.emplace_back(std::move(t));
120  ++i;
121  }
122 
123  socket_->listen();
124  }
std::vector< std::thread > threads_
std::unique_ptr< AsyncUDPServerSocket > socket_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool isInEventBaseThread() const
Definition: EventBase.h:504
std::vector< folly::EventBase > evbs_
std::vector< UDPAcceptor > acceptors_
const folly::SocketAddress addr_
EventBase *const evb_
void UDPServer::start ( )
inline

Definition at line 120 of file AsyncUDPSocketGSOTest.cpp.

References evb_, i, folly::EventBase::isInEventBaseThread(), folly::gen::move, socket_, and folly::pushmi::detail::t.

120  {
121  CHECK(evb_->isInEventBaseThread());
122 
123  socket_ = std::make_unique<AsyncUDPServerSocket>(evb_, 1500);
124 
125  try {
126  socket_->bind(addr_);
127  VLOG(4) << "Server listening on " << socket_->address().describe();
128  } catch (const std::exception& ex) {
129  LOG(FATAL) << ex.what();
130  }
131 
132  acceptors_.reserve(evbs_.size());
133  threads_.reserve(evbs_.size());
134 
135  // Add numWorkers thread
136  int i = 0;
137  for (auto& evb : evbs_) {
138  acceptors_.emplace_back(&evb);
139 
140  std::thread t([&]() { evb.loopForever(); });
141 
142  evb.waitUntilRunning();
143 
144  socket_->addListener(&evb, &acceptors_[i]);
145  threads_.emplace_back(std::move(t));
146  ++i;
147  }
148 
149  socket_->listen();
150  }
std::vector< std::thread > threads_
std::unique_ptr< AsyncUDPServerSocket > socket_
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
bool isInEventBaseThread() const
Definition: EventBase.h:504
std::vector< folly::EventBase > evbs_
std::vector< UDPAcceptor > acceptors_
const folly::SocketAddress addr_
EventBase *const evb_

Member Data Documentation

std::vector< UDPAcceptor > UDPServer::acceptors_
private

Definition at line 185 of file AsyncUDPSocketGSOTest.cpp.

const folly::SocketAddress UDPServer::addr_
private

Definition at line 180 of file AsyncUDPSocketGSOTest.cpp.

bool UDPServer::changePortForWrites_ {true}
private

Definition at line 165 of file AsyncUDPSocketTest.cpp.

EventBase *const UDPServer::evb_ {nullptr}
private

Definition at line 179 of file AsyncUDPSocketGSOTest.cpp.

std::vector< folly::EventBase > UDPServer::evbs_
private

Definition at line 184 of file AsyncUDPSocketGSOTest.cpp.

std::unique_ptr< AsyncUDPServerSocket > UDPServer::socket_
private

Definition at line 182 of file AsyncUDPSocketGSOTest.cpp.

std::vector< std::thread > UDPServer::threads_
private

Definition at line 183 of file AsyncUDPSocketGSOTest.cpp.


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