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

Method onConnection

examples/ace/logging/client.cc:64–89  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

62
63 private:
64 void onConnection(const TcpConnectionPtr& conn)
65 {
66 LOG_INFO << conn->localAddress().toIpPort() << " -> "
67 << conn->peerAddress().toIpPort() << " is "
68 << (conn->connected() ? "UP" : "DOWN");
69
70 MutexLockGuard lock(mutex_);
71 if (conn->connected())
72 {
73 connection_ = conn;
74 LogRecord_Heartbeat* hb = logRecord_.mutable_heartbeat();
75 hb->set_hostname(ProcessInfo::hostname().c_str());
76 hb->set_process_name(ProcessInfo::procname().c_str());
77 hb->set_process_id(ProcessInfo::pid());
78 hb->set_process_start_time(ProcessInfo::startTime().microSecondsSinceEpoch());
79 hb->set_username(ProcessInfo::username().c_str());
80 updateLogRecord("Heartbeat");
81 codec_.send(connection_, logRecord_);
82 logRecord_.clear_heartbeat();
83 LOG_INFO << "Type message below:";
84 }
85 else
86 {
87 connection_.reset();
88 }
89 }
90
91 void onMessage(const TcpConnectionPtr&,
92 const MessagePtr& message,

Callers

nothing calls this directly

Calls 6

c_strMethod · 0.80
toIpPortMethod · 0.45
connectedMethod · 0.45
sendMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected