TcpStream class
#include <core/net/tcp_stream.hpp>
Stream implementation which writes to/reads from a TCP connection.
Base classes
- class cubos::core::memory::Stream
- Interface class for memory streams. Abstracts away sources or destinations of data.
Constructors, destructors, conversion operators
Public functions
- auto operator=(const TcpStream&) -> TcpStream& deleted
- Forbid copy assignment.
- auto connect(const Address& address, uint16_t port) -> bool
- Connects to a TCP listener, possibly on a remote machine.
- void inner(InnerSocket socket)
- Replaces the inner socket with the given one.
- void disconnect()
- Disconnects inner socket.
- auto valid() const -> bool
- Checks if inner socket is currently valid successfully.
- auto setBlocking(bool blocking) -> bool
- Control blocking mode of inner socket.
- auto read(void* data, std::size_t size) -> std::size_t override
- Reads data from the stream.
- auto write(const void* data, std::size_t size) -> std::size_t override
- Writes data to the stream.
- auto tell() const -> std::size_t override
- Gets the current position in the stream.
- auto eof() const -> bool override
- Checks if the stream still has content to read.
- auto peek() -> char override
- Peeks one byte from the stream.
-
void seek(ptrdiff_t offset,
memory::
SeekOrigin origin) override - Seeks to a position in the stream.
Function documentation
void cubos:: core:: net:: TcpStream:: inner(InnerSocket socket)
Replaces the inner socket with the given one.
| Parameters | |
|---|---|
| socket | Socket. |
| Returns | Whether connecting was successful. |
bool cubos:: core:: net:: TcpStream:: valid() const
Checks if inner socket is currently valid successfully.
| Returns | Whether inner socket is valid. |
|---|
bool cubos:: core:: net:: TcpStream:: setBlocking(bool blocking)
Control blocking mode of inner socket.
| Parameters | |
|---|---|
| blocking | Whether to block or not. |
| Returns | Whether setting the block flag was sucessful. |
std::size_t cubos:: core:: net:: TcpStream:: read(void* data,
std::size_t size) override
Reads data from the stream.
| Parameters | |
|---|---|
| data | Buffer to read data into. |
| size | Size of the buffer. |
| Returns | Number of bytes read. |
std::size_t cubos:: core:: net:: TcpStream:: write(const void* data,
std::size_t size) override
Writes data to the stream.
| Parameters | |
|---|---|
| data | Buffer to write data from. |
| size | Size of the buffer. |
| Returns | Number of bytes written. |
std::size_t cubos:: core:: net:: TcpStream:: tell() const override
Gets the current position in the stream.
| Returns | Current position in the stream, or SIZE_MAX if the position is unknown. |
|---|
bool cubos:: core:: net:: TcpStream:: eof() const override
Checks if the stream still has content to read.
| Returns | Whether the stream has reached the end. |
|---|
char cubos:: core:: net:: TcpStream:: peek() override
Peeks one byte from the stream.
| Returns | Peeked byte. |
|---|
void cubos:: core:: net:: TcpStream:: seek(ptrdiff_t offset,
memory:: SeekOrigin origin) override
Seeks to a position in the stream.
| Parameters | |
|---|---|
| offset | Offset to seek to. |
| origin | Origin of the offset. |