MCPcopy Create free account
hub / github.com/chenshuo/muduo / onConnection

Method onConnection

examples/maxconnection/echo.cc:26–46  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

24}
25
26void EchoServer::onConnection(const TcpConnectionPtr& conn)
27{
28 LOG_INFO << "EchoServer - " << conn->peerAddress().toIpPort() << " -> "
29 << conn->localAddress().toIpPort() << " is "
30 << (conn->connected() ? "UP" : "DOWN");
31
32 if (conn->connected())
33 {
34 ++numConnected_;
35 if (numConnected_ > kMaxConnections_)
36 {
37 conn->shutdown();
38 conn->forceCloseWithDelay(3.0); // > round trip of the whole Internet.
39 }
40 }
41 else
42 {
43 --numConnected_;
44 }
45 LOG_INFO << "numConnected = " << numConnected_;
46}
47
48void EchoServer::onMessage(const TcpConnectionPtr& conn,
49 Buffer* buf,

Callers

nothing calls this directly

Calls 4

shutdownMethod · 0.80
forceCloseWithDelayMethod · 0.80
toIpPortMethod · 0.45
connectedMethod · 0.45

Tested by

no test coverage detected