2019-04-26 05:34:19 +00:00
|
|
|
#include <gflags/gflags.h>
|
|
|
|
|
#include <glog/logging.h>
|
2019-04-29 00:11:07 +00:00
|
|
|
#include <sys/time.h>
|
2019-04-28 00:17:32 +00:00
|
|
|
|
2019-04-28 21:30:15 +00:00
|
|
|
#include "sse.h"
|
2019-04-26 05:34:19 +00:00
|
|
|
|
|
|
|
|
DEFINE_int32(port, 9000, "TCP port to bind");
|
|
|
|
|
|
|
|
|
|
int main(int argc, char *argv[]) {
|
|
|
|
|
google::InitGoogleLogging(argv[0]);
|
|
|
|
|
gflags::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
|
|
2019-04-28 21:30:15 +00:00
|
|
|
SSEServer server(FLAGS_port, [](std::unique_ptr<SSEStream> stream) {
|
2019-04-29 00:11:07 +00:00
|
|
|
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);
|
|
|
|
|
}
|
2019-04-28 06:47:30 +00:00
|
|
|
});
|
2019-04-28 00:17:32 +00:00
|
|
|
server.Serve();
|
2019-04-26 05:34:19 +00:00
|
|
|
}
|