Fabcoin Core  0.16.2
P2P Digital Currency
Public Types | Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
dev::p2p::UDPSocket< Handler, MaxDatagramSize > Class Template Reference

UDP Interface Handler must implement UDPSocketEvents. More...

#include <UDP.h>

Inheritance diagram for dev::p2p::UDPSocket< Handler, MaxDatagramSize >:
[legend]
Collaboration diagram for dev::p2p::UDPSocket< Handler, MaxDatagramSize >:
[legend]

Public Types

enum  { maxDatagramSize = MaxDatagramSize }
 

Public Member Functions

 UDPSocket (ba::io_service &_io, UDPSocketEvents &_host, bi::udp::endpoint _endpoint)
 Create socket for specific endpoint. More...
 
 UDPSocket (ba::io_service &_io, UDPSocketEvents &_host, unsigned _port)
 Create socket which listens to all ports. More...
 
virtual ~UDPSocket ()
 
void connect ()
 Socket will begin listening for and delivering packets. More...
 
bool send (UDPDatagram const &_datagram)
 Send datagram. More...
 
bool isOpen ()
 Returns if socket is open. More...
 
void disconnect ()
 Disconnect socket. More...
 

Protected Member Functions

void doRead ()
 
void doWrite ()
 
void disconnectWithError (boost::system::error_code _ec)
 

Protected Attributes

std::atomic< bool > m_started
 Atomically ensure connection is started once. Start cannot occur unless m_started is false. Managed by start and disconnectWithError. More...
 
std::atomic< bool > m_closed
 Connection availability. More...
 
UDPSocketEventsm_host
 Interface which owns this socket. More...
 
bi::udp::endpoint m_endpoint
 Endpoint which we listen to. More...
 
Mutex x_sendQ
 
std::deque< UDPDatagramm_sendQ
 Queue for egress data. More...
 
std::array< byte, maxDatagramSizem_recvData
 Buffer for ingress data. More...
 
bi::udp::endpoint m_recvEndpoint
 Endpoint data was received from. More...
 
bi::udp::socket m_socket
 Boost asio udp socket. More...
 
Mutex x_socketError
 Mutex for error which can be set from host or IO thread. More...
 
boost::system::error_code m_socketError
 Set when shut down due to error. More...
 

Additional Inherited Members

Detailed Description

template<typename Handler, unsigned MaxDatagramSize>
class dev::p2p::UDPSocket< Handler, MaxDatagramSize >

UDP Interface Handler must implement UDPSocketEvents.

Todo:

multiple endpoints (we cannot advertise 0.0.0.0)

decouple deque from UDPDatagram and add ref() to datagram for fire&forget

Definition at line 107 of file UDP.h.

Member Enumeration Documentation

template<typename Handler , unsigned MaxDatagramSize>
anonymous enum
Enumerator
maxDatagramSize 

Definition at line 110 of file UDP.h.

Constructor & Destructor Documentation

template<typename Handler , unsigned MaxDatagramSize>
dev::p2p::UDPSocket< Handler, MaxDatagramSize >::UDPSocket ( ba::io_service &  _io,
UDPSocketEvents _host,
bi::udp::endpoint  _endpoint 
)
inline

Create socket for specific endpoint.

Definition at line 114 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
dev::p2p::UDPSocket< Handler, MaxDatagramSize >::UDPSocket ( ba::io_service &  _io,
UDPSocketEvents _host,
unsigned  _port 
)
inline

Create socket which listens to all ports.

Definition at line 117 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
virtual dev::p2p::UDPSocket< Handler, MaxDatagramSize >::~UDPSocket ( )
inlinevirtual

Definition at line 118 of file UDP.h.

Member Function Documentation

template<typename Handler , unsigned MaxDatagramSize>
void dev::p2p::UDPSocket< Handler, MaxDatagramSize >::connect ( )

Socket will begin listening for and delivering packets.

Definition at line 156 of file UDP.h.

Here is the caller graph for this function:

template<typename Handler , unsigned MaxDatagramSize>
void dev::p2p::UDPSocket< Handler, MaxDatagramSize >::disconnect ( )
inlinevirtual

Disconnect socket.

Implements dev::p2p::UDPSocketFace.

Definition at line 130 of file UDP.h.

Here is the caller graph for this function:

template<typename Handler , unsigned MaxDatagramSize>
void dev::p2p::UDPSocket< Handler, MaxDatagramSize >::disconnectWithError ( boost::system::error_code  _ec)
protected

Definition at line 241 of file UDP.h.

Here is the call graph for this function:

template<typename Handler , unsigned MaxDatagramSize>
void dev::p2p::UDPSocket< Handler, MaxDatagramSize >::doRead ( )
protected

Definition at line 195 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
void dev::p2p::UDPSocket< Handler, MaxDatagramSize >::doWrite ( )
protected

Definition at line 216 of file UDP.h.

Here is the call graph for this function:

template<typename Handler , unsigned MaxDatagramSize>
bool dev::p2p::UDPSocket< Handler, MaxDatagramSize >::isOpen ( )
inline

Returns if socket is open.

Definition at line 127 of file UDP.h.

Here is the caller graph for this function:

template<typename Handler , unsigned MaxDatagramSize>
bool dev::p2p::UDPSocket< Handler, MaxDatagramSize >::send ( UDPDatagram const &  _datagram)
virtual

Send datagram.

Implements dev::p2p::UDPSocketFace.

Definition at line 181 of file UDP.h.

Here is the caller graph for this function:

Member Data Documentation

template<typename Handler , unsigned MaxDatagramSize>
std::atomic<bool> dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_closed
protected

Connection availability.

Definition at line 140 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
bi::udp::endpoint dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_endpoint
protected

Endpoint which we listen to.

Definition at line 143 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
UDPSocketEvents& dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_host
protected

Interface which owns this socket.

Definition at line 142 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
std::array<byte, maxDatagramSize> dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_recvData
protected

Buffer for ingress data.

Definition at line 147 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
bi::udp::endpoint dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_recvEndpoint
protected

Endpoint data was received from.

Definition at line 148 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
std::deque<UDPDatagram> dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_sendQ
protected

Queue for egress data.

Definition at line 146 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
bi::udp::socket dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_socket
protected

Boost asio udp socket.

Definition at line 149 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
boost::system::error_code dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_socketError
protected

Set when shut down due to error.

Definition at line 152 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
std::atomic<bool> dev::p2p::UDPSocket< Handler, MaxDatagramSize >::m_started
protected

Atomically ensure connection is started once. Start cannot occur unless m_started is false. Managed by start and disconnectWithError.

Definition at line 139 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
Mutex dev::p2p::UDPSocket< Handler, MaxDatagramSize >::x_sendQ
protected

Definition at line 145 of file UDP.h.

template<typename Handler , unsigned MaxDatagramSize>
Mutex dev::p2p::UDPSocket< Handler, MaxDatagramSize >::x_socketError
protected

Mutex for error which can be set from host or IO thread.

Definition at line 151 of file UDP.h.


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