proxygen
AcceptorTest.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015-present, Facebook, Inc.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree. An additional grant
7  * of patent rights can be found in the PATENTS file in the same directory.
8  *
9  */
12 #include <glog/logging.h>
14 
15 using namespace folly;
16 using namespace wangle;
17 
19  public:
20  void timeoutExpired() noexcept override {}
21  void describe(std::ostream& /*os*/) const override {}
22  bool isBusy() const override { return false; }
23  void notifyPendingShutdown() override {}
24  void closeWhenIdle() override {}
25  void dropConnection() override {
26  delete this;
27  }
28  void dumpConnectionState(uint8_t /*loglevel*/) override {}
29 };
30 
31 class TestAcceptor : public Acceptor {
32  public:
33  explicit TestAcceptor(const ServerSocketConfig& accConfig)
34  : Acceptor(accConfig) {}
35 
37  const folly::SocketAddress* /*address*/,
38  const std::string& /*nextProtocolName*/,
39  SecureTransportType /*secureTransportType*/,
40  const TransportInfo& /*tinfo*/) override {
41  addConnection(new TestConnection);
42 
44  }
45 };
46 
47 TEST(AcceptorTest, Basic) {
48 
49  EventBase 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 }
TestAcceptor(const ServerSocketConfig &accConfig)
uint32_t getNumConnections() const
Definition: Acceptor.h:119
State getState() const
Definition: Acceptor.h:148
bool isBusy() const override
void dumpConnectionState(uint8_t) override
EventBase * getEventBase()
void dropConnection() override
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
requires E e noexcept(noexcept(s.error(std::move(e))))
AHArrayT::Config config
void describe(std::ostream &) const override
void closeWhenIdle() override
std::unique_ptr< AsyncTransportWrapper, Destructor > UniquePtr
void terminateLoopSoon()
Definition: EventBase.cpp:493
virtual void forceStop()
Definition: Acceptor.cpp:508
void notifyPendingShutdown() override
static std::shared_ptr< AsyncServerSocket > newSocket(EventBase *evb=nullptr)
NetworkSocket socket(int af, int type, int protocol)
Definition: NetOps.cpp:412
static std::shared_ptr< AsyncSocket > newSocket(EventBase *evb)
Definition: AsyncSocket.h:281
const char * string
Definition: Conv.cpp:212
void onNewConnection(folly::AsyncTransportWrapper::UniquePtr, const folly::SocketAddress *, const std::string &, SecureTransportType, const TransportInfo &) override
TEST(SequencedExecutor, CPUThreadPoolExecutor)
virtual void init(folly::AsyncServerSocket *serverSocket, folly::EventBase *eventBase, SSLStats *stats=nullptr)
Definition: Acceptor.cpp:60
void timeoutExpired() noexceptoverride