MPD: BufferedSocket Class Reference

MPD 0.20.15

Public Member Functions | Protected Types | Protected Member Functions
BufferedSocket Class Referenceabstract

A SocketMonitor specialization that adds an input buffer. More...

`#include <BufferedSocket.hxx>`

Inheritance diagram for BufferedSocket:
[legend]
Collaboration diagram for BufferedSocket:
[legend]

## Public Member Functions
| BufferedSocket (int _fd, EventLoop &_loop)
bool | IsDefined () const
void | Close ()
ssize_t | Write (const void *data, size_t length)

## Protected Types
enum | InputResult { InputResult::MORE, InputResult::PAUSE, InputResult::AGAIN, InputResult::CLOSED }
Protected Types inherited from SocketMonitor
typedef std::make_signed< size_t >::type | ssize_t

## Protected Member Functions
bool | ResumeInput ()
void | ConsumeInput (size_t nbytes)
| Mark a portion of the input buffer "consumed". More...
virtual InputResult | OnSocketInput (void *data, size_t length)=0
| Data has been received on the socket. More...
virtual void | OnSocketError (std::exception_ptr ep)=0
virtual void | OnSocketClosed ()=0
virtual bool | OnSocketReady (unsigned flags) override
| SocketMonitor (EventLoop &_loop)
| SocketMonitor (int _fd, EventLoop &_loop)
| ~SocketMonitor ()
EventLoop & | GetEventLoop ()
bool | IsDefined () const
int | Get () const
void | Open (int _fd)
int | Steal ()
| "Steal" the socket descriptor. More...
void | Abandon ()
| Somebody has closed the socket. More...
void | Close ()
unsigned | GetScheduledFlags () const
void | Schedule (unsigned flags)
void | Cancel ()
void | ScheduleRead ()
void | ScheduleWrite ()
void | CancelRead ()
void | CancelWrite ()
ssize_t | Read (void *data, size_t length)
ssize_t | Write (const void *data, size_t length)
void | Dispatch (unsigned flags)

## Additional Inherited Members
Static Protected Attributes inherited from SocketMonitor
static constexpr unsigned | READ = PollGroup::READ
static constexpr unsigned | WRITE = PollGroup::WRITE
static constexpr unsigned | ERROR = PollGroup::ERROR
static constexpr unsigned | HANGUP = PollGroup::HANGUP

## Detailed Description

A SocketMonitor specialization that adds an input buffer.

Definition at line 37 of file BufferedSocket.hxx.

## Member Enumeration Documentation

## ◆ InputResult

enum BufferedSocket::InputResult
| strongprotected

Enumerator
MORE | The method was successful, and it is ready to read more data.
PAUSE | The method does not want to get more data for now. It will call ResumeInput() when it's ready for more.
AGAIN | The method wants to be called again immediately, if there's more data in the buffer.
CLOSED | The method has closed the socket.

Definition at line 78 of file BufferedSocket.hxx.

## Constructor & Destructor Documentation

## ◆ BufferedSocket()

BufferedSocket::BufferedSocket | ( | int | _fd,
|  | EventLoop & | _loop
| ) |  |
| inline

Definition at line 41 of file BufferedSocket.hxx.

## Member Function Documentation

## ◆ Close()

void SocketMonitor::Close

## ◆ ConsumeInput()

void BufferedSocket::ConsumeInput | ( | size_t | nbytes | ) |
| inlineprotected

Mark a portion of the input buffer "consumed".

Only allowed to be called from OnSocketInput(). This method does not invalidate the pointer passed to OnSocketInput() yet.

Definition at line 72 of file BufferedSocket.hxx.

## ◆ IsDefined()

bool SocketMonitor::IsDefined
| inline

Definition at line 83 of file SocketMonitor.hxx.

## ◆ OnSocketClosed()

virtual void BufferedSocket::OnSocketClosed | ( |  | ) |
| protectedpure virtual

Implemented in HttpdClient.

## ◆ OnSocketError()

virtual void BufferedSocket::OnSocketError | ( | std::exception_ptr | ep | ) |
| protectedpure virtual

Implemented in HttpdClient.

## ◆ OnSocketInput()

virtual InputResult BufferedSocket::OnSocketInput | ( | void * | data,
|  | size_t | length
| ) |  |
| protectedpure virtual

Data has been received on the socket.

Parameters

  data | a pointer to the beginning of the buffer; the buffer may be modified by the method while it processes the data

Implemented in HttpdClient.

## ◆ OnSocketReady()

virtual bool BufferedSocket::OnSocketReady | ( | unsigned | flags | ) |
| overrideprotectedvirtual

Returns
  false if the socket has been closed

Implements SocketMonitor.

Reimplemented in HttpdClient, and FullyBufferedSocket.

## ◆ ResumeInput()

bool BufferedSocket::ResumeInput | ( |  | ) |
| protected

Returns
  false if the socket has been closed

## ◆ Write()

ssize_t SocketMonitor::Write

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

- event/BufferedSocket.hxx