E-MailRelay

Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
GNet::StreamSocket Class Reference

A derivation of GNet::Socket for a stream socket. More...

`#include <gsocket.h>`

Inheritance diagram for GNet::StreamSocket:

## Classes
struct | Listener
| Overload discriminator class for GNet::StreamSocket. More...

## Public Types
using | size_type = Socket::size_type
using | ssize_type = Socket::ssize_type
Public Types inherited from GNet::SocketBase
using | size_type = G::ReadWrite::size_type
using | ssize_type = G::ReadWrite::ssize_type
Public Types inherited from G::ReadWrite
using | size_type = std::size_t
using | ssize_type = ssize_t

## Public Member Functions
| StreamSocket (Address::Family)
| Constructor. More...
| StreamSocket (Address::Family, const Listener &)
| Constructor overload specifically for a listening socket, which might need slightly different socket options. More...
ssize_type | read (char *buffer, size_type buffer_length) override
| Override from ReadWrite::read(). More...
ssize_type | write (const char *buf, size_type len) override
| Override from Socket::write(). More...
AcceptPair | accept ()
| Accepts an incoming connection, returning a new()ed socket and the peer address. More...
| StreamSocket (const StreamSocket &)=delete
| StreamSocket (StreamSocket &&)=delete
void | operator= (const StreamSocket &)=delete
void | operator= (StreamSocket &&)=delete
Public Member Functions inherited from GNet::Socket
Address | getLocalAddress () const
| Retrieves local address of the socket. More...
std::pair< bool, Address > | getPeerAddress () const
| Retrieves address of socket's peer. More...
void | bind (const Address &)
| Binds the socket with the given address. More...
bool | bind (const Address &, std::nothrow_t)
| No-throw overload. Returns false on error. More...
unsigned long | getBoundScopeId () const
| Returns the scope-id of the address last successfully bind()ed. More...
bool | connect (const Address &addr, bool *done=nullptr)
| Initiates a connection to (or association with) the given address. More...
void | listen (int backlog=1)
| Starts the socket listening on the bound address for incoming connections or incoming datagrams. More...
void | shutdown (int how=1)
| Modifies the local socket state so that so that new sends (1 or 2) and/or receives (0 or 2) will fail. More...
| Socket (const Socket &)=delete
| Socket (Socket &&)=delete
void | operator= (const Socket &)=delete
void | operator= (Socket &&)=delete
Public Member Functions inherited from GNet::SocketBase
| ~SocketBase () override
| Destructor. More...
SOCKET | fd () const noexcept override
| Returns the socket file descriptor. More...
bool | eWouldBlock () const override
| Returns true if the previous socket operation failed because the socket would have blocked. More...
bool | eInProgress () const
| Returns true if the previous socket operation failed with the EINPROGRESS error status. More...
bool | eMsgSize () const
| Returns true if the previous socket operation failed with the EMSGSIZE error status. More...
bool | eTooMany () const
| Returns true if the previous socket operation failed with the EMFILE error status, or similar. More...
bool | eNotConn () const
| Returns true if the previous socket operation failed with the ENOTCONN error status, or similar. More...
void | addReadHandler (EventHandler &, ExceptionSink)
| Adds this socket to the event source list so that the given handler receives read events. More...
void | dropReadHandler () noexcept
| Reverses addReadHandler(). More...
void | addWriteHandler (EventHandler &, ExceptionSink)
| Adds this socket to the event source list so that the given handler receives write events when flow control is released. More...
void | dropWriteHandler () noexcept
| Reverses addWriteHandler(). More...
void | addOtherHandler (EventHandler &, ExceptionSink)
| Adds this socket to the event source list so that the given handler receives exception events. More...
void | dropOtherHandler () noexcept
| Reverses addOtherHandler(). More...
std::string | asString () const
| Returns the socket handle as a string. More...
std::string | reason () const
| Returns the reason for the previous error. More...
| SocketBase (const SocketBase &)=delete
| SocketBase (SocketBase &&)=delete
void | operator= (const SocketBase &)=delete
void | operator= (SocketBase &&)=delete
Public Member Functions inherited from G::ReadWrite
virtual ssize_type | read (char *buffer, size_type buffer_length)=0
| Reads data. More...
virtual ssize_type | write (const char *buf, size_type len)=0
| Sends data. More...
virtual bool | eWouldBlock () const =0
| See read() and write(). More...
virtual SOCKET | fd () const noexcept=0
| Returns the file descriptor. More...
virtual | ~ReadWrite ()=default
| Destructor.

## Static Public Member Functions
static bool | supports (Address::Family)
| Returns true if stream sockets can be created with the given the address family. More...
Static Public Member Functions inherited from GNet::Socket
static std::string | canBindHint (const Address &address, bool stream_socket=true)
| Returns the empty string if a socket could probably be bound with the given address or a failure reason. More...
Static Public Member Functions inherited from GNet::SocketBase
static bool | supports (Address::Family, int type, int protocol)
| Returns true if sockets can be created with the given parameters. More...

## Additional Inherited Members
Protected Member Functions inherited from GNet::Socket
| Socket (Address::Family, int type, int protocol)
| Socket (Address::Family, Descriptor s, const Accepted &)
std::pair< bool, Address > | getLocalAddress (std::nothrow_t) const
void | setOption (int, const char *, int, int)
bool | setOption (int, const char *, int, int, std::nothrow_t)
bool | setOptionImp (int, int, const void *, socklen_t)
void | setOptionsOnBind (Address::Family)
void | setOptionsOnConnect (Address::Family)
void | setOptionLingerImp (int, int)
void | setOptionNoLinger ()
void | setOptionReuse ()
void | setOptionExclusive ()
void | setOptionPureV6 ()
bool | setOptionPureV6 (std::nothrow_t)
void | setOptionKeepAlive ()
Protected Member Functions inherited from GNet::SocketBase
| SocketBase (Address::Family, int type, int protocol)
| Constructor used by derived classes. More...
| SocketBase (Address::Family, Descriptor s)
| Constructor used by derived classes. More...
| SocketBase (Address::Family, Descriptor s, const Accepted &)
| Constructor used by StreamSocket::accept() to create a socket object from a newly accept()ed socket handle. More...
| SocketBase (const Raw &, int domain, int type, int protocol)
| Constructor for a raw socket. More...
ssize_type | writeImp (const char *buf, size_type len)
| Writes to the socket. More...
void | clearReason ()
| Clears the saved errno. More...
void | saveReason ()
| Saves the current errno following error()/sizeError(). More...
void | saveReason () const
| Saves the current errno following error()/sizeError(). More...
bool | isFamily (Address::Family) const
| Returns true if the socket family is as given. More...
Static Protected Member Functions inherited from GNet::SocketBase
static bool | error (int rc)
| Returns true if the given return code indicates an error. More...
static bool | sizeError (ssize_type size)
| Returns true if the given write() return value indicates an error. More...

## Detailed Description

A derivation of GNet::Socket for a stream socket.

Definition at line 310 of file gsocket.h.

## Member Typedef Documentation

## ◆ size_type

using GNet::StreamSocket::size_type = Socket::size_type

Definition at line 313 of file gsocket.h.

## ◆ ssize_type

using GNet::StreamSocket::ssize_type = Socket::ssize_type

Definition at line 314 of file gsocket.h.

## Constructor & Destructor Documentation

## ◆ StreamSocket() [1/2]

GNet::StreamSocket::StreamSocket | ( | Address::Family | af | ) |
| explicit

Constructor.

Definition at line 452 of file gsocket.cpp.

## ◆ StreamSocket() [2/2]

GNet::StreamSocket::StreamSocket | ( | Address::Family | af,
|  | const Listener & |
| ) |  |

Constructor overload specifically for a listening socket, which might need slightly different socket options.

Definition at line 458 of file gsocket.cpp.

## Member Function Documentation

## ◆ accept()

GNet::AcceptPair GNet::StreamSocket::accept | ( |  | ) |

Accepts an incoming connection, returning a new()ed socket and the peer address.

Definition at line 489 of file gsocket.cpp.

## ◆ read()

GNet::Socket::ssize_type GNet::StreamSocket::read | ( | char * | buffer,
|  | size_type | buffer_length
| ) |  |
| override virtual

Override from ReadWrite::read().

Implements G::ReadWrite.

Definition at line 470 of file gsocket.cpp.

## ◆ supports()

bool GNet::StreamSocket::supports | ( | Address::Family | af | ) |
| static

Returns true if stream sockets can be created with the given the address family.

This is a one-off run-time check on socket creation, with a warning if it fails. Note that a run-time check is useful when running a new binary on an old operating system.

Definition at line 424 of file gsocket.cpp.

## ◆ write()

GNet::Socket::ssize_type GNet::StreamSocket::write | ( | const char * | buf,
|  | size_type | len
| ) |  |
| override virtual

Override from Socket::write().

Implements G::ReadWrite.

Definition at line 484 of file gsocket.cpp.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/gsocket.h
- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/gsocket.cpp