proxygen
AcceptorTest.cpp File Reference
#include <wangle/acceptor/Acceptor.h>
#include <folly/io/async/EventBase.h>
#include <glog/logging.h>
#include <folly/portability/GTest.h>

Go to the source code of this file.

Classes

class  TestConnection
 
class  TestAcceptor
 

Functions

 TEST (AcceptorTest, Basic)
 

Function Documentation

TEST ( AcceptorTest  ,
Basic   
)

Definition at line 47 of file AcceptorTest.cpp.

References config, wangle::Acceptor::forceStop(), wangle::Acceptor::getNumConnections(), wangle::Acceptor::getState(), wangle::Acceptor::init(), folly::EventBase::loop(), folly::EventBase::loopForever(), folly::AsyncServerSocket::newSocket(), folly::AsyncSocket::newSocket(), and folly::netops::socket().

47  {
48 
49  EventBase base;
50  auto socket = AsyncServerSocket::newSocket(&base);
52 
53  TestAcceptor acceptor(config);
54  socket->addAcceptCallback(&acceptor, &base);
55 
56  acceptor.init(socket.get(), &base);
57  socket->bind(0);
58  socket->listen(100);
59 
60  SocketAddress addy;
61  socket->getAddress(&addy);
62 
63  socket->startAccepting();
64 
65  auto client_socket = AsyncSocket::newSocket(
66  &base, addy);
67 
68  base.loopForever();
69 
70  CHECK_EQ(acceptor.getNumConnections(), 1);
71 
72  CHECK(acceptor.getState() == Acceptor::State::kRunning);
73  acceptor.forceStop();
74  socket->stopAccepting();
75  base.loop();
76 }
AHArrayT::Config config
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412