47 #ifndef __sockpp_stream_socket_h 48 #define __sockpp_stream_socket_h 123 base::operator=(std::move(rhs));
147 virtual ssize_t
read(
void *buf,
size_t n);
157 virtual ssize_t
read_n(
void *buf,
size_t n);
163 ssize_t
read(
const std::vector<iovec>& ranges);
171 virtual bool read_timeout(
const std::chrono::microseconds& to);
179 template<
class Rep,
class Period>
181 return read_timeout(std::chrono::duration_cast<std::chrono::microseconds>(to));
189 virtual ssize_t
write(
const void *buf,
size_t n);
197 virtual ssize_t
write_n(
const void *buf,
size_t n);
205 virtual ssize_t
write(
const std::string& s) {
206 return write_n(s.data(), s.size());
213 virtual ssize_t
write(
const std::vector<iovec> &ranges);
221 virtual bool write_timeout(
const std::chrono::microseconds& to);
229 template<
class Rep,
class Period>
231 return write_timeout(std::chrono::duration_cast<std::chrono::microseconds>(to));
244 template <
typename ADDR>
252 static constexpr sa_family_t ADDRESS_FAMILY = ADDR::ADDRESS_FAMILY;
271 :
base(std::move(sock)) {}
277 :
base(std::move(sock)) {}
284 base::operator=(std::move(rhs));
307 static std::tuple<stream_socket_tmpl, stream_socket_tmpl>
pair(
int protocol=0) {
309 return std::make_tuple<stream_socket_tmpl, stream_socket_tmpl>(
331 #endif // __sockpp_socket_h stream_socket_tmpl()
Creates an unconnected streaming socket.
Definition: stream_socket.h:258
static std::tuple< socket, socket > pair(int domain, int type, int protocol=0)
Creates a pair of connected sockets.
virtual ssize_t write_n(const void *buf, size_t n)
Best effort attempt to write the whole buffer to the socket.
stream_socket & operator=(stream_socket &&rhs)
Move assignment.
Definition: stream_socket.h:122
sock_address_any address() const
Gets the local address to which the socket is bound.
addr_t peer_address() const
Gets the address of the remote peer, if this socket is connected.
Definition: stream_socket.h:324
stream_socket(stream_socket &&sock)
Creates a stream socket by copying the socket handle from the specified socket object and transfers o...
Definition: stream_socket.h:96
Base class for streaming sockets, such as TCP and Unix Domain.
Definition: stream_socket.h:62
virtual bool write_timeout(const std::chrono::microseconds &to)
Set a timeout for write operations.
virtual ssize_t read(void *buf, size_t n)
Reads from the port.
stream_socket_tmpl(stream_socket &&sock)
Move constructor.
Definition: stream_socket.h:270
static socket_t create_handle(int domain)
Creates a streaming socket.
Definition: stream_socket.h:75
stream_socket clone() const
Creates a new stream_socket that refers to this one.
Definition: stream_socket.h:137
stream_socket()
Creates an unconnected streaming socket.
Definition: stream_socket.h:85
virtual bool read_timeout(const std::chrono::microseconds &to)
Set a timeout for read operations.
bool write_timeout(const std::chrono::duration< Rep, Period > &to)
Set a timeout for write operations.
Definition: stream_socket.h:230
ADDR addr_t
The type of network address used with this socket.
Definition: stream_socket.h:254
static std::tuple< stream_socket_tmpl, stream_socket_tmpl > pair(int protocol=0)
Creates a pair of connected stream sockets.
Definition: stream_socket.h:307
Class for creating a streaming server.
Definition: acceptor.h:63
socket()
Creates an unconnected (invalid) socket.
Definition: socket.h:183
stream_socket_tmpl(stream_socket_tmpl &&sock)
Creates a stream socket by copying the socket handle from the specified socket object and transfers o...
Definition: stream_socket.h:276
Definition: acceptor.h:51
socket clone() const
Creates a new socket that refers to this one.
static socket create(int domain, int type, int protocol=0)
Creates a socket with the specified communications characterics.
stream_socket_tmpl create(int protocol=0)
Cretates a stream socket.
Definition: stream_socket.h:292
Base class for socket objects.
Definition: socket.h:84
int socket_t
The OS socket handle.
Definition: socket.h:60
stream_socket_tmpl & operator=(stream_socket_tmpl &&rhs)
Move assignment.
Definition: stream_socket.h:283
sock_address_any peer_address() const
Gets the address of the remote peer, if this socket is connected.
socket_t release()
Releases ownership of the underlying socket object.
Definition: socket.h:311
stream_socket_tmpl(socket_t handle)
Creates a streaming socket from an existing OS socket handle and claims ownership of the handle...
Definition: stream_socket.h:264
Template for creating specific stream types (IPv4, IPv6, etc).
Definition: stream_socket.h:245
static constexpr int COMM_TYPE
The socket 'type' for communications semantics.
Definition: stream_socket.h:81
Classes for TCP & UDP socket.
bool read_timeout(const std::chrono::duration< Rep, Period > &to)
Set a timeout for read operations.
Definition: stream_socket.h:180
stream_socket(socket_t handle)
Creates a streaming socket from an existing OS socket handle and claims ownership of the handle...
Definition: stream_socket.h:91
socket_t handle() const
Get the underlying OS socket handle.
Definition: socket.h:259
virtual ssize_t write(const void *buf, size_t n)
Writes the buffer to the socket.
static stream_socket create(int domain, int protocol=0)
Creates a socket with the specified communications characterics.
addr_t address() const
Gets the local address to which the socket is bound.
Definition: stream_socket.h:318
virtual ssize_t write(const std::string &s)
Best effort attempt to write a string to the socket.
Definition: stream_socket.h:205
virtual ssize_t read_n(void *buf, size_t n)
Best effort attempts to read the specified number of bytes.