ADDIOPROC(3A) ADDIOPROC(3A)
NAME
#include <fcntl.h>
AddIoProc, RemoveIoProc - Add and remove an asynchronous I/O
procedure
SYNOPSIS
AddIoProc (fd, buf, size, func, errfunc, mode, line, arg)
int fd;
char *buf;
int size;
int (*func)();
int (*errfunc)();
int mode;
int line;
int arg;
RemoveIoProc (fd)
int fd;
DESCRIPTION
AddIoProc registers I/O procedures for doing asynchronous
I/O on the file descriptor fd . I/O to or from this file
will be done in the buffer buf , which can hold up to size
bytes. Normally, func will be called to indicate data
transfer. However, if there is an error, errfunc will be
called instead. They may, however, be the same function.
The mode is either O_RDONLY or O_WRONLY for read or write
mode. In read mode, the boolean line is non-zero for
reading line-by-line, otherwise func will be called only
when the buffer is full, or there has been some exception on
the file. The boolean line flag is ignored for writing.
When either func or errfunc is called, arg is passed to the
function
The calling sequence for both func and errfunc is as
follows:
int func (arg, fd, buf, len, error)
Page 1 (printed 9/3/91)
ADDIOPROC(3A) ADDIOPROC(3A)
int arg;
int fd;
char **pbuf;
int len;
int error;
Arg and fd are the same as those passed originally to
AddIoProc . The buffer is pointed to by the pointer pbuf is
a pointer to the buffer pointer, and len is the number of
bytes actually transferred. If len is -1, an error
occurred, and error will contain the system error number.
The size of the buffer pointer to by pbuf is returned by
func. In read mode, func may return 0 to indicate that the
remainder of the file should be ignored. In either read or
write mode, func may return -1 to indicate that the file
descriptor has been closed and the io procedure removed by
RemoveIoProc.
When errfunc is called, len is always -1. When func is
called, len is always greater than or Thus, if func and
errfunc are the same function, the value of len can be used
to determine which occured. If len is not -1, the value of
error is not meaningful and should be ignored.
The I/O handling routine is able to fully manage the
buffering of the data through the pointer pbuf and the
return value. In read mode, the current data buffer can be
saved and a different (perhaps dynamically allocated) buffer
returned for subsequent data, even a different sized one.
In write mode, another buffer with data already prepared may
be presented for the subsequent write operation.
RemoveIoProc removes the I/O procedure associated with the
file descriptor fd. The file should have been already
closed.
NOTES
The Atari Application Library has higher level routines for
handling common I/O cases, such as ReadFileData (3A). There
are also outines for doing pipe I/O, such as OpenReadPipe
Page 2 (printed 9/3/91)
ADDIOPROC(3A) ADDIOPROC(3A)
(3A).
SEE ALSO
XtAddInputProc(3Xt), OpenReadPipe(3A), OpenWritePipe(3A),
OpenFilter(3A), OpenFilter(3A), ReadFileData(3A),
ReadFileLines(3A), ReadFileStrings(3A), ReadPipeData(3A),
ReadPipeLines(3A), ReadPipeStrings(3A)
Page 3 (printed 9/3/91)