39#ifndef _uhal_ProtocolTCP_hpp_
40#define _uhal_ProtocolTCP_hpp_
44#include <condition_variable>
53#include <boost/asio/io_context.hpp>
54#include <boost/asio/executor_work_guard.hpp>
55#include <boost/asio/ip/tcp.hpp>
56#include <boost/asio/deadline_timer.hpp>
83 template < typename InnerProtocol ,
std::
size_t nr_buffers_per_send >
84 class
TCP : public InnerProtocol
109 TCP (
const std::string& aId,
const URI& aUri );
120 void implementDispatch ( std::shared_ptr< Buffers > aBuffers );
123 virtual void Flush( );
126 virtual void dispatchExceptionHandler();
132 uint32_t getMaxSendSize();
138 uint32_t getMaxReplySize();
155 void write_callback (
const boost::system::error_code& aErrorCode , std::size_t aBytesTransferred );
169 void read_callback (
const boost::system::error_code& aErrorCode , std::size_t aBytesTransferred );
172 void CheckDeadline();
178 void NotifyConditionalVariable (
const bool& aValue );
181 void WaitOnConditionalVariable();
203 boost::asio::executor_work_guard<boost::asio::io_context::executor_type>
mIOserviceWork;
214 std::deque < std::pair<std::vector< std::shared_ptr< Buffers > >, SteadyClock_t::time_point> >
mReplyQueue;
254 std::pair< std::vector< std::shared_ptr< Buffers > >, SteadyClock_t::time_point >
mReplyBuffers;
Wrapper to generate a new Python exception type.
\rst Holds a reference to a Python object (no reference counting)
Transport protocol to transfer an IPbus buffer via TCP.
boost::asio::deadline_timer mDeadlineTimer
The mechanism for providing the time-out.
TimeIntervalStats mRTTStats
std::pair< std::vector< std::shared_ptr< Buffers > >, SteadyClock_t::time_point > mReplyBuffers
The buffers containing the payloads for the receive operation that's currently in progress.
boost::asio::executor_work_guard< boost::asio::io_context::executor_type > mIOserviceWork
Needed when multi-threading to stop the boost::asio::io_context thinking it has nothing to do and so ...
std::vector< std::shared_ptr< Buffers > > mDispatchBuffers
The buffers containing the payload for the send operation that's currently in progress.
TCP(const TCP &aTCP)
Copy Constructor This creates a new socket, dispatch queue, dispatch thread, etc.
std::mutex mTransportLayerMutex
A MutEx lock used to make sure the access functions are thread safe.
TimeIntervalStats mLSTStats
uint32_t mPacketsInFlight
Counter of how many writes have been sent, for which no reply has yet been received.
bool mFlushStarted
Boolean specifying whether or not the main thread is within TCP::Flush method. Its value checked by t...
size_t mMaxPayloadSize
The maximum UDP payload size (in bytes)
std::chrono::steady_clock SteadyClock_t
std::condition_variable mConditionalVariable
A conditional variable for blocking the main thread until the variable with which it is associated is...
bool mFlushDone
A variable associated with the conditional variable which specifies whether all packets have been sen...
boost::asio::io_context mIOservice
The boost::asio::io_context used to create the connections.
boost::asio::ip::tcp::resolver::results_type mEndpoint
A shared pointer to a boost::asio tcp endpoint - used by the delayed (open-on-first-use) connect.
std::thread mDispatchThread
The Worker thread in Multi-threaded mode.
SteadyClock_t::time_point mLastSendQueued
SteadyClock_t::time_point mLastRecvQueued
std::deque< std::pair< std::vector< std::shared_ptr< Buffers > >, SteadyClock_t::time_point > > mReplyQueue
The list of buffers still awaiting a reply.
TimeIntervalStats mInterRecvTimeStats
uint32_t mSendByteCounter
Variable storing "number of bytes to follow" field for the TCP chunk currently being sent.
std::mutex mConditionalVariableMutex
A mutex for use by the conditional variable.
std::deque< std::shared_ptr< Buffers > > mDispatchQueue
The list of buffers still waiting to be sent.
uint32_t mReplyByteCounter
Variable used to store "number of bytes to follow" field for the next/current TCP chunk being receive...
boost::asio::ip::tcp::socket mSocket
A shared pointer to a boost::asio tcp socket through which the operation will be performed.
TimeIntervalStats mInterSendTimeStats
uhal::exception::exception * mAsynchronousException
A pointer to an exception object for passing exceptions from the worker thread to the main thread.
An abstract base exception class, including an interface to throw as the derived type (for passing ex...
#define UHAL_DEFINE_DERIVED_EXCEPTION_CLASS(ClassName, BaseClassName, ClassDescription)
Macro for simplifying the declaration and definition of derived exception types.
Struct to store a URI when parsed by boost spirit.