Transport protocol to transfer an IPbus buffer via UDP. More...
#include <uhal/ProtocolUDP.hpp>
Public Member Functions | |
UDP (const std::string &aId, const URI &aUri) | |
Constructor. More... | |
virtual | ~UDP () |
Destructor. More... | |
Private Member Functions | |
UDP (const UDP &aUDP) | |
Copy Constructor This creates a new socket, dispatch queue, dispatch thread, etc. More... | |
UDP & | operator= (const UDP &aUDP) |
Assignment operator This reassigns the endpoint, closes the existing socket and cleans up the buffers, etc. More... | |
void | implementDispatch (std::shared_ptr< Buffers > aBuffers) |
Send the IPbus buffer to the target, read back the response and call the packing-protocol's validate function. More... | |
virtual void | Flush () |
Concrete implementation of the synchronization function to block until all buffers have been sent, all replies received and all data validated. More... | |
virtual void | dispatchExceptionHandler () |
Function which tidies up this protocol layer in the event of an exception. More... | |
uint32_t | getMaxSendSize () |
Return the maximum size to be sent based on the buffer size in the target. More... | |
uint32_t | getMaxReplySize () |
Return the maximum size of reply packet based on the buffer size in the target. More... | |
void | connect () |
Set up the UDP socket. More... | |
void | write () |
Initialize performing the next UDP write operation In multi-threaded mode, this runs the ASIO async send and exits In single-threaded mode, this runs the ASIO async send and blocks. More... | |
void | write_callback (const boost::system::error_code &aErrorCode, std::size_t aBytesTransferred) |
Callback function which is called upon completion of the ASIO async send This, then, makes a call to read to read back the reply to what has just been sent. More... | |
void | read () |
Initialize performing the next UDP read operation In multi-threaded mode, this runs the ASIO async receive and exits In single-threaded mode, this runs the ASIO async receive and blocks. More... | |
void | read_callback (const boost::system::error_code &aErrorCode, std::size_t aBytesTransferred) |
Callback function which is called upon completion of the ASIO async receive This, then, checks the queue to see if there are more packets to be sent and if so, calls write. More... | |
void | CheckDeadline () |
Function called by the ASIO deadline timer. More... | |
void | NotifyConditionalVariable (const bool &aValue) |
Function to set the value of a variable associated with a BOOST conditional-variable and then notify that conditional variable. More... | |
void | WaitOnConditionalVariable () |
Function to block a thread pending a BOOST conditional-variable and its associated regular variable. More... | |
Private Attributes | |
size_t | mMaxPayloadSize |
The maximum UDP payload size (in bytes) More... | |
boost::asio::io_service | mIOservice |
The boost::asio::io_service used to create the connections. More... | |
boost::asio::ip::udp::socket | mSocket |
A shared pointer to a boost::asio udp socket through which the operation will be performed. More... | |
boost::asio::ip::udp::endpoint | mEndpoint |
A shared pointer to a boost::asio udp endpoint - used in the ASIO send and receive functions (UDP has no concept of a connection) More... | |
boost::asio::deadline_timer | mDeadlineTimer |
The mechanism for providing the time-out. More... | |
std::vector< uint8_t > | mReplyMemory |
A block of memory into which we write replies, before copying them to their final destination. More... | |
boost::asio::io_service::work | mIOserviceWork |
Needed when multi-threading to stop the boost::asio::io_service thinking it has nothing to do and so close the socket. More... | |
std::thread | mDispatchThread |
The Worker thread in Multi-threaded mode. More... | |
std::mutex | mTransportLayerMutex |
A MutEx lock used to make sure the access functions are thread safe. More... | |
std::deque< std::shared_ptr< Buffers > > | mDispatchQueue |
The list of buffers still waiting to be sent. More... | |
std::deque< std::shared_ptr< Buffers > > | mReplyQueue |
The list of buffers still awaiting a reply. More... | |
uint32_t | mPacketsInFlight |
Counter of how many writes have been sent, for which no reply has yet been received. More... | |
std::mutex | mConditionalVariableMutex |
A mutex for use by the conditional variable. More... | |
std::condition_variable | mConditionalVariable |
A conditional variable for blocking the main thread until the variable with which it is associated is set correctly. More... | |
bool | mFlushDone |
A variable associated with the conditional variable which specifies whether all packets have been sent and all replies have been received. More... | |
std::shared_ptr< Buffers > | mDispatchBuffers |
The send operation currently in progress. More... | |
std::shared_ptr< Buffers > | mReplyBuffers |
The receive operation currently in progress or the next to be done. More... | |
uhal::exception::exception * | mAsynchronousException |
A pointer to an exception object for passing exceptions from the worker thread to the main thread. More... | |
Transport protocol to transfer an IPbus buffer via UDP.
Definition at line 82 of file ProtocolUDP.hpp.
|
private |
Copy Constructor This creates a new socket, dispatch queue, dispatch thread, etc.
which connects to the same target ip/port
aUDP | a UDP-protocol object to copy |
uhal::UDP< InnerProtocol >::UDP | ( | const std::string & | aId, |
const URI & | aUri | ||
) |
Constructor.
aId | the uinique identifier that the client will be given. |
aUri | a struct containing the full URI of the target. |
Definition at line 59 of file ProtocolUDP.cpp.
References uhal::UDP< InnerProtocol >::mIOservice.
Destructor.
Definition at line 97 of file ProtocolUDP.cpp.
References uhal::Error, uhal::log(), uhal::Quote(), uhal::ClientInterface::returnBufferToPool(), and uhal::Type().
|
private |
Function called by the ASIO deadline timer.
Definition at line 411 of file ProtocolUDP.cpp.
References uhal::Debug, uhal::log(), uhal::Quote(), and uhal::Warning.
|
private |
Set up the UDP socket.
Definition at line 164 of file ProtocolUDP.cpp.
References uhal::Info, uhal::log(), and uhal::Quote().
|
privatevirtual |
Function which tidies up this protocol layer in the event of an exception.
Definition at line 458 of file ProtocolUDP.cpp.
References uhal::log(), uhal::ClientInterface::returnBufferToPool(), and uhal::Warning.
|
privatevirtual |
Concrete implementation of the synchronization function to block until all buffers have been sent, all replies received and all data validated.
Definition at line 444 of file ProtocolUDP.cpp.
|
private |
Return the maximum size of reply packet based on the buffer size in the target.
Definition at line 157 of file ProtocolUDP.cpp.
|
private |
Return the maximum size to be sent based on the buffer size in the target.
Definition at line 150 of file ProtocolUDP.cpp.
|
private |
Send the IPbus buffer to the target, read back the response and call the packing-protocol's validate function.
aBuffers | the buffer object wrapping the send and recieve buffers that are to be transported If multithreaded, adds buffer to the dispatch queue and returns. If single-threaded, calls the dispatch-worker dispatch function directly and blocks until the response is validated. |
Definition at line 121 of file ProtocolUDP.cpp.
References uhal::log(), and uhal::Type().
|
private |
Function to set the value of a variable associated with a BOOST conditional-variable and then notify that conditional variable.
aValue | a value to which to update the variable associated with a BOOST conditional-variable |
Definition at line 497 of file ProtocolUDP.cpp.
|
private |
Assignment operator This reassigns the endpoint, closes the existing socket and cleans up the buffers, etc.
On the next call which requires the socket, it will be reopened with the new endpoint.
aUDP | a UDP-protocol object to copy |
|
private |
Initialize performing the next UDP read operation In multi-threaded mode, this runs the ASIO async receive and exits In single-threaded mode, this runs the ASIO async receive and blocks.
Definition at line 270 of file ProtocolUDP.cpp.
References uhal::Debug, uhal::Error, uhal::Integer(), and uhal::log().
|
private |
Callback function which is called upon completion of the ASIO async receive This, then, checks the queue to see if there are more packets to be sent and if so, calls write.
aErrorCode | the error code with which the ASIO operation completed |
Definition at line 295 of file ProtocolUDP.cpp.
References uhal::Error, uhal::Integer(), uhal::log(), uhal::Quote(), uhal::ClientInterface::validate(), and uhal::exception::exception::what().
|
private |
Function to block a thread pending a BOOST conditional-variable and its associated regular variable.
Definition at line 508 of file ProtocolUDP.cpp.
|
private |
Initialize performing the next UDP write operation In multi-threaded mode, this runs the ASIO async send and exits In single-threaded mode, this runs the ASIO async send and blocks.
Definition at line 176 of file ProtocolUDP.cpp.
References uhal::Debug, uhal::Error, uhal::Integer(), and uhal::log().
|
private |
Callback function which is called upon completion of the ASIO async send This, then, makes a call to read to read back the reply to what has just been sent.
aErrorCode | the error code with which the ASIO operation completed |
Definition at line 204 of file ProtocolUDP.cpp.
References uhal::Integer(), uhal::log(), and uhal::Quote().
|
private |
A pointer to an exception object for passing exceptions from the worker thread to the main thread.
Exceptions must always be created on the heap (i.e. using new
) and deletion will be handled in the main thread
Definition at line 237 of file ProtocolUDP.hpp.
|
private |
A conditional variable for blocking the main thread until the variable with which it is associated is set correctly.
Definition at line 224 of file ProtocolUDP.hpp.
|
private |
A mutex for use by the conditional variable.
Definition at line 222 of file ProtocolUDP.hpp.
|
private |
The mechanism for providing the time-out.
Definition at line 195 of file ProtocolUDP.hpp.
|
private |
The send operation currently in progress.
Definition at line 229 of file ProtocolUDP.hpp.
|
private |
The list of buffers still waiting to be sent.
Definition at line 214 of file ProtocolUDP.hpp.
|
private |
The Worker thread in Multi-threaded mode.
Definition at line 208 of file ProtocolUDP.hpp.
|
private |
A shared pointer to a boost::asio udp endpoint - used in the ASIO send and receive functions (UDP has no concept of a connection)
Definition at line 192 of file ProtocolUDP.hpp.
|
private |
A variable associated with the conditional variable which specifies whether all packets have been sent and all replies have been received.
Definition at line 226 of file ProtocolUDP.hpp.
|
private |
The boost::asio::io_service used to create the connections.
Definition at line 186 of file ProtocolUDP.hpp.
Referenced by uhal::UDP< InnerProtocol >::UDP().
|
private |
Needed when multi-threading to stop the boost::asio::io_service thinking it has nothing to do and so close the socket.
Definition at line 205 of file ProtocolUDP.hpp.
The maximum UDP payload size (in bytes)
Definition at line 183 of file ProtocolUDP.hpp.
|
private |
Counter of how many writes have been sent, for which no reply has yet been received.
Definition at line 219 of file ProtocolUDP.hpp.
|
private |
The receive operation currently in progress or the next to be done.
Definition at line 231 of file ProtocolUDP.hpp.
|
private |
A block of memory into which we write replies, before copying them to their final destination.
Definition at line 202 of file ProtocolUDP.hpp.
|
private |
The list of buffers still awaiting a reply.
Definition at line 216 of file ProtocolUDP.hpp.
|
private |
A shared pointer to a boost::asio udp socket through which the operation will be performed.
Definition at line 189 of file ProtocolUDP.hpp.
|
private |
A MutEx lock used to make sure the access functions are thread safe.
Definition at line 211 of file ProtocolUDP.hpp.