tcp_socket.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_SOCKET_TCP_SOCKET_H
27 #define ODVA_ETHERNETIP_SOCKET_TCP_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 using boost::asio::ip::tcp;
38 
39 namespace eip {
40 namespace socket {
41 
45 class TCPSocket : public Socket
46 {
47 public:
48 
49  TCPSocket(io_service& io_serv) : socket_(io_serv) { }
50 
56  virtual void open(string hostname, string port)
57  {
58  tcp::resolver resolver(socket_.get_io_service());
59  tcp::resolver::query query(hostname, port);
60  tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
61  connect(socket_, endpoint_iterator);
62  }
63 
67  virtual inline void close()
68  {
69  socket_.close();
70  }
71 
77  virtual size_t send(const_buffer buf)
78  {
79  return socket_.send(const_buffers_1(buf));
80  }
81 
87  virtual size_t receive(mutable_buffer buf)
88  {
89  // have to make this into a sequence or the templating engine throws a fit
90  return socket_.receive(mutable_buffers_1(buf));
91  }
92 
93 private:
94  tcp::socket socket_;
95 };
96 
97 } // namespace socket
98 } // namespace eip
99 #endif // ODVA_ETHERNETIP_SOCKET_TCP_SOCKET_H
virtual void open(string hostname, string port)
Definition: tcp_socket.h:56
TCPSocket(io_service &io_serv)
Definition: tcp_socket.h:49
Definition: connection.h:41
tcp::socket socket_
Definition: tcp_socket.h:94
virtual size_t send(const_buffer buf)
Definition: tcp_socket.h:77
virtual size_t receive(mutable_buffer buf)
Definition: tcp_socket.h:87
virtual void close()
Definition: tcp_socket.h:67


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