1 #ifndef _FIBERIO_SOCKET_H_ 2 #define _FIBERIO_SOCKET_H_ 27 socket(std::shared_ptr<socket_impl>&& impl);
39 void connect(
const std::string& host, uint16_t port);
47 std::size_t
read(
char* buf, std::size_t size);
61 bool shrink_to_fit =
true);
67 void write(
const char* data, std::size_t len);
70 void write(
const std::string& data);
86 std::shared_ptr<socket_impl> impl_;
void close()
Closes the socket if it's not already closed.
~socket()
Destructor. Closes the socket if still open.
socket()
Creates a non-connected socket.
Client socket for communicating over a network and opening connections.
void connect(const std::string &host, uint16_t port)
Connects to host:port and throws an exception on failure.
std::size_t read(char *buf, std::size_t size)
Reads up to size bytes into buf.
void write(const char *data, std::size_t len)
Writes data from the buffer and returns once the buffer can be freed.
static constexpr std::size_t DEFAULT_BUF_SIZE
socket & operator=(const socket &other)
Copy assignment.
std::string read_string_exactly(std::size_t count)
The same as read_string() but reads exactly count bytes (or fails)
std::string read_string(std::size_t count=DEFAULT_BUF_SIZE, bool shrink_to_fit=true)
Reads up to count bytes and returns it as an std::string.
void read_exactly(char *buf, std::size_t size)
The same as read() but always fills the buffer completely (or fails)
bool is_open()
Check if the connection is open.