PL::NetworkStream class
-
class NetworkStream : public PL::Stream
Network stream class.
Public Functions
-
inline NetworkStream()
Creates a closed network stream.
-
NetworkStream(int sock)
Creates an open network stream.
Note
The stream does not take ownership of the socket. The caller remains responsible for closing it, whether by calling Close or by closing the socket directly.
- Parameters:
sock – stream socket
-
virtual esp_err_t Lock(TickType_t timeout = portMAX_DELAY) override
Locks the object.
- Parameters:
timeout – timeout in FreeRTOS ticks
- Returns:
error code
-
virtual esp_err_t Unlock() override
Unlocks the object.
- Returns:
error code
-
virtual esp_err_t Read(void *dest, size_t size) override
Reads the data from the stream.
- Parameters:
dest – destination (can be NULL)
size – number of bytes to read
- Returns:
error code
-
virtual esp_err_t Write(const void *src, size_t size) override
Writes the data to the stream.
- Parameters:
src – source
size – number of bytes to write
- Returns:
error code
-
esp_err_t Close()
Closes the stream.
- Returns:
error code
-
esp_err_t EnableNagleAlgorithm()
Enables the Nagle’s algorithm.
- Returns:
error code
-
esp_err_t DisableNagleAlgorithm()
Disables the Nagle’s algorithm.
- Returns:
error code
-
esp_err_t EnableKeepAlive()
Enables the keep-alive packets.
- Returns:
error code
-
esp_err_t DisableKeepAlive()
Disables the keep-alive packets.
- Returns:
error code
-
bool IsOpen()
Checks if the stream is open.
- Returns:
true if the stream is open
-
virtual size_t GetReadableSize() override
Gets the number of bytes that are available for reading from the stream.
- Returns:
number of bytes
-
virtual TickType_t GetReadTimeout() override
Gets the read operation timeout.
- Returns:
timeout in FreeRTOS ticks
-
virtual esp_err_t SetReadTimeout(TickType_t timeout) override
Sets the read operation timeout.
- Parameters:
timeout – timeout in FreeRTOS ticks
- Returns:
error code
-
virtual TickType_t GetWriteTimeout() override
Gets the write operation timeout.
- Returns:
timeout in FreeRTOS ticks
-
virtual esp_err_t SetWriteTimeout(TickType_t timeout) override
Sets the write operation timeout.
- Parameters:
timeout – timeout in FreeRTOS ticks
- Returns:
error code
-
NetworkEndpoint GetLocalEndpoint()
Gets the local endpoint of the stream.
- Returns:
local endpoint
-
NetworkEndpoint GetRemoteEndpoint()
Gets the remote endpoint of the stream.
- Returns:
remote endpoint
-
esp_err_t SetKeepAliveIdleTime(int seconds)
Sets the idle time before the keep-alive packets are sent.
- Parameters:
seconds – time in seconds
- Returns:
error code
-
esp_err_t SetKeepAliveInterval(int seconds)
Sets the keep-alive packet interval.
- Parameters:
seconds – interval in seconds
- Returns:
error code
-
esp_err_t SetKeepAliveCount(int count)
Sets the number of the keep-alive packets.
- Parameters:
count – number of packets
- Returns:
error code
-
virtual esp_err_t Read(void *dest, size_t size) = 0
Reads the data from the stream.
- Parameters:
dest – destination (can be NULL)
size – number of bytes to read
- Returns:
error code
-
esp_err_t Read(Buffer &dest, size_t offset, size_t size)
Reads the data from the stream to the buffer.
- Parameters:
dest – destination buffer
offset – destination buffer offset
size – number of bytes to read
- Returns:
error code
-
virtual esp_err_t Write(const void *src, size_t size) = 0
Writes the data to the stream.
- Parameters:
src – source
size – number of bytes to write
- Returns:
error code
-
esp_err_t Write(Buffer &src, size_t offset, size_t size)
Writes the data from the buffer to the stream.
- Parameters:
src – source buffer
offset – source buffer offset
size – number of bytes to write
- Returns:
error code
-
esp_err_t Write(const std::string &src)
Writes the string to the stream.
- Parameters:
src – source string
- Returns:
error code
-
esp_err_t ReadUntil(void *dest, size_t maxSize, char termChar, size_t *size)
Reads the data from the stream up to the specified termination character.
- Parameters:
dest – destination (can be NULL)
maxSize – maximum number of bytes to read
termChar – termination character
size – number of bytes read
- Returns:
error code
-
esp_err_t ReadUntil(Buffer &dest, size_t offset, char termChar, size_t *size)
Reads the data from the stream to the buffer up to the specified termination character.
- Parameters:
dest – destination buffer
offset – destination buffer offset
termChar – termination character
size – number of bytes read
- Returns:
error code
-
esp_err_t ReadUntil(char termChar)
Reads the data from the stream up to the specified termination character.
- Parameters:
termChar – termination character
- Returns:
error code
-
esp_err_t FlushReadBuffer(TickType_t time = 0)
Discards the data in the read buffer until no data is received for the specified period of time.
- Parameters:
time – time
- Returns:
error code
-
inline NetworkStream()