Furrent
Public Member Functions | List of all members
fur::download::socket::Socket Class Reference

#include <socket.hpp>

Public Member Functions

Outcome< SocketErrorconnect (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< SocketErrorwrite (const std::vector< uint8_t > &buf, timeout timeout)
 
Result< std::vector< uint8_t >, SocketErrorread (int64_t n, timeout timeout)
 Attempt to readn n bytes from the socket with the given timeout. More...
 
Outcome< SocketErrorclose ()
 Close the socket. More...
 

Detailed Description

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.

Member Function Documentation

◆ close()

Outcome< SocketError > fur::download::socket::Socket::close ( )

Close the socket.

◆ connect()

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.

◆ is_open()

bool fur::download::socket::Socket::is_open ( )

Returns true if the socket is open.

◆ read()

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

◆ write()

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.


The documentation for this class was generated from the following files: