client.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. #include "log.h"
  2. #include "zio.h"
  3. #include "message_file.h"
  4. #include "thread"
  5. #include "chrono"
  6. int main()
  7. {
  8. int sock=zio::build_stream();
  9. if(zio::connect(sock,"127.0.0.1",4000))
  10. //if(zio::connect(sock,"192.168.8.116",4000))
  11. {
  12. return -1;
  13. }
  14. zio::setiobuf(sock,32<<10,64<<10);
  15. zio::setblocking(sock,false);
  16. int len=1;
  17. int count=0x400+2;
  18. char buf[8192];
  19. uint64_t time;
  20. #if 0
  21. for(int i=0;i<8000;i++)
  22. {
  23. buf[i]='1';
  24. }
  25. buf[0]=0x04;
  26. buf[1]=0x00;
  27. char recv_buf[8192];
  28. for(;;)
  29. {
  30. while(zio::read(sock,recv_buf,sizeof(recv_buf))>0);
  31. if(count!=zio::writev(sock,buf,count))
  32. break;
  33. }
  34. #else
  35. message_file mf(stdin);
  36. count=0;
  37. uint64_t time_tmp=0;
  38. while(len>0)
  39. {
  40. //while((len=mf.get_line(&time,&buf[count],sizeof(buf)-count)))
  41. {
  42. std_info("......%lu",time);
  43. count+=len;
  44. if(count>1024)
  45. break;
  46. }
  47. len=mf.get_line(&time,&buf[count],sizeof(buf)-count);
  48. if(0==time_tmp)
  49. time_tmp =time;
  50. std::this_thread::sleep_for(std::chrono::milliseconds(time-time_tmp));
  51. log_info("count=%d,time=%llu buf=%s",len,time,buf);
  52. if(count!=zio::writev(sock,buf,count))
  53. break;
  54. count=0;
  55. }
  56. #endif
  57. zio::close(sock);
  58. return 0;
  59. }