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

Method onMessage

examples/simple/timeclient/timeclient.cc:51–67  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 }
50
51 void onMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp receiveTime)
52 {
53 if (buf->readableBytes() >= sizeof(int32_t))
54 {
55 const void* data = buf->peek();
56 int32_t be32 = *static_cast<const int32_t*>(data);
57 buf->retrieve(sizeof(int32_t));
58 time_t time = sockets::networkToHost32(be32);
59 Timestamp ts(implicit_cast<uint64_t>(time) * Timestamp::kMicroSecondsPerSecond);
60 LOG_INFO << "Server time = " << time << ", " << ts.toFormattedString();
61 }
62 else
63 {
64 LOG_INFO << conn->name() << " no enough data " << buf->readableBytes()
65 << " at " << receiveTime.toFormattedString();
66 }
67 }
68};
69
70int main(int argc, char* argv[])

Callers

nothing calls this directly

Calls 5

networkToHost32Function · 0.85
readableBytesMethod · 0.80
peekMethod · 0.80
retrieveMethod · 0.80
toFormattedStringMethod · 0.80

Tested by

no test coverage detected