Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
fc::udp_socket Class Reference

#include <udp_socket.hpp>

Classes

class  impl
 

Public Member Functions

 udp_socket ()
 
 udp_socket (const udp_socket &s)
 
 ~udp_socket ()
 
void initialize (boost::asio::io_service &)
 
void open ()
 
void send_to (const char *b, size_t l, boost::asio::ip::udp::endpoint &to)
 
void send_to (const std::shared_ptr< const char > &b, size_t l, boost::asio::ip::udp::endpoint &to)
 
void close ()
 
void set_reuse_address (bool)
 
void connect (const boost::asio::ip::udp::endpoint &e)
 
const boost::asio::ip::udp::endpoint local_endpoint () const
 

Detailed Description

The udp_socket class has reference semantics, all copies will refer to the same underlying socket.

Definition at line 17 of file udp_socket.hpp.

Constructor & Destructor Documentation

◆ udp_socket() [1/2]

fc::udp_socket::udp_socket ( )

Definition at line 16 of file udp_socket.cpp.

17 : my(new impl())
18 {
19 }

◆ udp_socket() [2/2]

fc::udp_socket::udp_socket ( const udp_socket & s)

◆ ~udp_socket()

fc::udp_socket::~udp_socket ( )

Definition at line 26 of file udp_socket.cpp.

27 {
28 try
29 {
30 if(my->_sock)
31 my->_sock->close(); //close boost socket to make any pending reads run their completion handler
32 }
33 catch (...) //avoid destructor throw and likely this is just happening because socket wasn't open.
34 {
35 }
36 }

Member Function Documentation

◆ close()

void fc::udp_socket::close ( )

Definition at line 91 of file udp_socket.cpp.

92 {
93 my->_sock->close();
94 }
Here is the caller graph for this function:

◆ connect()

void fc::udp_socket::connect ( const boost::asio::ip::udp::endpoint & e)

Definition at line 101 of file udp_socket.cpp.

102 {
103 my->_sock->connect(e);
104 }

◆ initialize()

void fc::udp_socket::initialize ( boost::asio::io_service & service)

Definition at line 21 of file udp_socket.cpp.

22 {
23 my->_sock.reset(new boost::asio::ip::udp::socket(service));
24 }

◆ local_endpoint()

const boost::asio::ip::udp::endpoint fc::udp_socket::local_endpoint ( ) const

Definition at line 96 of file udp_socket.cpp.

97 {
98 return my->_sock->local_endpoint();
99 }

◆ open()

void fc::udp_socket::open ( )

Definition at line 85 of file udp_socket.cpp.

86 {
87 my->_sock->open(boost::asio::ip::udp::v4());
88 my->_sock->non_blocking(true);
89 }
Here is the caller graph for this function:

◆ send_to() [1/2]

void fc::udp_socket::send_to ( const char * b,
size_t l,
boost::asio::ip::udp::endpoint & to )

Definition at line 38 of file udp_socket.cpp.

39 {
40 try
41 {
42 my->_sock->send_to(boost::asio::buffer(buffer, length), to);
43 return;
44 }
45 catch(const boost::system::system_error& e)
46 {
47 if(e.code() == boost::asio::error::would_block)
48 {
49 auto send_buffer_ptr = std::make_shared<std::vector<char>>(buffer, buffer+length);
50 my->_sock->async_send_to(boost::asio::buffer(send_buffer_ptr.get(), length), to,
51 [send_buffer_ptr](const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/)
52 {
53 // Swallow errors. Currently only used for GELF logging, so depend on local
54 // log to catch anything that doesn't make it across the network.
55 });
56 }
57 // All other exceptions ignored.
58 }
59 }
Here is the caller graph for this function:

◆ send_to() [2/2]

void fc::udp_socket::send_to ( const std::shared_ptr< const char > & b,
size_t l,
boost::asio::ip::udp::endpoint & to )

Definition at line 61 of file udp_socket.cpp.

63 {
64 try
65 {
66 my->_sock->send_to(boost::asio::buffer(buffer.get(), length), to);
67 return;
68 }
69 catch(const boost::system::system_error& e)
70 {
71 if(e.code() == boost::asio::error::would_block)
72 {
73 auto preserved_buffer_ptr = buffer;
74 my->_sock->async_send_to(boost::asio::buffer(preserved_buffer_ptr.get(), length), to,
75 [preserved_buffer_ptr](const boost::system::error_code& /*ec*/, std::size_t /*bytes_transferred*/)
76 {
77 // Swallow errors. Currently only used for GELF logging, so depend on local
78 // log to catch anything that doesn't make it across the network.
79 });
80 }
81 // All other exceptions ignored.
82 }
83 }

◆ set_reuse_address()

void fc::udp_socket::set_reuse_address ( bool s)

Definition at line 106 of file udp_socket.cpp.

107 {
108 my->_sock->set_option( boost::asio::ip::udp::socket::reuse_address(s) );
109 }
char * s

The documentation for this class was generated from the following files: