GNU Radio 3.6.5 C++ API

socket_pdu_impl.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2013 Free Software Foundation, Inc.
00004  *
00005  * This file is part of GNU Radio
00006  *
00007  * GNU Radio is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published by
00009  * the Free Software Foundation; either version 3, or (at your option)
00010  * any later version.
00011  *
00012  * GNU Radio is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with GNU Radio; see the file COPYING.  If not, write to
00019  * the Free Software Foundation, Inc., 51 Franklin Street,
00020  * Boston, MA 02110-1301, USA.
00021  */
00022 
00023 #ifndef INCLUDED_BLOCKS_SOCKET_PDU_IMPL_H
00024 #define INCLUDED_BLOCKS_SOCKET_PDU_IMPL_H
00025 
00026 #include <blocks/socket_pdu.h>
00027 #include "stream_pdu_base.h"
00028 #include "tcp_connection.h"
00029 
00030 namespace gr {
00031   namespace blocks {
00032 
00033     class socket_pdu_impl : public socket_pdu, public stream_pdu_base
00034     {
00035     private:
00036       boost::asio::io_service d_io_service;
00037       boost::array<char, 10000> d_rxbuf;
00038       void run_io_service() { d_io_service.run(); }
00039 
00040       // TCP specific
00041       boost::asio::ip::tcp::endpoint d_tcp_endpoint;
00042       std::vector<tcp_connection::sptr> d_tcp_connections;
00043       void handle_tcp_read(const boost::system::error_code& error, size_t bytes_transferred);
00044 
00045       // TCP server specific
00046       boost::shared_ptr<boost::asio::ip::tcp::acceptor> d_acceptor_tcp;
00047       void start_tcp_accept();
00048       void tcp_server_send(pmt::pmt_t msg);
00049       void handle_tcp_accept(tcp_connection::sptr new_connection, const boost::system::error_code& error);
00050 
00051       // TCP client specific
00052       boost::shared_ptr<boost::asio::ip::tcp::socket> d_tcp_socket;
00053       void tcp_client_send(pmt::pmt_t msg);
00054 
00055       // UDP specific
00056       boost::asio::ip::udp::endpoint d_udp_endpoint;
00057       boost::asio::ip::udp::endpoint d_udp_endpoint_other;
00058       boost::shared_ptr<boost::asio::ip::udp::socket> d_udp_socket;
00059       void handle_udp_read(const boost::system::error_code& error, size_t bytes_transferred);
00060       void udp_send(pmt::pmt_t msg);
00061     
00062     public:
00063       socket_pdu_impl(std::string type, std::string addr, std::string port, int MTU);
00064     };
00065 
00066   } /* namespace blocks */
00067 } /* namespace gr */
00068 
00069 #endif /* INCLUDED_BLOCKS_SOCKET_PDU_IMPL_H */