emp-toolkit
check_io_channel.h
Go to the documentation of this file.
1 #ifndef CHECK_IO_CHANNEL_H__
2 #define CHECK_IO_CHANNEL_H__
3 #include <iostream>
4 #include <string>
5 #include "net_io_channel.h"
6 using namespace std;
7 
13 class CheckIO: public IOChannel<CheckIO> { public:
15  bool check_result = true;
16  char * buffer = nullptr;
17  char * net_buffer = nullptr;
18  int check_size = 0;
19  CheckIO(NetIO * netio ) {
20  this->netio = netio;
21  buffer = new char[CHECK_BUFFER_SIZE];
22  net_buffer = new char[CHECK_BUFFER_SIZE];
23  }
25  delete[] buffer;
26  delete[] net_buffer;
27  }
28 
30  netio->recv_data(net_buffer, check_size);
31  check_result &= (strncmp(net_buffer, buffer, check_size)==0);
32  check_size = 0;
33  return check_result;
34  }
35 
36 
37  void recv_data_impl(void * data, int len) {
38  }
39  void send_data_impl(const void * data, int len) {
40  assert(len < CHECK_BUFFER_SIZE);
41  if(check_size + len >= CHECK_BUFFER_SIZE) {
42  netio->recv_data(net_buffer, check_size);
43  check_result &= (strncmp(net_buffer, buffer, check_size)==0);
44  check_size = 0;
45  }
46  memcpy(buffer+check_size, data, len);
47  check_size += len;
48  }
49 };
51 #endif//CHECK_IO_CHANNEL
bool get_check_result()
Definition: check_io_channel.h:29
void recv_data(void *data, int nbyte)
Definition: io_channel.h:17
void send_data_impl(const void *data, int len)
Definition: check_io_channel.h:39
#define CHECK_BUFFER_SIZE
Definition: config.h:9
Definition: net_io_channel.h:22
Definition: check_io_channel.h:13
~CheckIO()
Definition: check_io_channel.h:24
Definition: io_channel.h:12
CheckIO(NetIO *netio)
Definition: check_io_channel.h:19
NetIO * netio
Definition: check_io_channel.h:14
void recv_data_impl(void *data, int len)
Definition: check_io_channel.h:37