00001 00026 #ifndef ODVA_ETHERNETIP_SOCKET_TEST_SOCKET_H 00027 #define ODVA_ETHERNETIP_SOCKET_TEST_SOCKET_H 00028 00029 #include <string> 00030 #include <boost/asio.hpp> 00031 00032 #include "odva_ethernetip/socket/socket.h" 00033 00034 using std::size_t; 00035 using std::string; 00036 using namespace boost::asio; 00037 00038 namespace eip { 00039 namespace socket { 00040 00044 class TestSocket : public Socket 00045 { 00046 public: 00047 00049 bool is_open; 00050 00052 string hostname; 00053 00055 string port; 00056 00058 unsigned char tx_buffer[4096]; 00060 size_t tx_count; 00061 00063 const_buffer rx_buffer; 00065 size_t rx_count; 00066 00067 TestSocket() : tx_count(0), rx_count(0), is_open(false) { } 00068 00069 TestSocket(const_buffer rbuf) : tx_count(0), rx_count(0), rx_buffer(rbuf), is_open(false) { } 00070 00076 virtual void open(string hostname, string port) 00077 { 00078 this->hostname = hostname; 00079 this->port = port; 00080 is_open = true; 00081 } 00082 00086 virtual void close() 00087 { 00088 is_open = false; 00089 } 00090 00096 virtual size_t send(const_buffer buf) 00097 { 00098 size_t n = buffer_copy(buffer(tx_buffer) + tx_count, buf); 00099 tx_count += n; 00100 return n; 00101 } 00102 00108 virtual size_t receive(mutable_buffer buf) 00109 { 00110 size_t n = buffer_copy(buf, rx_buffer); 00111 rx_count += n; 00112 rx_buffer = rx_buffer + n; 00113 return n; 00114 } 00115 00119 void clearTxBuffer() 00120 { 00121 tx_count = 0; 00122 memset(tx_buffer, 0, sizeof(tx_count)); 00123 } 00124 00125 }; 00126 00127 } // namespace socket 00128 } // namespace eip 00129 #endif // ODVA_ETHERNETIP_SOCKET_TEST_SOCKET_H