Detailed Description
A BidirectionalFileDescriptor that also generates notifications when closed.
Public Member Functions |
virtual ssize_t | Send (const uint8_t *buffer, unsigned int size) |
| Write a buffer to the descriptor.
|
virtual ssize_t | Send (IOQueue *data) |
| Write data from an IOQueue to a descriptor.
|
virtual int | Receive (uint8_t *buffer, unsigned int size, unsigned int &data_read) |
| Read data from this descriptor.
|
virtual bool | SetReadNonBlocking () |
| Enable on non-blocking reads..
|
virtual bool | Close ()=0 |
int | DataRemaining () const |
| Find out how much data is left to read.
|
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.
|
OnCloseCallback * | TransferOnClose () |
| Take ownership of the on_close callback.
|
void | SetOnData (ola::Callback0< void > *on_read) |
| Set the callback to be run when data is available for reading.
|
void | SetOnWritable (ola::Callback0< void > *on_write) |
| Set the callback to be run when the descriptor can be written to.
|
void | PerformRead () |
| Called when there is data available on the descriptor.
|
void | PerformWrite () |
| Called when the descriptor can be written to.
|
virtual DescriptorHandle | ReadDescriptor () const =0 |
| Returns the read descriptor for this socket.
|
bool | ValidReadDescriptor () const |
| Check if this file descriptor is valid.
|
virtual DescriptorHandle | WriteDescriptor () const =0 |
| Returns the write descriptor for this socket.
|
bool | ValidWriteDescriptor () const |
| Check if this file descriptor is valid.
|
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
int ola::io::ConnectedDescriptor::DataRemaining |
( |
| ) |
const |
Find out how much data is left to read.
- Returns
- the amount of unread data for the descriptor.
int ola::io::ConnectedDescriptor::Receive |
( |
uint8_t * |
buffer, |
|
|
unsigned int |
size, |
|
|
unsigned int & |
data_read |
|
) |
| |
|
virtual |
Read data from this descriptor.
- Parameters
-
buffer | a pointer to the buffer to store new data in |
size | the size of the buffer |
data_read | a value result argument which returns the size of the data copied into the buffer. |
- Returns
- -1 on error, 0 on success.
ssize_t ola::io::ConnectedDescriptor::Send |
( |
const uint8_t * |
buffer, |
|
|
unsigned int |
size |
|
) |
| |
|
virtual |
Write a buffer to the descriptor.
- Parameters
-
buffer | a pointer to the buffer to write |
size | the number of bytes in the buffer to write |
- Returns
- the number of bytes written
ssize_t ola::io::ConnectedDescriptor::Send |
( |
IOQueue * |
data | ) |
|
|
virtual |
Write data from an IOQueue to a descriptor.
- Parameters
-
data | the 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.
void ola::io::ConnectedDescriptor::SetOnClose |
( |
OnCloseCallback * |
on_close | ) |
|
|
inline |
Set the callback to be run when the descriptor is closed.
- Parameters
-
on_close | the callback to run, ownership of the callback is transferred. |
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.
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: