NAME
io_send, io_recv, io_shutdown, io_close - replacement for socket fuctions
SYNOPSIS
#include <peks.h>
int io_send (unsigned fd,
const char *data, unsigned len, unsigned flags);
int io_recv (unsigned fd,
char *buffer, unsigned len, unsigned flags);
int io_recv_tmo (unsigned fd, int timeout);
int io_shutdown (unsigned fd, unsigned how);
int io_close (unsigned fd);
int io_recv_timeout;
DESCRIPTION
These functions are replacements for the standard socket functions send(2), recv(2), shutdown(2) and close(2) unless a data stream diversion has been installed by the function io_push().
Instead of passing arguments and return codes to and from the socket functions send(), or recv() the following internal replacements take place:
for the outgoing data stream
send (fd,buf,len,flg) ::=
(*rdwr_fn) (desc,buf,len,flg)
and for the incoming data stream
recv (fd,buf,len,flg) ::=
(*rdwr_fn) (desc,buf,len,flg)
where the symbol desc = desc (fd, how) is a pointer to the data area also returned by io_push().
The functions io_shutdown() and io_close() work as shutdown() and close() with an additional call of io_pop().
The function io_recv_tmo() imposes a timeout on the receiver recv() of the input data stream associated with the first argument. So the io_recv() call will be thrown out of a blocking wait for input data. In that case, the global variable errno will be set to the value EINTR. In some cases, this is somewhat misleading as--implementation dependent--the timeout also may occur from a timeout detected after a call for select() or for poll().
Passing some positive second argument n, a signal SIGALRM will be sent to io_recv() after n seconds idle time. Passing some negative value, the system waits at most -n seconds before data are available, but will not interrupt a pending recv() operation. Passing a 0 value, the timeout is disabled.
Upon return, the function returns the old timer value, or -1 if there was no input data associated with the first argument. As a consequence, when receiving a value -1, you can only detect an error by asking io_recv_tmo() again (provided the first timeout arguent was different from -1.)
By setting the global variable io_recv_timeout, the default timeout (as changed with io_recv_tmo()) that controls the receiver recv() in io_recv() is set, default is 20 seconds.
It is save calling the functions io_send(), io_recv(), io_close(), and io_shutdown() without having installed a data stream diversion using io_push().
SEE ALSO
errno(3), iostream(3), io_push(3), send(2), recv(2), socket(2), shutdown(2), close(2), signal(5),
AUTHOR
The peks package where these functions belong to was written by Jordan Hrycaj <[email protected]>, originally to support the nessus security scanner.