---
name: "shevek_fd"
section: "3"
platform: "linux"
package: "libshevek-doc"
version: "1.4-1"
release: "Debian 8 (Jessie)"
platforms: ["linux"]
url: "https://new.carta.tech/shevek_fd"
---

# shevek\_fd(3)

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

## NAME

shevek::fd -

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

## 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 (read\_tcb)

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 (relative\_timetimeout = relative\_time`(-1, 0)`)

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 (read\_custom\_tcb)

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 (error\_tcb)

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 (relative\_timetimeout = relative\_time`(-1, 0)`)

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.
