46 : gso_(gso), useSocketGSO_(useSocketGSO) {
47 in_.assign(in, in + inLen);
48 expected_.assign(expected, expected + expectedLen);
65 return (outSize_ >= expectedSize_);
74 std::unique_ptr<folly::IOBuf> ret =
77 for (
size_t i = 1;
i <
in_.size();
i++) {
86 bool useSocketGSO_{
false};
103 std::shared_ptr<folly::AsyncUDPSocket>
socket,
105 std::unique_ptr<folly::IOBuf>
data,
108 socket->write(client, data->
clone());
118 :
evb_(evb), addr_(addr), evbs_(n) {}
123 socket_ = std::make_unique<AsyncUDPServerSocket>(
evb_, 1500);
126 socket_->bind(addr_);
127 VLOG(4) <<
"Server listening on " << socket_->address().describe();
128 }
catch (
const std::exception& ex) {
129 LOG(FATAL) << ex.what();
132 acceptors_.reserve(evbs_.size());
133 threads_.reserve(evbs_.size());
137 for (
auto& evb : evbs_) {
138 acceptors_.emplace_back(&evb);
140 std::thread
t([&]() { evb.loopForever(); });
142 evb.waitUntilRunning();
144 socket_->addListener(&evb, &acceptors_[i]);
161 for (
auto& evb : evbs_) {
162 evb.terminateLoopSoon();
165 for (
auto&
t : threads_) {
182 std::unique_ptr<AsyncUDPServerSocket>
socket_;
184 std::vector<folly::EventBase>
evbs_;
203 VLOG(2) <<
"Client bound to " <<
socket_->address().describe();
204 }
catch (
const std::exception& ex) {
205 LOG(FATAL) << ex.what();
210 LOG(INFO) <<
"GSO not supported";
211 testData_.out_ = testData_.expected_;
216 if (testData_.useSocketGSO_) {
217 socket_->setGSO(testData_.gso_);
229 int ret =
socket_->connect(*connectAddr_);
234 VLOG(2) <<
"Client connected to address=" << *connectAddr_;
248 testData_.getInBuf(), testData_.useSocketGSO_ ? -1 : testData_.gso_);
251 virtual void writePing(std::unique_ptr<folly::IOBuf> buf,
int gso) {
264 VLOG(0) <<
"Got " << len <<
" bytes";
265 if (testData_.appendOut(len)) {
271 VLOG(4) << ex.what();
278 CHECK(
false) <<
"We unregister reads before closing";
282 VLOG(4) <<
"Timeout expired";
291 connectAddr_ = connectAddr;
309 server = std::make_unique<UDPServer>(
314 std::make_unique<std::thread>([
this]() { sevb.loopForever(); });
317 sevb.waitUntilRunning();
322 sevb.runInEventBaseThreadAndWait([&]() { server->start(); });
323 LOG(INFO) <<
"Server listening=" << server->address();
328 sevb.runInEventBaseThread([&]() {
330 sevb.terminateLoopSoon();
334 serverThread->join();
337 std::unique_ptr<UDPClient> performPingPongTest(
343 TestData* testData_{
nullptr};
352 testData_ = &testData;
354 client = std::make_unique<UDPClient>(&cevb, testData);
355 if (connectedAddress) {
356 client->setShouldConnect(*connectedAddress);
360 auto clientThread = std::thread([
this]() { cevb.loopForever(); });
363 cevb.waitUntilRunning();
366 cevb.runInEventBaseThread([&]() { client->start(server->address()); });
375 int in[] = {100, 1200, 3000, 200, 100, 300};
376 int expected[] = {1000, 1000, 1000, 1000, 900};
381 sizeof(in) /
sizeof(in[0]),
383 sizeof(expected) /
sizeof(expected[0]));
386 auto pingClient = performPingPongTest(testData,
folly::none);
392 int in[] = {100, 1200, 3000, 200, 100, 300};
393 int expected[] = {421, 421, 421, 421, 421, 421, 421, 421, 421, 421, 421, 269};
398 sizeof(in) /
sizeof(in[0]),
400 sizeof(expected) /
sizeof(expected[0]));
403 auto pingClient = performPingPongTest(testData,
folly::none);
414 explicit GSOBuf(
size_t size1,
size_t size2 = 0) {
425 const std::unique_ptr<IOBuf>&
get()
const {
446 ssize_t
get()
const {
458 if (client.
getGSO() < 0) {
459 LOG(INFO) <<
"GSO not supported";
470 CHECK_LT(
test.get(), 0);
476 CHECK_LT(
test.get(), 0);
482 CHECK_LT(
test.get(), 0);
488 CHECK_LT(
test.get(), 0);
virtual const folly::SocketAddress & address() const
TestData(int gso, bool useSocketGSO, int *in, size_t inLen, int *expected, size_t expectedLen)
std::vector< std::thread > threads_
AsyncUDPSocket & getSocket()
size_t writePing(IOBufQueue &queue, uint64_t opaqueData, bool ack) noexcept
folly::SocketAddress server_
int connect(NetworkSocket s, const sockaddr *name, socklen_t namelen)
GSOBuf(size_t size1, size_t size2=0)
std::unique_ptr< IOBuf > ioBuf_
void accumulate(std::vector< std::size_t > &a, std::vector< std::size_t > const &d)
std::unique_ptr< AsyncUDPServerSocket > socket_
void onDataAvailable(const folly::SocketAddress &, size_t len, bool) noexceptoverride
UDPAcceptor(EventBase *evb)
TEST_F(TestInfoTest, Names)
std::unique_ptr< folly::IOBuf > getInBuf()
std::unique_ptr< AsyncUDPSocket > socket_
void onDataAvailable(std::shared_ptr< folly::AsyncUDPSocket > socket, const folly::SocketAddress &client, std::unique_ptr< folly::IOBuf > data, bool) noexceptoverride
virtual ssize_t writeGSO(const folly::SocketAddress &address, const std::unique_ptr< folly::IOBuf > &buf, int gso)
void onListenStarted() noexceptoverride
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
constexpr detail::Map< Move > move
folly::Optional< folly::SocketAddress > connectAddr_
void onListenStopped() noexceptoverride
std::unique_ptr< IOBuf > clone() const
UDPServer(EventBase *evb, folly::SocketAddress addr, int n)
requires E e noexcept(noexcept(s.error(std::move(e))))
UDPClient(EventBase *evb, TestData &testData)
std::unique_ptr< UDPClient > client
bool isInEventBaseThread() const
std::vector< folly::EventBase > evbs_
virtual void writePing(std::unique_ptr< folly::IOBuf > buf, int gso)
void start(const folly::SocketAddress &server)
TEST(GTestEnvVarTest, Dummy)
AsyncServerSocket::UniquePtr socket_
void timeoutExpired() noexceptoverride
std::unique_ptr< std::thread > serverThread
std::unique_ptr< UDPServer > server
std::unique_ptr< UDPClient > performPingPongTest(TestData &testData, folly::Optional< folly::SocketAddress > connectedAddress)
ssize_t send(NetworkSocket s, const void *buf, size_t len, int flags)
NetworkSocket socket(int af, int type, int protocol)
std::vector< UDPAcceptor > acceptors_
virtual void bind(const folly::SocketAddress &address)
void prependChain(std::unique_ptr< IOBuf > &&iobuf)
void onReadClosed() noexceptoverride
void setShouldConnect(const folly::SocketAddress &connectAddr)
const folly::SocketAddress addr_
std::vector< int > expected_
const std::unique_ptr< IOBuf > & get() const
void onReadError(const folly::AsyncSocketException &ex) noexceptoverride
void getReadBuffer(void **buf, size_t *len) noexceptoverride
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
#define ASSERT_TRUE(condition)
static constexpr uint64_t data[1]
ThreadPoolListHook * addr
folly::SocketAddress address() const
GSOSendTest(folly::AsyncUDPSocket &socket, const folly::SocketAddress &address, int gso, size_t size1, size_t size2=0)