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(GET_IO_SERVICE(&socket_));
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
eip
Definition: connection.h:41
eip::socket::TCPSocket::close
virtual void close()
Definition: tcp_socket.h:67
eip::socket::TCPSocket::send
virtual size_t send(const_buffer buf)
Definition: tcp_socket.h:77
eip::socket::TCPSocket::TCPSocket
TCPSocket(io_service &io_serv)
Definition: tcp_socket.h:49
eip::socket::TCPSocket
Definition: tcp_socket.h:45
eip::socket::TCPSocket::receive
virtual size_t receive(mutable_buffer buf)
Definition: tcp_socket.h:87
socket.h
GET_IO_SERVICE
#define GET_IO_SERVICE(s)
Definition: socket.h:35
eip::socket::TCPSocket::socket_
tcp::socket socket_
Definition: tcp_socket.h:94
eip::socket::Socket
Definition: socket.h:58
eip::socket::TCPSocket::open
virtual void open(string hostname, string port)
Definition: tcp_socket.h:56


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Wed Mar 2 2022 00:38:56