git-svn-id: svn://elaine/murooma/trunk@6 d8a302eb-03bc-478d-80e4-98257eca68ef
This commit is contained in:
(no author) 2014-06-24 20:22:53 +00:00
parent 105ac263c0
commit 71949a8366
2 changed files with 20 additions and 3 deletions

View file

@ -8,16 +8,30 @@
#include <zmq.hpp> #include <zmq.hpp>
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <sys/time.h>
const size_t size(1024); const size_t size(1024);
struct Chunk struct Chunk
{ {
time_t timestamp; timeval timestamp;
char payload[size]; char payload[size];
}; };
std::string timeToStr(const timeval& timestamp)
{
char tmbuf[64], buf[64];
struct tm *nowtm;
time_t nowtime;
nowtime = timestamp.tv_sec;
nowtm = localtime(&nowtime);
strftime(tmbuf, sizeof tmbuf, "%Y-%m-%d %H:%M:%S", nowtm);
snprintf(buf, sizeof buf, "%s.%06d", tmbuf, timestamp.tv_usec);
return buf;
}
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
zmq::context_t context (1); zmq::context_t context (1);
@ -46,6 +60,8 @@ int main (int argc, char *argv[])
// std::cout << "update\n"; // std::cout << "update\n";
for (size_t n=0; n<size; ++n) for (size_t n=0; n<size; ++n)
std::cout << chunk->payload[n] << std::flush; std::cout << chunk->payload[n] << std::flush;
std::cerr << timeToStr(chunk->timestamp) << "\n";
delete chunk; delete chunk;
// std::cout << std::flush; // std::cout << std::flush;
// std::cerr << "flushed\n"; // std::cerr << "flushed\n";

View file

@ -12,6 +12,7 @@
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include <fcntl.h> #include <fcntl.h>
#include <sys/time.h>
using namespace std; using namespace std;
@ -19,7 +20,7 @@ const int size(1024);
struct Chunk struct Chunk
{ {
time_t timestamp; timeval timestamp;
char payload[size]; char payload[size];
}; };
@ -37,7 +38,7 @@ int main () {
while (!cin.get(c).eof()) while (!cin.get(c).eof())
{ {
if (idx == 0) if (idx == 0)
time(&chunk.timestamp); gettimeofday(&chunk.timestamp, 0);
// read(fd, &msg[0], size); // read(fd, &msg[0], size);
chunk.payload[idx++] = c; chunk.payload[idx++] = c;