TcpChannel
class TcpChannel : public Channel
Functions
| Name | Description |
|---|---|
| getConnection | Pointer to connection of this channel - empty if that is not alive anymore |
| readSizeInBytes | Synchronously reads the TCP message's size. |
| readAsyncSizeInBytes | In case a TCP message arrived, handler will be called back The handler will inform about the number of bytes going to come in The handler must have the following signature: void handler(Channel::Pointer, const size_t&) handler : Callback with signature: void (Channel::Pointer, const size_t&) |
| consumeBytesAfterReadUntil | ******** ******** Synchronously reads size bytes and return them as a string. |
| read | Synchronously reads size bytes from TCP socket into data. |
| read | This function reads from a channel into vector of chars The reading will block until the data record is read. |
| read | This function reads from a channel into shared pointer of vector of chars The reading will block until the data record is read. |
| read | This function reads from a channel into vector of chars The reading will block until the data record is read. |
| read | Synchronously reads size bytes from socket into data and provides a header. |
| read | This function reads into a header and a vector of chars. |
| read | This function reads into a header and shared pointer of vector of chars. |
| read | This function reads into a header hash and a data hash. |
| readAsyncRaw | Asynchronously reads size number of bytes into pre-allocated data buffer A handler can be registered to inform about completion of writing data : Pre-allocated contiguous block of memory size : This number of bytes will be copied into data handler : Function of signature: |
| readAsyncStringUntil | wrapper around boost::asio::async_read_until Read a string until terminator string is found. (No header is expected). terminator : when this string found, read is done handler : handler with signature ReadStringHandler, i.e. void (const boost::system::error_code&, std::string&) is called. second handler parameter is the read string including the terminator !!! note This method should ONLY be used in association with consumeBytesAfterReadUntil - they consume from the same boost::asio::streambuf and should not be used in the same context of the other read* methods. |
| queueInfo | Records the sizes of the write queues in a Hash. |
| remoteAddress | Address of the remote endpoint |
| writeAsync | Writes a copy from the data array. |
| writeAsync | Writes a copy of the data vector. |
| writeAsync | Sends the vector pointed by data. |
| writeAsync | Writes a copy of the data string. |
| writeAsync | When copyAllData is false, elements of type NDArray in the hash won't be copied before being sent. |
| writeAsync | Writes copies of the header hash and the data array. |
| writeAsync | Writes copies of the header hash and of the data vector. |
| writeAsync | Writes a copy of the header hash. |
| writeAsync | Writes copies of the header hash and of the data string. |
| writeAsync | When copyAllData is false, elements of type NDArray in the body hash won't be copied before being sent. |
| getChannelInfo | This function returns low level info about connection like ... "localIp", "localPort", "remoteIp", "remotePort" that constitute active connection. in form of Hash container ptr : input TcpChannel boost shared pointer Return : Hash with 4 key/value pairs |
| bytesAvailableHandler | Internal default handler channel : |
| onSizeInBytesAvailable | This function calls the corresponding handler handler : error : |
| onVectorBufferSetPointerAvailable | Internal handler called after filling the buffer set error : error code length : number of bytes read == total size of buffer set buffers : vector of buffer set pointers with the data handler : to be called |
| byteSizeAvailableHandler | Internal default handler byteSize : |
| bufferSetFromString | Creates a buffer set with the given string stored in its sole buffer. |
| bufferSetFromPointerToChar | Creates a buffer set with contents of a given buffer of chars stored in its sole buffer. |
| bufferSetFromVectorCharPointer | Creates a buffer set with characters in a given vector of chars stored in its sole buffer. |
| bufferSetFromHash | Creates a buffer set with a given hash stored in its sole buffer. |
| storeCompleteHandler | Helper to store async write completion handler handler : write completion handler to be stored Return : index under which handler is stored in internal map |
| applySocketKeepAlive | Helper to apply the TCP keep-alive settings to the socket if configured to do so. |
Function Details
applySocketKeepAlive
void applySocketKeepAlive()
Helper to apply the TCP keep-alive settings to the socket if configured to do so.
Requires that m_socketMutex is locked.
bufferSetFromHash
karabo::data::BufferSet::Pointer bufferSetFromHash(const karabo::data::Hash& data, bool copyAllData)
Creates a buffer set with a given hash stored in its sole buffer.
data
: the hash to be stored in the buffer set.
copyAllData
: if false no copy of any NDArray internal to the hash will be made upon storing the
hash in the bufferset (the buffer set will actually become one of the "owners" of the NDArray).
Return : pBuffSet a shared pointer that will be pointed to the newly created buffer set with the hash.
bufferSetFromPointerToChar
karabo::data::BufferSet::Pointer bufferSetFromPointerToChar(const char* data, size_t size)
Creates a buffer set with contents of a given buffer of chars stored in its sole buffer.
data
: a pointer to the first char in the input sequence.
Return : shared_ptr to the buffer set with the input buffer contents stored.
Note
actually places a copy of the contents of the input buffer into the buffer set.
bufferSetFromString
karabo::data::BufferSet::Pointer bufferSetFromString(const std::string& str)
Creates a buffer set with the given string stored in its sole buffer.
str
: the string to be stored in the buffer set.
Return : shared_ptr to the buffer set with the string stored.
Note
actually places a copy of the string into the buffer set.
bufferSetFromVectorCharPointer
karabo::data::BufferSet::Pointer bufferSetFromVectorCharPointer(const VectorCharPointer& dataVect)
Creates a buffer set with characters in a given vector of chars stored in its sole buffer.
data
: a pointer to the vector of chars to be stored in the buffer set.
Return : shared_ptr to the buffer set with the character in the vector stored.
byteSizeAvailableHandler
void byteSizeAvailableHandler(const size_t byteSize)
Internal default handler
byteSize
:
bytesAvailableHandler
void bytesAvailableHandler(const boost::system::error_code& e)
Internal default handler
channel
:
consumeBytesAfterReadUntil
std::string consumeBytesAfterReadUntil(const size_t nBytes) override
***********************************************************
***********************************************************
Synchronously reads size bytes and return them as a string. The reading will block until the bytes are read.
size
: This number of bytes will be copied into data
Note
reads up nBytes expecting no header. This method should ONLY be used in association with readAsyncStringUntil - they consume from the same boost::asio::streamBuffer and should not be used in the same context of the other read* methods.
getChannelInfo
static karabo::data::Hash getChannelInfo(const std::shared_ptr<karabo::net::TcpChannel>& ptr)
This function returns low level info about connection like ... "localIp", "localPort", "remoteIp", "remotePort" that constitute active connection. in form of Hash container
ptr
: input TcpChannel boost shared pointer
Return : Hash with 4 key/value pairs
getConnection
Connection::Pointer getConnection() const override
Pointer to connection of this channel - empty if that is not alive anymore
onSizeInBytesAvailable
void onSizeInBytesAvailable(const ErrorCode& error, const ReadSizeInBytesHandler& handler)
This function calls the corresponding handler
handler
:
error
:
onVectorBufferSetPointerAvailable
void onVectorBufferSetPointerAvailable(const ErrorCode& error, size_t length, const std::vector<karabo::data::BufferSet::Pointer>& buffers, const ReadVectorBufferSetPointerHandler& handler)
Internal handler called after filling the buffer set
error
: error code
length
: number of bytes read == total size of buffer set
buffers
: vector of buffer set pointers with the data
handler
: to be called
queueInfo
karabo::data::Hash queueInfo()
Records the sizes of the write queues in a Hash. Useful for debugging devices with multiple channels open (like the GuiServerDevice...)
read
void read(char* data, const size_t& size) override
Synchronously reads size bytes from TCP socket into data.
data
: Pre-allocated contiguous block of memory
size
: This number of bytes will be copied into data
void read(std::vector<char>& data) override
This function reads from a channel into vector of chars The reading will block until the data record is read. The vector will be updated accordingly (must not be pre-allocated before)
Return : void
void read(std::shared_ptr<std::vector<char>>& data) override
This function reads from a channel into shared pointer of vector of chars The reading will block until the data record is read. The shared pointer of vector will be updated accordingly (must not be pre-allocated before)
Return : void
void read(karabo::data::Hash& data) override
This function reads from a channel into vector of chars The reading will block until the data record is read. The size of data record is the first 4 bytes in a channel stream. The hash will be updated accordingly.
Return : void
void read(karabo::data::Hash& header, char* data, const size_t& size) override
Synchronously reads size bytes from socket into data and provides a header.
header
: Hash object which will be updated to contain header information
data
: Pre-allocated contiguous block of memory
size
: This number of bytes will be copied into data
void read(karabo::data::Hash& header, std::vector<char>& data) override
This function reads into a header and a vector of chars. The reading will block until the data record is read.
header
: Hash object which will be updated to contain header information
data
: A vector which will be updated accordingly
void read(karabo::data::Hash& header, std::shared_ptr<std::vector<char>>& data) override
This function reads into a header and shared pointer of vector of chars. The reading will block until the data record is read.
header
: Hash object which will be updated to contain header information
data
: A shared pointer of a vector which will be updated accordingly
void read(karabo::data::Hash& header, karabo::data::Hash& data) override
This function reads into a header hash and a data hash. The reading will block until the data record is read. The reading will block until the data record is read.
header
: Hash object which will be updated to contain header information
data
: Hash object which will be updated to contain data information
readAsyncRaw
void readAsyncRaw(char* data, const size_t& size, const ReadRawHandler& handler) override
Asynchronously reads size number of bytes into pre-allocated data buffer A handler can be registered to inform about completion of writing
data
: Pre-allocated contiguous block of memory
size
: This number of bytes will be copied into data
handler
: Function of signature:
readAsyncSizeInBytes
void readAsyncSizeInBytes(const ReadSizeInBytesHandler& handler) override
In case a TCP message arrived, handler will be called back The handler will inform about the number of bytes going to come in The handler must have the following signature: void handler(Channel::Pointer, const size_t&)
handler
: Callback with signature: void (Channel::Pointer, const size_t&)
readAsyncStringUntil
void readAsyncStringUntil(const std::string& terminator, const ReadStringHandler& handler) override
wrapper around boost::asio::async_read_until
Read a string until terminator string is found. (No header is expected).
terminator
: when this string found, read is done
handler
: handler with signature ReadStringHandler,
i.e. void (const boost::system::error_code&, std::string&) is called.
second handler parameter is the read string including the terminator
Note
This method should ONLY be used in association with consumeBytesAfterReadUntil - they consume from the same boost::asio::streambuf and should not be used in the same context of the other read* methods.
readSizeInBytes
size_t readSizeInBytes() override
Synchronously reads the TCP message's size. Will block until a message arrives on the socket.
Return : Size in bytes of incoming TCP message
remoteAddress
std::string remoteAddress() const
Address of the remote endpoint
storeCompleteHandler
unsigned int storeCompleteHandler(const WriteCompleteHandler& handler)
Helper to store async write completion handler
handler
: write completion handler to be stored
Return : index under which handler is stored in internal map
writeAsync
void writeAsync(const char* data, const size_t& size, int prio)
Writes a copy from the data array.
void writeAsync(const std::vector<char>& data, int prio)
Writes a copy of the data vector.
void writeAsync(const std::shared_ptr<std::vector<char>>& data, int prio)
Sends the vector pointed by data. The data vector must not be changed after the call to writeAsync.
void writeAsync(const std::string& data, int prio)
Writes a copy of the data string.
void writeAsync(const karabo::data::Hash& data, int prio, bool copyAllData)
When copyAllData is false, elements of type NDArray in the hash won't be copied before being sent.
void writeAsync(const karabo::data::Hash& header, const char* data, const size_t& size, int prio)
Writes copies of the header hash and the data array.
void writeAsync(const karabo::data::Hash& header, const std::vector<char>& data, int prio)
Writes copies of the header hash and of the data vector.
void writeAsync(const karabo::data::Hash& header, const std::shared_ptr<std::vector<char>>& data, int prio)
Writes a copy of the header hash. Sends the vector pointed by data, not a copy of it. The data vector must not be changed after the call to writeAsync.
void writeAsync(const karabo::data::Hash& header, const std::string& data, int prio)
Writes copies of the header hash and of the data string.
void writeAsync(const karabo::data::Hash& header, const karabo::data::Hash& data, int prio, bool copyAllData)
When copyAllData is false, elements of type NDArray in the body hash won't be copied before being sent. copyAllData doesn't influence the handling of the header hash.