MLIB
|
Provide functions required by streambuf
interface using an underlying socket.
More...
#include <wsockstream.h>
Public Member Functions | |
sockbuf (SOCKET soc=INVALID_SOCKET) | |
Build a sockbuf object from an existing socket. | |
sockbuf (int type, int domain=AF_INET, int proto=0) | |
Build a sockbuf object and the attached socket with the given parameters. | |
sockbuf (const sockbuf &) | |
Copy constructor. | |
sockbuf (const sock &soc) | |
Build a sockbuf object from a sock base. | |
virtual | ~sockbuf () |
Destructor. | |
sockbuf & | operator= (const sockbuf &) |
Assignment operator. | |
Public Member Functions inherited from mlib::sock | |
sock () | |
Default constructor creates a closed socket. | |
sock (SOCKET soc) | |
Create a sock object from a socket handle. | |
sock (int type, int domain=AF_INET, int proto=0) | |
Construct a sock object for the specified domain. | |
sock (const sock &) | |
Copy constructor. | |
sock (sock &&) | |
Move constructor. | |
virtual | ~sock () |
Destructor. | |
sock & | operator= (const sock &) |
Assignment operator. | |
sock & | operator= (sock &&) |
Move assignment. | |
HANDLE | handle () const |
Retrieve Windows socket handle. | |
bool | operator== (const sock &other) const |
Equality comparison operator. | |
bool | operator!= (const sock &other) const |
Inequality comparison operator. | |
virtual erc | open (int type, int domain=AF_INET, int proto=0) |
Open the socket. | |
virtual erc | close () |
Close socket. | |
virtual erc | shutdown (shuthow sh) const |
Disables sends or receives on socket. | |
virtual bool | is_open () const |
Check if socket is opened. | |
size_t | recv (void *buf, size_t maxlen, mflags msgf=mflags::none) const |
Receives data from socket. | |
size_t | recvfrom (sockaddr &sa, void *buf, size_t maxlen, mflags msgf=mflags::none) const |
Receives data from socket. | |
size_t | send (const void *buf, size_t len, mflags msgf=mflags::none) const |
Send data to the connected peer. | |
template<typename T > | |
size_t | send (std::basic_string< T > buf, mflags msgf=mflags::none) const |
Send data to connected peer. | |
size_t | sendto (const sockaddr &sa, const void *buf, size_t len, mflags msgf=mflags::none) const |
Send data to a peer. | |
template<typename T > | |
size_t | sendto (const sockaddr &sa, std::basic_string< T > buf, mflags msgf=mflags::none) const |
Send data to a peer. | |
int | sendtimeout (int wp_sec) const |
Set send timeout value. | |
int | sendtimeout () const |
Returns the send timeout value. | |
int | recvtimeout (int wp_sec) const |
Set receive timeout value. | |
int | recvtimeout () const |
Returns the send timeout value. | |
bool | is_readready (int wp_sec, int wp_usec=0) const |
Check if socket is "readable". | |
bool | is_writeready (int wp_sec, int wp_usec=0) const |
Check if socket is "writable". | |
bool | is_exceptionpending (int wp_sec, int wp_usec=0) const |
Check if socket has OOB data or any exceptional error conditions. | |
unsigned int | nread () const |
Return number of characters waiting in socket's buffer. | |
erc | bind (const inaddr &) const |
Associates a local address with the socket. | |
erc | bind () const |
Associates a local address with the socket. | |
erc | connect (const inaddr &peer) const |
Establishes a connection to specified peer. | |
erc | connect (const inaddr &peer, int wp_sec) const |
Establishes a connection to a specified address. | |
erc | listen (int num=SOMAXCONN) const |
Places the socket in a state in which it is listening for incoming connections. | |
erc | accept (sock &client, inaddr *sa=nullptr) const |
Permits an incoming connection attempt on the socket. | |
erc | accept (sock &client, int wp_sec, inaddr *sa=nullptr) const |
Permits an incoming connection attempt on the socket. | |
erc | name (inaddr &addr) const |
Return the local name for the object. | |
erc | peer (inaddr &addr) const |
Retrieves the name of the peer to which the socket is connected. | |
int | getopt (int op, void *buf, int len, int level=SOL_SOCKET) const |
Returns a socket option. | |
erc | setopt (int op, void *buf, int len, int level=SOL_SOCKET) const |
Set a socket option. | |
int | gettype () const |
Return socket type (SOCK_DGRAM or SOCK_STREAM) | |
int | clearerror () const |
Return and clear the socket error flag. | |
bool | debug () const |
Return the debug flag. | |
void | debug (bool opt) const |
Set the debug flag. | |
bool | reuseaddr () const |
Return the "reuse address" flag. | |
void | reuseaddr (bool opt) const |
Set the "reuse address" flag. | |
bool | keepalive () const |
Return "keep alive" flag. | |
void | keepalive (bool opt) const |
Set "keep alive" flag. | |
bool | dontroute () const |
Return status of "don't route" flag. | |
void | dontroute (bool opt) const |
Turn on or off the "don't route" flag. | |
bool | broadcast () const |
Return "broadcast" option. | |
void | broadcast (bool opt) const |
Turn on or off the "broadcast" option. | |
bool | oobinline () const |
Return the status of the OOB_INLINE flag. | |
void | oobinline (bool opt) const |
Set the status of the OOB_INLINE flag. | |
int | sendbufsz () const |
Return buffer size for send operations. | |
void | sendbufsz (size_t sz) const |
Set buffer size for send operations. | |
int | recvbufsz () const |
Return buffer size for receive operations. | |
void | recvbufsz (size_t sz) const |
Set buffer size for receive operations. | |
void | blocking (bool on_off) |
Change blocking mode. | |
erc | setevent (HANDLE evt, long mask) const |
Associate an event object with this socket. | |
long | enumevents () const |
Indicates which of the FD_XXX network events have occurred. | |
void | linger (bool on_off, unsigned short seconds) const |
Turn on or off linger mode and lingering timeout. | |
bool | linger (unsigned short *seconds=0) const |
Return linger mode and lingering timeout. | |
Protected Member Functions | |
Redefined virtuals from parent <tt>streambuf</tt> | |
virtual int | underflow () override |
underflow | |
virtual int | overflow (int c=EOF) override |
If c == EOF or buffer full, return sync(); otherwise insert c into the buffer and return c. | |
virtual int | sync () override |
Return 0 if all chars flushed or -1 if error. | |
virtual std::streambuf * | setbuf (char *buf, std::streamsize sz) override |
Change buffering mode. | |
virtual std::streamsize | showmanyc () override |
Return number of characters available in socket buffer. | |
Additional Inherited Members | |
Public Types inherited from mlib::sock | |
enum | shuthow { shut_read = 0 , shut_write = 1 , shut_readwrite = 2 } |
operation blocked by shutdown function More... | |
enum | mflags { none = 0 , out_of_band = MSG_OOB , peek = MSG_PEEK , dont_route = MSG_DONTROUTE , wait_all = MSG_WAITALL } |
Flags for send/receive operations. More... | |
Static Public Member Functions inherited from mlib::sock | |
static errfac & | Errors () |
Return error facility used by all sock-derived classes. | |
static void | Errors (errfac &facitlity) |
Set the error facility use by all sock-derived classes. | |
Static Protected Member Functions inherited from mlib::sock | |
static erc | last_error () |
Return an error code with the value returned by WSAGetLastError. | |
Provide functions required by streambuf
interface using an underlying socket.
You can simultaneously read and write into a sockbuf just like you can listen and talk through a telephone.
Hence, the read and the write buffers are different.
Read: eback() points to the start of the get area. The unread chars are gptr() to egptr().
eback() is set to base() so that pbackfail() is called only when there is no place to putback a char. And pbackfail() always returns EOF.
Write: pbase() points to the start of the put area The unflushed chars are pbase() - pptr()
epptr() points to the end of the write buffer.
Output is flushed whenever one of the following conditions holds: (1) pptr() == epptr()
(2) EOF is written
Unbuffered: Input buffer size is assumed to be of size 1 and output buffer is of size 0. That is, egptr() <= base()+1
and epptr() == pbase()
.
Assignment operator.
Maintains current buffering mode
|
overrideprotectedvirtual |
Change buffering mode.
If buf
is NULL, switches to automatic buffering mode with separate buffers for input and output.