socket.h
Go to the documentation of this file.
1 
26 #ifndef ODVA_ETHERNETIP_SOCKET_SOCKET_H
27 #define ODVA_ETHERNETIP_SOCKET_SOCKET_H
28 
29 #include <string>
30 #include <boost/asio.hpp>
31 
32 #if BOOST_VERSION >= 107000
33 #define GET_IO_SERVICE(s) ((boost::asio::io_context&)(s)->get_executor().context())
34 #else
35 #define GET_IO_SERVICE(s) ((s)->get_io_service())
36 #endif
37 
40 
41 using std::string;
42 using std::size_t;
43 using boost::asio::buffer;
44 using boost::asio::const_buffer;
45 using boost::asio::mutable_buffer;
46 
47 namespace eip {
48 
49 using serialization::Serializable;
50 using serialization::BufferWriter;
51 
52 namespace socket {
53 
58 class Socket
59 {
60 public:
61 
62  virtual ~Socket() { }
63 
69  virtual void open(string hostname, string port) = 0;
70 
74  virtual void close() = 0;
75 
81  virtual size_t send(const_buffer buf) = 0;
82 
88  virtual size_t send(const Serializable& msg)
89  {
90  std::vector<char> buf(msg.getLength());
91  BufferWriter writer(buffer(buf));
92  msg.serialize(writer);
93  return send(buffer(buf));
94  }
95 
101  virtual size_t receive(mutable_buffer buf) = 0;
102 
103 };
104 
105 } // namespace socket
106 } // namespace eip
107 #endif // ODVA_ETHERNETIP_SOCKET_SOCKET_H
eip::socket::Socket::~Socket
virtual ~Socket()
Definition: socket.h:62
eip::socket::Socket::receive
virtual size_t receive(mutable_buffer buf)=0
eip
Definition: connection.h:41
eip::serialization::BufferWriter
Definition: buffer_writer.h:44
eip::serialization::Serializable::getLength
virtual size_t getLength() const =0
eip::socket::Socket::open
virtual void open(string hostname, string port)=0
buffer_writer.h
eip::serialization::Serializable
Definition: serializable.h:38
eip::socket::Socket::send
virtual size_t send(const Serializable &msg)
Definition: socket.h:88
eip::socket::Socket::close
virtual void close()=0
eip::socket::Socket::send
virtual size_t send(const_buffer buf)=0
eip::serialization::Serializable::serialize
virtual Writer & serialize(Writer &writer) const =0
eip::socket::Socket
Definition: socket.h:58
serializable.h


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