iv\_fd\_pump(3) ivykis programmer's manual iv\_fd\_pump(3)

# [NAME](#NAME)

IV\_FD\_PUMP\_INIT, iv\_fd\_pump\_init, iv\_fd\_pump\_destroy, iv\_fd\_pump\_pump, iv\_fd\_pump\_is\_done - pump data between file descriptors

# [SYNOPSIS](#SYNOPSIS)

**#include &lt;iv\_fd\_pump.h&gt;**

```
struct iv_fd_pump {


        int             from_fd;


        int             to_fd;


        void            *cookie;


        void            (*set_bands)(void *cookie, int pollin, int pollout);


        unsigned int    flags;
};
```

**void IV\_FD\_PUMP\_INIT(struct iv\_fd\_pump \*this);**  
**void iv\_fd\_pump\_init(struct iv\_fd\_pump \*this);**  
**void iv\_fd\_pump\_destroy(struct iv\_fd\_pump \*this);**  
**int iv\_fd\_pump\_pump(struct iv\_fd\_pump \*this);**  
**int iv\_fd\_pump\_is\_done(const struct iv\_fd\_pump \*this);**

# [DESCRIPTION](#DESCRIPTION)

**iv\_fd\_pump** provides a way for moving data between two file descriptors.

To set up **iv\_fd\_pump** for moving data, call **IV\_FD\_PUMP\_INIT** on a **struct iv\_fd\_pump** object, fill in the **-&gt;from\_fd, -&gt;to\_fd, -&gt;cookie, -&gt;set\_bands** and **-&gt;flags** members, and then call **iv\_fd\_pump\_init** on the object.

Conversely, to destroy a **struct iv\_fd\_pump** object, call **iv\_fd\_pump\_destroy.** There are no restrictions on when this function can be called.

A call to **iv\_fd\_pump\_pump** will attempt to move data from **-&gt;from\_fd** to **-&gt;to\_fd** via an internal buffer associated with the **struct iv\_fd\_pump** object.

During calls to **iv\_fd\_pump\_init,** **iv\_fd\_pump\_destroy** and **iv\_fd\_pump\_pump,** the callback function specified by **-&gt;set\_bands** may be invoked (with **-&gt;cookie** as its first argument), by which **iv\_fd\_pump** indicates under which circumstances it wishes for future invocations of **iv\_fd\_pump\_pump** to be done.

If the **pollin** argument to **-&gt;set\_bands** is true, there is space left in the internal buffer (and we have not yet seen an end-of-file condition on input), and so you should call **iv\_fd\_pump\_pump** again when there is a POLLIN condition on **-&gt;from\_fd.**

If the **pollout** argument to **-&gt;set\_bands** is true, there is data in the internal buffer that could not all be transferred to **-&gt;to\_fd,** and so you should call **iv\_fd\_pump\_pump** again when there is a POLLOUT condition on **-&gt;to\_fd.**

If **IV\_FD\_PUMP\_FLAG\_RELAY\_EOF** is set in **-&gt;flags,** **iv\_fd\_pump\_pump** will call [**shutdown**(2)](/man/os/ivykis/shutdown.2) on **-&gt;to\_fd** with **SHUT\_WR** as its second argument upon seeing an end-of-file condition on **-&gt;from\_fd** (but only after all data from the internal buffer has been drained into **-&gt;to\_fd** first).

**iv\_fd\_pump\_pump** will return -1 if there was an error, 0 if we're done pumping data (meaning that an end-of-file condition was seen on the input file descriptor and that all data in the internal buffer has been drained into the output file descriptor), or 1 if there is more data left to be pumped.

**iv\_fd\_pump\_is\_done** will return a true value if iv\_fd\_pump\_pump has previously returned 0, otherwise it will return false.

Internally, **iv\_fd\_pump\_pump** will use [**splice**(2)](/man/os/ivykis/splice.2) if it is available, otherwise it will fall back to [**read**(2)](/man/os/ivykis/read.2) and [**write**(2)](/man/os/ivykis/write.2).

# [SEE ALSO](#SEE_ALSO)

[**ivykis**(3)](/man/os/ivykis/ivykis.3), [**splice**(2)](/man/os/ivykis/splice.2)

2012-06-05 ivykis

---

Document: iv_fd_pump_init(3) from ivykis 0.43.2-r10 (Chainguard OS)
Source: https://github.com/buytenh/ivykis
