E-MailRelay

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

A socket base class that holds a non-blocking socket file descriptor and interfaces to the event loop. More...

`#include <gsocket.h>`

Inheritance diagram for GNet::SocketBase:

## Classes
struct | Accepted
| Overload discriminator class for GNet::SocketBase. More...
struct | Raw
| Overload discriminator class for GNet::SocketBase. More...

## Public Types
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
| ~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, int type, int protocol)
| Returns true if sockets can be created with the given parameters. More...

## Protected Member Functions
| 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
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 socket base class that holds a non-blocking socket file descriptor and interfaces to the event loop.

Definition at line 51 of file gsocket.h.

## Member Typedef Documentation

## ◆ size_type

using GNet::SocketBase::size_type = G::ReadWrite::size_type

Definition at line 58 of file gsocket.h.

## ◆ ssize_type

using GNet::SocketBase::ssize_type = G::ReadWrite::ssize_type

Definition at line 59 of file gsocket.h.

## Constructor & Destructor Documentation

## ◆ ~SocketBase()

GNet::SocketBase::~SocketBase | ( |  | ) |
| override

Destructor.

The socket file descriptor is closed and removed from the event loop.

Definition at line 123 of file gsocket.cpp.

## ◆ SocketBase() [1/4]

GNet::SocketBase::SocketBase | ( | Address::Family | family,
|  | int | type,
|  | int | protocol
| ) |  |
| protected

Constructor used by derived classes.

Creates the socket using socket() and makes it non-blocking.

Definition at line 57 of file gsocket.cpp.

## ◆ SocketBase() [2/4]

GNet::SocketBase::SocketBase | ( | Address::Family | family,
|  | Descriptor | s
| ) |  |
| protected

Constructor used by derived classes.

Creates the socket object from a newly-created socket handle and makes it non-blocking.

Definition at line 93 of file gsocket.cpp.

## ◆ SocketBase() [3/4]

GNet::SocketBase::SocketBase | ( | Address::Family | family,
|  | Descriptor | s,
|  | const Accepted & |
| ) |  |
| protected

Constructor used by StreamSocket::accept() to create a socket object from a newly accept()ed socket handle.

Definition at line 108 of file gsocket.cpp.

## ◆ SocketBase() [4/4]

GNet::SocketBase::SocketBase | ( | const Raw & | ,
|  | int | domain,
|  | int | type,
|  | int | protocol
| ) |  |
| protected

Constructor for a raw socket.

Definition at line 74 of file gsocket.cpp.

## Member Function Documentation

## ◆ addOtherHandler()

void GNet::SocketBase::addOtherHandler | ( | EventHandler & | handler,
|  | ExceptionSink | es
| ) |  |

Adds this socket to the event source list so that the given handler receives exception events.

A TCP exception event should be treated as a disconnection event. (Not used for datagram sockets.)

Definition at line 186 of file gsocket.cpp.

## ◆ addReadHandler()

void GNet::SocketBase::addReadHandler | ( | EventHandler & | handler,
|  | ExceptionSink | es
| ) |  |

Adds this socket to the event source list so that the given handler receives read events.

Definition at line 172 of file gsocket.cpp.

## ◆ addWriteHandler()

void GNet::SocketBase::addWriteHandler | ( | EventHandler & | handler,
|  | ExceptionSink | es
| ) |  |

Adds this socket to the event source list so that the given handler receives write events when flow control is released.

(Not used for datagram sockets.)

Definition at line 179 of file gsocket.cpp.

## ◆ asString()

std::string GNet::SocketBase::asString | ( |  | ) | const

Returns the socket handle as a string.

Only used in debugging.

Definition at line 222 of file gsocket.cpp.

## ◆ clearReason()

void GNet::SocketBase::clearReason | ( |  | ) |
| protected

Clears the saved errno.

Definition at line 143 of file gsocket.cpp.

## ◆ dropOtherHandler()

void GNet::SocketBase::dropOtherHandler | ( |  | ) |
| noexcept

Reverses addOtherHandler().

Definition at line 205 of file gsocket.cpp.

## ◆ dropReadHandler()

void GNet::SocketBase::dropReadHandler | ( |  | ) |
| noexcept

Reverses addReadHandler().

Definition at line 193 of file gsocket.cpp.

## ◆ dropWriteHandler()

void GNet::SocketBase::dropWriteHandler | ( |  | ) |
| noexcept

Reverses addWriteHandler().

Definition at line 199 of file gsocket.cpp.

## ◆ eInProgress()

bool GNet::SocketBase::eInProgress | ( |  | ) | const

Returns true if the previous socket operation failed with the EINPROGRESS error status.

When connecting this can be considered a non-error.

Definition at line 130 of file gsocket_unix.cpp.

## ◆ eMsgSize()

bool GNet::SocketBase::eMsgSize | ( |  | ) | const

Returns true if the previous socket operation failed with the EMSGSIZE error status.

When writing to a datagram socket this indicates that the message was too big to send atomically.

Definition at line 135 of file gsocket_unix.cpp.

## ◆ eNotConn()

bool GNet::SocketBase::eNotConn | ( |  | ) | const

Returns true if the previous socket operation failed with the ENOTCONN error status, or similar.

Definition at line 120 of file gsocket_unix.cpp.

## ◆ error()

bool GNet::SocketBase::error | ( | int | rc | ) |
| static protected

Returns true if the given return code indicates an error.

Definition at line 95 of file gsocket_unix.cpp.

## ◆ eTooMany()

bool GNet::SocketBase::eTooMany | ( |  | ) | const

Returns true if the previous socket operation failed with the EMFILE error status, or similar.

Definition at line 140 of file gsocket_unix.cpp.

## ◆ eWouldBlock()

bool GNet::SocketBase::eWouldBlock | ( |  | ) | const
| override virtual

Returns true if the previous socket operation failed because the socket would have blocked.

Implements G::ReadWrite.

Definition at line 125 of file gsocket_unix.cpp.

## ◆ fd()

SOCKET GNet::SocketBase::fd | ( |  | ) | const
| override virtual noexcept

Returns the socket file descriptor.

Implements G::ReadWrite.

Definition at line 211 of file gsocket.cpp.

## ◆ isFamily()

bool GNet::SocketBase::isFamily | ( | Address::Family | family | ) | const
| protected

Returns true if the socket family is as given.

Definition at line 129 of file gsocket.cpp.

## ◆ reason()

std::string GNet::SocketBase::reason | ( |  | ) | const

Returns the reason for the previous error.

Definition at line 216 of file gsocket.cpp.

## ◆ saveReason() [1/2]

void GNet::SocketBase::saveReason | ( |  | ) |
| protected

Saves the current errno following error()/sizeError().

Definition at line 100 of file gsocket_unix.cpp.

## ◆ saveReason() [2/2]

void GNet::SocketBase::saveReason | ( |  | ) | const
| protected

Saves the current errno following error()/sizeError().

Definition at line 148 of file gsocket.cpp.

## ◆ sizeError()

bool GNet::SocketBase::sizeError | ( | ssize_type | size | ) |
| static protected

Returns true if the given write() return value indicates an error.

Definition at line 115 of file gsocket_unix.cpp.

## ◆ supports()

bool GNet::SocketBase::supports | ( | Address::Family | af,
|  | int | type,
|  | int | protocol
| ) |  |
| static

Returns true if sockets can be created with the given parameters.

Definition at line 34 of file gsocket_unix.cpp.

## ◆ writeImp()

GNet::SocketBase::ssize_type GNet::SocketBase::writeImp | ( | const char * | buf,
|  | size_type | len
| ) |  |
| protected

Writes to the socket.

This is a default implementation for write() that can be called from derived classes' overrides.

Definition at line 153 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
- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/gnet/gsocket_unix.cpp