Furrent
|
#include <socket.hpp>
Public Member Functions | |
Outcome< SocketError > | connect (uint32_t ip, uint16_t port, timeout timeout) |
Attempt connecting to a TCP server within the given timeout. More... | |
bool | is_open () |
Returns true if the socket is open. More... | |
Outcome< SocketError > | write (const std::vector< uint8_t > &buf, timeout timeout) |
Result< std::vector< uint8_t >, SocketError > | read (int64_t n, timeout timeout) |
Attempt to readn n bytes from the socket with the given timeout. More... | |
Outcome< SocketError > | close () |
Close the socket. More... | |
A Socket
wraps an asio::ip::tcp::socket
providing a simplified interface enhanced with timeout support. All methods are blocking and don't spawn any more threads.
Outcome< SocketError > fur::download::socket::Socket::close | ( | ) |
Close the socket.
Outcome< SocketError > fur::download::socket::Socket::connect | ( | uint32_t | ip, |
uint16_t | port, | ||
timeout | timeout | ||
) |
Attempt connecting to a TCP server within the given timeout.
bool fur::download::socket::Socket::is_open | ( | ) |
Returns true
if the socket is open.
Result< std::vector< uint8_t >, SocketError > fur::download::socket::Socket::read | ( | int64_t | n, |
timeout | timeout | ||
) |
Attempt to readn n
bytes from the socket with the given timeout.
resize takes in a size_t and we can safely pass an int64_t because, on a 64bits machine, it used 1 fewer bits than size_t
Outcome< SocketError > fur::download::socket::Socket::write | ( | const std::vector< uint8_t > & | buf, |
timeout | timeout | ||
) |
Attempt to write all the bytes in buf
to the socket with the given timeout.