Working clock stream. Propagate up write errors

This commit is contained in:
Ian Gulliver
2019-04-29 00:11:07 +00:00
parent 4d4525b145
commit 205b8253b2
11 changed files with 92 additions and 13 deletions

View File

@@ -1,5 +1,6 @@
#include <gflags/gflags.h>
#include <glog/logging.h>
#include <sys/time.h>
#include "sse.h"
@@ -10,6 +11,15 @@ int main(int argc, char *argv[]) {
gflags::ParseCommandLineFlags(&argc, &argv, true);
SSEServer server(FLAGS_port, [](std::unique_ptr<SSEStream> 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();
}