---
name: "io_push"
section: "3"
platform: "linux"
package: "libnessus-dev"
version: "1.0.10-2"
release: "Debian 3.0 (Woody)"
platforms: ["linux"]
url: "https://new.carta.tech/io_push"
---

# io\_push(3)

create a socket io replacement layer

## NAME

io\_push, io\_pop, io\_enable, io\_suspend - create a socket io replacement layer

## SYNOPSIS

```
#include <peks.h>

void *io_push (unsigned fd, unsigned context_size,
               int (*rdwr_fn)
                     (void *context,
                      char *data, unsigned len, int flags),
               int (*ioctl_fn)
                     (void *context,
                      io_ctrl_request request, int *arg),
               void (*destroy_fn) (void *context),
               unsigned how);

void io_pop (unsigned fd, unsigned how);

void io_enable (unsigned fd, unsigned how);

void io_suspend (unsigned fd, unsigned how);
```

## DESCRIPTION

**Io\_push()** creates a new io data stream diversion for the open file descriptor fd according to the argument **how**:

- 0 divert incoming data stream (like stdin)

  1 divert outgoing data stream (like stdout).

The function creates a data area of size contextsize and zero initialises it.  If also registeres the call back functions, given as argument.  When this is done, a pointer of the data area allocated is returned, or NULL if an error occurs while the variable errno is set,  accordingly.

If there has been a layer pushed on the current io data stream, already it is replaced unless the flag **IO\_PUSH\_EXCLUSIVELY** is xored with the argument how.  In the latter case, an error is detected.

**Io\_pop()** removes the diversion from the io data stream and calls

- **(\****destroy\_fn***)(***desc***)**

  where **desc = desc (fd, how)** is the data area also pointed to by the return code of **io\_push()**.  Finally, **io\_pop()** frees **desc**.

**Io\_suspend()** disables a diversion from the io data stream in which case it behaves as if the diversion had been io\_pop ()-ed.

**Io\_enable()** undoes the effect of **io\_suspend()**.  By default, **io\_enable()** is automatically activated by **io\_push()**.

It is save calling the functions **io\_pop()**, **io\_enable()** and **io\_suspend()** without having installed a data stream diversion using **io\_push()**.

## CAVEAT

The data area returned by **io\_push()** must never be deallocated  using **free()**.  It should be initialized immediately after returned  successfully by **io\_push()**.

## SEE ALSO

[**iostream**(3)](/iostream/3.md), [**io\_ctrl**(3)](/io_ctrl/3.md),  [**io\_send**(3)](/io_send/3.md),

## AUTHOR

The **peks** package where these functions belong to was written by Jordan Hrycaj \<jordan@teddy-net.com\>, originally to support the **nessus** security scanner.
