E-MailRelay

Public Types | Public Member Functions | List of all members
G::ReadWrite Class Referenceabstract

An abstract interface for reading and writing from a non-blocking i/o channel. More...

`#include <greadwrite.h>`

Inheritance diagram for G::ReadWrite:

## Public Types
using | size_type = std::size_t
using | ssize_type = ssize_t

## Public Member Functions
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.

## Detailed Description

An abstract interface for reading and writing from a non-blocking i/o channel.

Eg:

ssize_t rc = s.read( buffer , buffer.size() ) ;
if( rc == 0 ) throw Disconnected() ;
else if( rc < 0 && !s.eWouldBlock() ) throw ReadError() ;
else if( rc > 0 ) got_some( buffer , rc ) ;
else /*nothing-to-do*/ ;
ssize_t rc = s.write( buffer , buffer.size() )
if( rc < 0 && !s.eWouldBlock() ) throw Disconnected() ;
else if( rc < 0 || rc < buffer.size() ) sent_some( rc < 0 ? 0 : rc ) ;
else sent_all() ;

Definition at line 49 of file greadwrite.h.

## Member Typedef Documentation

## ◆ size_type

using G::ReadWrite::size_type = std::size_t

Definition at line 52 of file greadwrite.h.

## ◆ ssize_type

using G::ReadWrite::ssize_type = ssize_t

Definition at line 53 of file greadwrite.h.

## Member Function Documentation

## ◆ eWouldBlock()

virtual bool G::ReadWrite::eWouldBlock | ( |  | ) | const
| pure virtual

See read() and write().

Implemented in GNet::SocketBase.

## ◆ fd()

virtual SOCKET G::ReadWrite::fd | ( |  | ) | const
| pure virtual noexcept

Returns the file descriptor.

Implemented in GNet::SocketBase.

## ◆ read()

virtual ssize_type G::ReadWrite::read | ( | char * | buffer,
|  | size_type | buffer_length
| ) |  |
| pure virtual

Reads data.

Returns 0 if the connection has been lost. Returns -1 on error or if there is nothing to read (in which case eWouldBlock() returns true).

Implemented in GNet::StreamSocket, GNet::RawSocket, and GNet::DatagramSocket.

## ◆ write()

virtual ssize_type G::ReadWrite::write | ( | const char * | buf,
|  | size_type | len
| ) |  |
| pure virtual

Sends data.

Returns the amount of data sent.

If this method returns -1 then use eWouldBlock() to determine whether there was a flow control problem; if it returns -1 and eWouldBlock() returns false then the connection is lost. If it returns less than the requested length then eWouldBlock() should not be used.

Implemented in GNet::StreamSocket, GNet::RawSocket, and GNet::DatagramSocket.

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

- /usr/src/slapt-src-x86_64/network/emailrelay/emailrelay-2.3/src/glib/greadwrite.h