example_clock building and working

This commit is contained in:
flamingcow
2019-05-05 00:11:57 -07:00
commit ee2667bb1a
9 changed files with 154 additions and 0 deletions

25
example_clock.cc Normal file
View File

@@ -0,0 +1,25 @@
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <sys/time.h>
#include "firesse.h"
DEFINE_int32(port, 9000, "TCP port to bind");
int main(int argc, char *argv[]) {
google::InitGoogleLogging(argv[0]);
gflags::ParseCommandLineFlags(&argc, &argv, true);
firesse::Server server(FLAGS_port, [](std::unique_ptr<firesse::Stream> stream) {
while (true) {
timeval tv;
PCHECK(gettimeofday(&tv, nullptr) == 0);
uint64_t time_ms = tv.tv_sec * 1000 + tv.tv_usec / 1000;
if (!stream->WriteEvent(std::to_string(time_ms), 0, "time")) {
break;
}
sleep(1);
}
});
server.Serve();
}