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);
gr_socket_pdu * d_block
Definition: gr_socket_pdu.h:45
void start(gr_socket_pdu *parent)
Definition: gr_socket_pdu.h:58
void send(pmt::pmt_t vector)
Definition: gr_socket_pdu.h:71
unsigned char uint8_t
Definition: stdint.h:78
GRUEL_API pmt_t pmt_cons(const pmt_t &x, const pmt_t &y)
Return a newly allocated pair whose car is x and whose cdr is y.
shared_ptr documentation stub
Definition: shared_ptr_docstub.h:15
~tcp_connection()
Definition: gr_socket_pdu.h:82
#define GR_CORE_API
Definition: gr_core_api.h:30
static pointer create(boost::asio::io_service &io_service)
Definition: gr_socket_pdu.h:48
GRUEL_API size_t pmt_length(const pmt_t &v)
Return the number of elements in v.
~gr_socket_pdu()
Definition: gr_socket_pdu.h:200
boost::array< char, 10000 > buf
Definition: gr_socket_pdu.h:46
Gather received items into messages and insert into msgq.
Definition: gr_socket_pdu.h:108
GRUEL_API pmt_t pmt_init_u8vector(size_t k, const uint8_t *data)
GRUEL_API const void * pmt_uniform_vector_elements(pmt_t v, size_t &len)
GRUEL_API const pmt_t PMT_NIL
boost::asio::ip::tcp::socket & socket()
Definition: gr_socket_pdu.h:53
boost::shared_ptr< tcp_connection > pointer
Definition: gr_socket_pdu.h:44
boost::intrusive_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:54
Gather received items into messages and insert into msgq.
Definition: gr_stream_pdu_base.h:35
static pmt_t mp(const std::string &s)
Make pmt symbol.
Definition: pmt_sugar.h:33
void message_port_pub(pmt::pmt_t, pmt::pmt_t)
Definition: gr_block.h:236
GR_CORE_API gr_socket_pdu_sptr gr_make_socket_pdu(std::string type, std::string addr, std::string port, int MTU=10000)
Definition: gr_socket_pdu.h:40