Jpp 19.3.0-rc.2
the software that should make you happy
Loading...
Searching...
No Matches
input_channel_handler.hh
Go to the documentation of this file.
1#ifndef INPUT_CHANNEL_HANDLER_HH
2#define INPUT_CHANNEL_HANDLER_HH
3
4#include <boost/bind.hpp>
5#include <boost/asio.hpp>
6#include <boost/atomic.hpp>
7
10
11/**
12 * \author cpellegrino
13 */
14
16{
17 boost::asio::ip::udp::socket m_socket;
20 boost::atomic<bool> m_paused;
21
22 void handle(const boost::system::error_code& error, size_t size)
23 {
24 // The error_code should be handled in principle, but
25 // it is not mandatory, since all possibilities should be already
26 // handled somewhere else.
27
28 if (size && ! m_paused)
29 {
30 m_buffer->resize(size);
32
34 }
35
36 m_socket.async_receive(
37 boost::asio::buffer(m_buffer->raw(), m_buffer->capacity()),
38 boost::bind(
40 this,
41 boost::asio::placeholders::error,
42 boost::asio::placeholders::bytes_transferred));
43 }
44
45 public:
46
47 // Receive buffer size (see SOL_SOCKET/SO_RCVBUF) set to 64MB
48 // (default between 32 and 128KB)
49#if __APPLE__
50 static const int recv_buf_size = 6108864;
51#else
52 static const int recv_buf_size = 67108864;
53#endif
54
55 void pause()
56 {
57 m_paused = true;
58 }
59
60 void cont()
61 {
62 m_paused = false;
63 }
64
65 InChannelHandler(boost::asio::io_service& service,
66 unsigned short port,
67 FrameFarm& farm)
68 :
69 m_socket(service, boost::asio::ip::udp::endpoint(boost::asio::ip::udp::v4(), port)),
71 InBufferCollector::getCollector().getEmptyDataGram()),
72 m_farm(&farm),
73 m_paused(false)
74 {
75 boost::asio::ip::udp::socket::receive_buffer_size option(recv_buf_size);
76 m_socket.set_option(option);
77 handle(boost::system::error_code(), 0);
78 }
79
84};
85
86#endif // INPUT_CHANNEL_HANDLER_HH
void resize(size_t s)
char * raw()
size_t capacity() const
bool insert(CLBDataGram *datagram)
void putDataGram(CLBDataGram *p)
static InBufferCollector & getCollector()
CLBDataGram * getEmptyDataGram()
boost::asio::ip::udp::socket m_socket
void handle(const boost::system::error_code &error, size_t size)
boost::atomic< bool > m_paused
static const int recv_buf_size
FrameFarm *const m_farm
InChannelHandler(boost::asio::io_service &service, unsigned short port, FrameFarm &farm)