Open Lighting Architecture  Latest Git
Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | List of all members
ola::io::ConnectedDescriptor Class Referenceabstract

Detailed Description

A BidirectionalFileDescriptor that also generates notifications when closed.

Inheritance diagram for ola::io::ConnectedDescriptor:
Inheritance graph
[legend]
Collaboration diagram for ola::io::ConnectedDescriptor:
Collaboration graph
[legend]

Public Types

typedef ola::SingleUseCallback0< void > OnCloseCallback
 

Public Member Functions

virtual ssize_t Send (const uint8_t *buffer, unsigned int size)
 Write a buffer to the descriptor. More...
 
virtual ssize_t Send (IOQueue *data)
 Write data from an IOQueue to a descriptor. More...
 
virtual int Receive (uint8_t *buffer, unsigned int size, unsigned int &data_read)
 Read data from this descriptor. More...
 
virtual bool SetReadNonBlocking ()
 Enable on non-blocking reads.. More...
 
virtual bool Close ()=0
 
int DataRemaining () const
 Find out how much data is left to read. More...
 
bool IsClosed () const
 Check if the descriptor is closed.
 
void SetOnClose (OnCloseCallback *on_close)
 Set the callback to be run when the descriptor is closed. More...
 
OnCloseCallbackTransferOnClose ()
 Take ownership of the on_close callback. More...
 
- Public Member Functions inherited from ola::io::BidirectionalFileDescriptor
void SetOnData (ola::Callback0< void > *on_read)
 Set the callback to be run when data is available for reading. More...
 
void SetOnWritable (ola::Callback0< void > *on_write)
 Set the callback to be run when the descriptor can be written to. More...
 
void PerformRead ()
 Called when there is data available on the descriptor. More...
 
void PerformWrite ()
 Called when the descriptor can be written to. More...
 
- Public Member Functions inherited from ola::io::ReadFileDescriptor
virtual DescriptorHandle ReadDescriptor () const =0
 Returns the read descriptor for this socket. More...
 
bool ValidReadDescriptor () const
 Check if this file descriptor is valid. More...
 
- Public Member Functions inherited from ola::io::WriteFileDescriptor
virtual DescriptorHandle WriteDescriptor () const =0
 Returns the write descriptor for this socket. More...
 
bool ValidWriteDescriptor () const
 Check if this file descriptor is valid. More...
 

Static Public Member Functions

static bool SetNonBlocking (DescriptorHandle fd)
 Set a DescriptorHandle to non-blocking mode.
 

Protected Member Functions

virtual bool IsSocket () const =0
 
bool SetNoSigPipe (DescriptorHandle fd)
 Disable SIGPIPE for this descriptor.
 

Member Function Documentation

◆ DataRemaining()

int ola::io::ConnectedDescriptor::DataRemaining ( ) const

Find out how much data is left to read.

Returns
the amount of unread data for the descriptor.

◆ Receive()

int ola::io::ConnectedDescriptor::Receive ( uint8_t *  buffer,
unsigned int  size,
unsigned int &  data_read 
)
virtual

Read data from this descriptor.

Parameters
buffera pointer to the buffer to store new data in
sizethe size of the buffer
data_reada value result argument which returns the size of the data copied into the buffer.
Returns
-1 on error, 0 on success.

◆ Send() [1/2]

ssize_t ola::io::ConnectedDescriptor::Send ( const uint8_t *  buffer,
unsigned int  size 
)
virtual

Write a buffer to the descriptor.

Parameters
buffera pointer to the buffer to write
sizethe number of bytes in the buffer to write
Returns
the number of bytes written

◆ Send() [2/2]

ssize_t ola::io::ConnectedDescriptor::Send ( IOQueue data)
virtual

Write data from an IOQueue to a descriptor.

Parameters
datathe IOQueue containing the data to write. Data written to the descriptor will be removed from the IOQueue.
Returns
the number of bytes written.

This attempts to send as much of the IOQueue data as possible. The IOQueue may be non-empty when this completes if the descriptor buffer is full.

Returns
the number of bytes sent.

◆ SetOnClose()

void ola::io::ConnectedDescriptor::SetOnClose ( OnCloseCallback on_close)
inline

Set the callback to be run when the descriptor is closed.

Parameters
on_closethe callback to run, ownership of the callback is transferred.

◆ SetReadNonBlocking()

virtual bool ola::io::ConnectedDescriptor::SetReadNonBlocking ( )
inlinevirtual

Enable on non-blocking reads..

Returns
true if it worked, false otherwise.

On Windows, this is only supported for sockets.

◆ TransferOnClose()

OnCloseCallback* ola::io::ConnectedDescriptor::TransferOnClose ( )
inline

Take ownership of the on_close callback.

This method transfers ownership of the on_close callback from the socket to the caller. Often an on_close callback ends up deleting the socket that its bound to. This can cause problems because we run the destructor from within the Close() method of the same object. To avoid this when we want to call the on close handler we transfer ownership away from the socket


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