io_fdopen, io_fclose, io_fgetc, io_fgets, io_ungetc, io_fread, io_fputc, io_fputs, io_fprintf, io_fwrite, io_fflush, io_fileno, io_popen, io_pclose, io_copy, io_setbufmode, io_get_inbufcount, io_get_outbufcount - A buffered I/O library |
#include <pthr_iolib.h> io_handle io_fdopen (pseudothread pth, int sock); void io_fclose (io_handle); int io_fgetc (io_handle); char *io_fgets (char *s, int max_size, io_handle, int store_eol); int io_ungetc (int c, io_handle); size_t io_fread (void *ptr, size_t size, size_t nmemb, io_handle); int io_fputc (int c, io_handle); int io_fputs (const char *s, io_handle); int io_fprintf (io_handle, const char *fs, ...) __attribute__ ((format (printf, 2, 3))); size_t io_fwrite (const void *ptr, size_t size, size_t nmemb, io_handle); int io_fflush (io_handle); int io_fileno (io_handle); io_handle io_popen (pseudothread pth, const char *command, const char *mode); void io_pclose (io_handle); int io_copy (io_handle from_io, io_handle to_io, int len); void io_setbufmode (io_handle, int mode); int io_get_inbufcount (io_handle); int io_get_outbufcount (io_handle); |
The io_* functions replace the normal blocking C library f* functions with equivalents which work on non-blocking pseudothread file descriptors. |
All of the functions in the synopsis above work identically to the C library equivalents, except where documented below. |
io_fdopen associates a socket sock with a I/O handle. The association cannot be broken later (so use dup(2) if you wish to later take back control of the underlying socket). If either the current thread exits or io_fclose is called, the underlying socket is closed (with close(2)). |
io_fclose flushes all unwritten data out of the socket and closes it. |
io_fgets operates similarly to the ordinary C library function fgets(3), except that it contains a useful fourth argument, store_eol. If this fourth argument is false, then the end of line characters (CR, CR LF or LF) are stripped from the string before it is stored. |
io_copy copies len bytes from from_io to to_io. If len equals -1 then bytes are copied from from_io until end of file is reached. If len equals 0, then no bytes are copied. The number of bytes actually copied is returned. |
io_setbufmode sets the output buffer mode, and works completely differently to the ordinary C library function setbufmode(3). The three mode arguments possible are: IO_MODE_LINE_BUFFERED, IO_MODE_UNBUFFERED and IO_MODE_FULLY_BUFFERED, and these correspond to line buffering, no buffering and full (block) buffering. |
io_get_inbufcount and io_get_outbufcount return the number of characters read and written on the socket since the socket was associated with the I/O object. |
Richard Jones <rich@annexia.org> |
GNU LGPL (see http://www.gnu.org/) |
pthrlib-3.0.3 |
fgetc(3), fgets(3), ungetc(3), fread(3), fputc(3), fputs(3), fprintf(3), fwrite(3), fflush(3), fileno(3), popen(3), pclose(3), pth_exit(3). |