Back to index

openldap  2.4.31
tio.h
Go to the documentation of this file.
00001 /*
00002    tio.h - timed io functions
00003    This file is part of the nss-pam-ldapd library.
00004 
00005    Copyright (C) 2007, 2008 Arthur de Jong
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Lesser General Public
00009    License as published by the Free Software Foundation; either
00010    version 2.1 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Lesser General Public License for more details.
00016 
00017    You should have received a copy of the GNU Lesser General Public
00018    License along with this library; if not, write to the Free Software
00019    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00020    02110-1301 USA
00021 */
00022 
00023 /*
00024 
00025    TODO: Add some documentation here.
00026 
00027    the SIGPIPE signal should be ignored (is ignored in this code)
00028 
00029    This library is not thread safe. You cannot share TFILE objects between
00030    threads and expect to be able to read and write from them in different
00031    threads. All the state is in the TFILE object so calls to this library on
00032    different objects can be done in parallel.
00033 
00034 */
00035 
00036 #ifndef _TIO_H
00037 #define _TIO_H
00038 
00039 #include <sys/time.h>
00040 #include <sys/types.h>
00041 
00042 #include "attrs.h"
00043 
00044 /* This is a generic file handle used for reading and writing
00045    (something like FILE from stdio.h). */
00046 typedef struct tio_fileinfo TFILE;
00047 
00048 /* Open a new TFILE based on the file descriptor. The timeout is set for any
00049    operation. The timeout value is copied so may be dereferenced after the
00050    call. */
00051 TFILE *tio_fdopen(int fd,struct timeval *readtimeout,struct timeval *writetimeout,
00052                   size_t initreadsize,size_t maxreadsize,
00053                   size_t initwritesize,size_t maxwritesize)
00054   LIKE_MALLOC MUST_USE;
00055 
00056 /* Read the specified number of bytes from the stream. */
00057 int tio_read(TFILE *fp,void *buf,size_t count);
00058 
00059 /* Read and discard the specified number of bytes from the stream. */
00060 int tio_skip(TFILE *fp,size_t count);
00061 
00062 /* Write the specified buffer to the stream. */
00063 int tio_write(TFILE *fp,const void *buf,size_t count);
00064 
00065 /* Write out all buffered data to the stream. */
00066 int tio_flush(TFILE *fp);
00067 
00068 /* Flush the streams and closes the underlying file descriptor. */
00069 int tio_close(TFILE *fp);
00070 
00071 /* Store the current position in the stream so that we can jump back to it
00072    with the tio_reset() function. */
00073 void tio_mark(TFILE *fp);
00074 
00075 /* Rewinds the stream to the point set by tio_mark(). Note that this only
00076    resets the read stream and not the write stream. This function returns
00077    whether the reset was successful (this function may fail if the buffers
00078    were full). */
00079 int tio_reset(TFILE *fp);
00080 
00081 #endif /* _TIO_H */