21 #include <sigc++/sigc++.h>
36 typedef sigc::slot1 <bool, std::string &>
read_t;
44 typedef sigc::slot1 <void, std::string &>
filter_t;
58 void read (read_t cb);
64 void unread (
bool flush_buffer =
false, flush_t cb = flush_t () );
66 void write (std::string
const &data, write_done_t cb = write_done_t () );
68 void write_raw (std::string
const &data, write_done_t cb = write_done_t () );
90 static Glib::RefPtr <fd>
91 create (
int value = -1, Glib::RefPtr <Glib::MainContext> main
92 = Glib::MainContext::get_default () );
117 fd (
int value, Glib::RefPtr <Glib::MainContext> main);
123 fd &operator= (
fd const &that);
126 bool l_check (Glib::IOCondition result);
130 void l_read (
bool force_fill);
131 void l_read_priority (
bool force_fill);
134 bool l_idle_priority ();
138 void l_connect (Glib::IOCondition
139 io = Glib::IO_HUP | Glib::IO_ERR | Glib::IO_NVAL);
141 bool l_read_lines (std::string &data);
151 std::list <write_t> m_writebuffer;
153 std::string m_readbuffer;
154 std::string m_priority_readbuffer;
157 read_t m_read_priority;
159 read_lines_t m_read_lines;
161 read_custom_t m_read_custom;
162 read_custom_t m_read_priority_custom;
169 filter_t m_in_filter, m_out_filter;
171 sigc::connection m_handle, m_idle, m_idle_priority;
173 error_t m_error, m_poll_error, m_rerror, m_werror, m_eof;
175 Glib::RefPtr <Glib::MainContext> m_main;
177 Glib::IOCondition m_iocondition;
179 Glib::RefPtr <fd> m_keepalive_helper;
180 Glib::RefPtr <fd> m_keepalive_helper_idle;
181 Glib::RefPtr <fd> m_keepalive_helper_idle_priority;
185 static std::string s_junkbuffer;
void set_poll_error(error_t cb)
Callback for errors from poll.
sigc::slot0< void > write_done_t
Function pointer to call when data has been written.
Definition: fd.hh:42
Base class for classes which want reference counting through Glib::RefPtr.
Definition: refbase.hh:27
sigc::slot1< bool, std::string & > read_t
Function pointer to call when fd is ready for reading.
Definition: fd.hh:36
void read_custom(read_custom_t cb)
Poll for read with a custom callback to poll.
sigc::slot1< void, std::string const & > read_lines_t
Function pointer to call when a complete line has arrived.
Definition: fd.hh:38
Time interval.
Definition: time.hh:143
fd(int value, Glib::RefPtr< Glib::MainContext > main)
Constructor.
void unread(bool flush_buffer=false, flush_t cb=flush_t())
Stop polling for read (including priority read).
void set_fd(int fd)
Change file descriptor.
int get_fd() const
Get the fd. This function should mostly be used by derived classes.
sigc::slot0< void > flush_t
Function pointer to signal that all data is flushed after unread ()
Definition: fd.hh:46
void write(std::string const &data, write_done_t cb=write_done_t())
Write data and set a callback (defaults to none).
sigc::slot0< void > read_custom_t
Function pointer to call when data is read from fd.
Definition: fd.hh:34
void in_filter(filter_t cb)
If set, incoming data is filtered through this callback before it is put into the buffer...
void read_lines(read_lines_t cb)
Poll for read and set read lines callback (resets custom and read callback). Polls for priority read ...
static Glib::RefPtr< fd > create(int value=-1, Glib::RefPtr< Glib::MainContext > main=Glib::MainContext::get_default())
Create a new fd.
sigc::slot1< void, std::string & > filter_t
Function pointer to filter in and outgoing data.
Definition: fd.hh:44
sigc::slot0< void > error_t
Function pointer to call when an error occurs.
Definition: fd.hh:40
void read_reset()
Stop reading, delete 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...
The fd class is a generic wrapper for a file descriptor to use it in the Glib event loop...
Definition: fd.hh:29
void reset()
Stop reading and writing, delete the buffers.
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 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).
void set_write_error(error_t cb)
Callback for errors from write.
void set_read_error(error_t cb)
Callback for errors from read.
void read_priority(read_t cb)
Poll for priority read and set read callback (resets custom callback)
Glib::RefPtr< Glib::MainContext > get_main_context()
Get the main context. Also mostly used by derived classes.
void set_eof(error_t cb)
Callback for end of file.
void write_reset()
Stop writing, delete the buffer.
void set_error(error_t cb)
Set a callback for all error types at once.
std::string & read_block(relative_time timeout=relative_time(-1, 0))
Block until data is read, try writing if there is a write buffer.
bool write_block(relative_time timeout=relative_time(-1, 0))
Block until write buffer is empty.
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.