#include "log.h" #include "zio.h" #include "message_file.h" #include "thread" #include "chrono" int main() { int sock=zio::build_stream(); if(zio::connect(sock,"127.0.0.1",4000)) //if(zio::connect(sock,"192.168.8.116",4000)) { return -1; } zio::setiobuf(sock,32<<10,64<<10); zio::setblocking(sock,false); int len=1; int count=0x400+2; char buf[8192]; uint64_t time; #if 0 for(int i=0;i<8000;i++) { buf[i]='1'; } buf[0]=0x04; buf[1]=0x00; char recv_buf[8192]; for(;;) { while(zio::read(sock,recv_buf,sizeof(recv_buf))>0); if(count!=zio::writev(sock,buf,count)) break; } #else message_file mf(stdin); count=0; uint64_t time_tmp=0; while(len>0) { //while((len=mf.get_line(&time,&buf[count],sizeof(buf)-count))) { std_info("......%lu",time); count+=len; if(count>1024) break; } len=mf.get_line(&time,&buf[count],sizeof(buf)-count); if(0==time_tmp) time_tmp =time; std::this_thread::sleep_for(std::chrono::milliseconds(time-time_tmp)); log_info("count=%d,time=%llu buf=%s",len,time,buf); if(count!=zio::writev(sock,buf,count)) break; count=0; } #endif zio::close(sock); return 0; }