void onMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp receiveTime) { printf("onMessage(): tid=%d received %d bytes from connection [%s] at %s\n", CurrentThread::tid(), buf->readableBytes(), conn->name().c_str(), receiveTime.toFormattedString().c_str()); string str(buf->peek(), buf->readableBytes()); printf("str:%s\n", str.c_str()); buf->retrieveAll(); }
int main() { Timestamp timestamp = Timestamp::now(); cout << sizeof(A) << endl << sizeof(B) << endl; //1 ,8 cout << sizeof(C) << endl;//windowsƽ̨Ϊ16 cout << "sizeof(copyable):"<<sizeof(copyable)<<endl; cout << "sizeof(timestamp)"<<sizeof(timestamp) << endl; cout << endl << endl; cout << "time seocnds:" << timestamp.secondsSinceEpoch() << endl; string str = timestamp.toFormattedString(); cout << str << endl; }
void MyTcpClient::onMessage(const TcpConnectionPtr& conn, Buffer* buf, Timestamp receiveTime) { if (buf->readableBytes() >= sizeof(int32_t)) { /* const void* data = buf->peek(); int32_t be32 = *static_cast<const int32_t*>(data); buf->retrieve(sizeof(int32_t)); time_t time = sockets::networkToHost32(be32); Timestamp ts(implicit_cast<uint64_t>(time) * Timestamp::kMicroSecondsPerSecond); LOG_INFO << "Server time = " << time << ", " << ts.toFormattedString(); */ std::string str = static_cast<std::string>(buf->retrieveAllAsString()); LOG_INFO << "Server time = " << str; } else { LOG_INFO << conn->name() << " no enough data " << buf->readableBytes() << " at " << receiveTime.toFormattedString(); } }
TEST(TimestampTest, Ops) { Timestamp stamp = Timestamp::now(); LOG(INFO) << stamp.toFormattedString(); }
void defaultReadEventCallback(Timestamp ts) { LOG_INFO << "defaultReadEventCallback [" << ts.toFormattedString() << "]"; }
void timePubish() { Timestamp now = Timestamp::now(); doPublish("internal", "utc_time", now.toFormattedString(), now); }
void timePublish() { Timestamp now = Timestamp::now(); distributePublish("utc_time", now.toFormattedString().data()); }