23 #ifndef INCLUDED_GR_SOCKET_PDU_H
24 #define INCLUDED_GR_SOCKET_PDU_H
31 #include <boost/array.hpp>
32 #include <boost/asio.hpp>
41 :
public boost::enable_shared_from_this<tcp_connection>
46 boost::array<char, 10000>
buf;
53 boost::asio::ip::tcp::socket&
socket()
67 socket_.async_read_some(
68 boost::asio::buffer(
buf),
69 boost::bind(&tcp_connection::handle_read,
this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
74 boost::array<char, 10000> txbuf;
76 boost::asio::async_write(socket_, boost::asio::buffer(txbuf, len),
77 boost::bind(&tcp_connection::handle_write, shared_from_this(),
78 boost::asio::placeholders::error,
79 boost::asio::placeholders::bytes_transferred));
92 void handle_read(
const boost::system::error_code& error,
size_t bytes_transferred);
94 void handle_write(
const boost::system::error_code& ,
99 boost::asio::ip::tcp::socket socket_;
100 std::string message_;
114 boost::asio::io_service _io_service;
116 boost::array<char, 10000> rxbuf;
119 boost::asio::ip::tcp::endpoint _tcp_endpoint;
123 std::vector<tcp_connection::pointer> d_tcp_connections;
132 boost::asio::ip::udp::endpoint _udp_endpoint;
133 boost::asio::ip::udp::endpoint _udp_endpoint_other;
136 void handle_receive(
const boost::system::error_code& error, std::size_t ){
139 void start_tcp_accept(){
143 _acceptor_tcp->async_accept(new_connection->socket(),
144 boost::bind(&gr_socket_pdu::handle_tcp_accept,
this, new_connection,
145 boost::asio::placeholders::error));
151 new_connection->start(
this);
152 d_tcp_connections.push_back(new_connection);
155 std::cout << error << std::endl;
159 void run_io_service(){
163 void handle_udp_read(
const boost::system::error_code& error,
size_t bytes_transferred){
170 _udp_socket->async_receive_from( boost::asio::buffer(rxbuf), _udp_endpoint_other,
171 boost::bind(&gr_socket_pdu::handle_udp_read,
this,
172 boost::asio::placeholders::error,
173 boost::asio::placeholders::bytes_transferred));
175 throw boost::system::system_error(error);
179 void handle_tcp_read(
const boost::system::error_code& error,
size_t bytes_transferred){
187 _tcp_socket->async_read_some(
188 boost::asio::buffer(rxbuf),
189 boost::bind(&gr_socket_pdu::handle_tcp_read,
this, boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred));
193 throw boost::system::system_error(error);
198 gr_socket_pdu (std::string type, std::string addr, std::string port,
int MTU=10000);