tcp_socket.h
Go to the documentation of this file.
00001 
00026 #ifndef ODVA_ETHERNETIP_SOCKET_TCP_SOCKET_H
00027 #define ODVA_ETHERNETIP_SOCKET_TCP_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 using boost::asio::ip::tcp;
00038 
00039 namespace eip {
00040 namespace socket {
00041 
00045 class TCPSocket : public Socket
00046 {
00047 public:
00048 
00049   TCPSocket(io_service& io_serv) : socket_(io_serv) { }
00050 
00056   virtual void open(string hostname, string port)
00057   {
00058     tcp::resolver resolver(socket_.get_io_service());
00059     tcp::resolver::query query(hostname, port);
00060     tcp::resolver::iterator endpoint_iterator = resolver.resolve(query);
00061     connect(socket_, endpoint_iterator);
00062   }
00063 
00067   virtual inline void close()
00068   {
00069     socket_.close();
00070   }
00071 
00077   virtual size_t send(const_buffer buf)
00078   {
00079     return socket_.send(const_buffers_1(buf));
00080   }
00081 
00087   virtual size_t receive(mutable_buffer buf)
00088   {
00089     // have to make this into a sequence or the templating engine throws a fit
00090     return socket_.receive(mutable_buffers_1(buf));
00091   }
00092 
00093 private:
00094   tcp::socket socket_;
00095 };
00096 
00097 } // namespace socket
00098 } // namespace eip
00099 #endif  // ODVA_ETHERNETIP_SOCKET_TCP_SOCKET_H


odva_ethernetip
Author(s): Kareem Shehata
autogenerated on Sat Jun 8 2019 20:21:23