example_clock building and working
This commit is contained in:
25
example_clock.cc
Normal file
25
example_clock.cc
Normal 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();
|
||||
}
|
||||
Reference in New Issue
Block a user