11 using boost::asio::ip::tcp;
29 std::stringstream sPort;
32 tcp::resolver::query query(tcp::v4(), ip_address, sPort.str());
33 tcp::resolver::iterator it = res.resolve(query);
34 boost::system::error_code ec;
38 if (ec.value() == boost::system::errc::success)
42 else if (ec.value() == boost::asio::error::invalid_argument)
58 boost::system::error_code ec;
61 if (ec.value() == boost::system::errc::success)
79 if (error != boost::asio::error::operation_aborted)
81 error_.assign(boost::system::errc::timed_out, boost::system::system_category());
91 const size_t &buf_size,
98 error_.assign(boost::system::errc::success, boost::system::system_category());
104 timer.expires_from_now(boost::posix_time::milliseconds(timeout_ms));
107 boost::asio::placeholders::error));
110 boost::asio::async_read(
socket_,
111 boost::asio::buffer(msg, buf_size),
114 boost::asio::placeholders::error,
115 boost::asio::placeholders::bytes_transferred));
119 if (
error_.value() == boost::system::errc::success)
124 else if (
error_.value() == boost::system::errc::timed_out)
132 if (
error_.value() == boost::system::errc::success)
136 else if (
error_.value() == boost::system::errc::timed_out)
147 const size_t &buf_size,
148 const size_t &bytes_to_read,
154 error_.assign(boost::system::errc::success, boost::system::system_category());
160 timer.expires_from_now(boost::posix_time::milliseconds(timeout_ms));
163 boost::asio::placeholders::error));
166 boost::asio::async_read(
socket_,
167 boost::asio::buffer(msg, buf_size),
168 boost::asio::transfer_exactly(bytes_to_read),
171 boost::asio::placeholders::error,
172 boost::asio::placeholders::bytes_transferred));
176 if (
error_.value() == boost::system::errc::success)
180 else if (
error_.value() == boost::system::errc::timed_out)
188 if (
error_.value() == boost::system::errc::success)
192 else if (
error_.value() == boost::system::errc::timed_out)
207 boost::system::error_code ec;
208 boost::asio::write(
socket_, boost::asio::buffer(msg, msg_size), ec);
210 if (ec.value() == boost::system::errc::success)
return_statuses read_exactly(unsigned char *msg, const size_t &buf_size, const size_t &bytes_to_read, int timeout_ms=0)
boost::asio::ip::tcp::socket socket_
void timeout_handler(const boost::system::error_code &error)
return_statuses open(const char *ip_address, const int &port)
boost::system::error_code error_
void read_handler(const boost::system::error_code &error, size_t bytes_read)
boost::asio::io_service io_service_
return_statuses write(unsigned char *msg, const size_t &msg_size)
return_statuses read(unsigned char *msg, const size_t &buf_size, size_t &bytes_read, int timeout_ms=0)