test_socket.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_SOCKET_TEST_SOCKET_H
27 #define ODVA_ETHERNETIP_SOCKET_TEST_SOCKET_H
28 
29 #include <string>
30 #include <boost/asio.hpp>
31 
33 
34 using std::size_t;
35 using std::string;
36 using namespace boost::asio;
37 
38 namespace eip {
39 namespace socket {
40 
44 class TestSocket : public Socket
45 {
46 public:
47 
49  bool is_open;
50 
52  string hostname;
53 
55  string port;
56 
58  unsigned char tx_buffer[4096];
60  size_t tx_count;
61 
63  const_buffer rx_buffer;
65  size_t rx_count;
66 
67  TestSocket() : tx_count(0), rx_count(0), is_open(false) { }
68 
69  TestSocket(const_buffer rbuf) : tx_count(0), rx_count(0), rx_buffer(rbuf), is_open(false) { }
70 
76  virtual void open(string hostname, string port)
77  {
78  this->hostname = hostname;
79  this->port = port;
80  is_open = true;
81  }
82 
86  virtual void close()
87  {
88  is_open = false;
89  }
90 
96  virtual size_t send(const_buffer buf)
97  {
98  size_t n = buffer_copy(buffer(tx_buffer) + tx_count, buf);
99  tx_count += n;
100  return n;
101  }
102 
108  virtual size_t receive(mutable_buffer buf)
109  {
110  size_t n = buffer_copy(buf, rx_buffer);
111  rx_count += n;
112  rx_buffer = rx_buffer + n;
113  return n;
114  }
115 
120  {
121  tx_count = 0;
122  memset(tx_buffer, 0, sizeof(tx_count));
123  }
124 
125 };
126 
127 } // namespace socket
128 } // namespace eip
129 #endif // ODVA_ETHERNETIP_SOCKET_TEST_SOCKET_H
bool is_open
Whether the socket has been opened.
Definition: test_socket.h:49
size_t tx_count
Number of characters sent via send()
Definition: test_socket.h:60
string port
Port given at open.
Definition: test_socket.h:55
TestSocket(const_buffer rbuf)
Definition: test_socket.h:69
virtual void close()
Definition: test_socket.h:86
Definition: connection.h:41
virtual size_t receive(mutable_buffer buf)
Definition: test_socket.h:108
string hostname
Hostname given at open.
Definition: test_socket.h:52
virtual void open(string hostname, string port)
Definition: test_socket.h:76
size_t rx_count
Number of characters requested by client by calling receive()
Definition: test_socket.h:65
virtual size_t send(const_buffer buf)
Definition: test_socket.h:96
const_buffer rx_buffer
Characters to return on calls to receive()
Definition: test_socket.h:63


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Mon Jun 10 2019 14:00:16