SYNOPSIS

#include <fd.hh>

Inherits shevek::refbase.

Inherited by shevek::file, and shevek::socket.

Public Types

typedef sigc::slot0< void > read_custom_t

Function pointer to call when data is read from fd. typedef sigc::slot1< bool,

std::string & > read_t"

Function pointer to call when fd is ready for reading. typedef sigc::slot1< void,

std::string const & > read_lines_t"

Function pointer to call when a complete line has arrived. typedef sigc::slot0< void > error_t

Function pointer to call when an error occurs. typedef sigc::slot0< void > write_done_t

Function pointer to call when data has been written. typedef sigc::slot1< void,

std::string & > filter_t"

Function pointer to filter in and outgoing data. typedef sigc::slot0< void > flush_t

Function pointer to signal that all data is flushed after unread ()

Public Member Functions

void read_custom (read_custom_t cb)

Poll for read with a custom callback to poll. void read_priority_custom (read_custom_t cb)

Poll for priority read with a custom callback to poll. void read (read_t cb)

Poll for read and set read callback (resets custom callback) void read_priority (read_t cb)

Poll for priority read and set read callback (resets custom callback) void read_lines (read_lines_t cb)

Poll for read and set read lines callback (resets custom and read callback). Polls for priority read as well. void unread (bool flush_buffer=false, flush_t cb=flush_t())

Stop polling for read (including priority read). void write (std::string const &data, write_done_t cb=write_done_t())

Write data and set a callback (defaults to none). void write_raw (std::string const &data, write_done_t cb=write_done_t())

Write data, ignoring the filter, and set a callback (defaults to none). bool write_block (relative_time timeout=relative_time(-1, 0))

Block until write buffer is empty. std::string & read_block (relative_time timeout=relative_time(-1, 0))

Block until data is read, try writing if there is a write buffer. std::string read_line_block (relative_time timeout=relative_time(-1, 0))

Call read_block until a line has been read, or the timeout expires. void set_fd (int fd)

Change file descriptor. void in_filter (filter_t cb)

If set, incoming data is filtered through this callback before it is put into the buffer. void out_filter (filter_t cb)

If set, outgoing data is filtered through this callback before it is sent to the file descriptor. void set_error (error_t cb)

Set a callback for all error types at once. void set_poll_error (error_t cb)

Callback for errors from poll. void set_read_error (error_t cb)

Callback for errors from read. void set_write_error (error_t cb)

Callback for errors from write. void set_eof (error_t cb)

Callback for end of file. void read_reset ()

Stop reading, delete the buffer. void write_reset ()

Stop writing, delete the buffer. void reset ()

Stop reading and writing, delete the buffers. int get_fd () const

Get the fd. This function should mostly be used by derived classes. Glib::RefPtr< Glib::MainContext > get_main_context ()

Get the main context. Also mostly used by derived classes.

Static Public Member Functions

static Glib::RefPtr< fd > create (int value=-1, Glib::RefPtr< Glib::MainContext > main=Glib::MainContext::get_default())

Create a new fd.

Protected Member Functions

fd (int value, Glib::RefPtr< Glib::MainContext > main)

Constructor. ~fd ()

Destructor.

Detailed Description

The fd class is a generic wrapper for a file descriptor to use it in the Glib event loop.

Member Function Documentation

void shevek::fd::read (\fBread_t\fPcb)

Poll for read and set read callback (resets custom callback) If no callback is set for priority read, this callback is used for that as well.

std::string& shevek::fd::read_block (\fBrelative_time\fPtimeout = \fC\fBrelative_time\fP(-1, 0)\fP)

Block until data is read, try writing if there is a write buffer. Return read data as reference to buffer. (callback is not called) Returns immediately if buffer is not empty. Priority read buffer and normal read buffer are both checked. This will block at most until the timeout is reached, if it is positive.

void shevek::fd::read_custom (\fBread_custom_t\fPcb)

Poll for read with a custom callback to poll. If no callback is set for priority read, this callback is used for that as well.

void shevek::fd::set_error (\fBerror_t\fPcb)

Set a callback for all error types at once. This is used for any error for which no other callback is set.

bool shevek::fd::write_block (\fBrelative_time\fPtimeout = \fC\fBrelative_time\fP(-1, 0)\fP)

Block until write buffer is empty. This will block at most until the timeout is reached, if it is positive.

Author

Generated automatically by Doxygen for libshevek from the source code.