Home | History | Annotate | Line # | Download | only in nss-pam-ldapd
      1  1.2  christos /*	$NetBSD: tio.h,v 1.2 2021/08/14 16:14:52 christos Exp $	*/
      2  1.1      adam 
      3  1.1      adam /*
      4  1.1      adam    tio.h - timed io functions
      5  1.1      adam    This file is part of the nss-pam-ldapd library.
      6  1.1      adam 
      7  1.2  christos    Copyright (C) 2007, 2008, 2010, 2012, 2013 Arthur de Jong
      8  1.1      adam 
      9  1.1      adam    This library is free software; you can redistribute it and/or
     10  1.1      adam    modify it under the terms of the GNU Lesser General Public
     11  1.1      adam    License as published by the Free Software Foundation; either
     12  1.1      adam    version 2.1 of the License, or (at your option) any later version.
     13  1.1      adam 
     14  1.1      adam    This library is distributed in the hope that it will be useful,
     15  1.1      adam    but WITHOUT ANY WARRANTY; without even the implied warranty of
     16  1.1      adam    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     17  1.1      adam    Lesser General Public License for more details.
     18  1.1      adam 
     19  1.1      adam    You should have received a copy of the GNU Lesser General Public
     20  1.1      adam    License along with this library; if not, write to the Free Software
     21  1.1      adam    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
     22  1.1      adam    02110-1301 USA
     23  1.1      adam */
     24  1.1      adam 
     25  1.1      adam /*
     26  1.1      adam 
     27  1.1      adam    TODO: Add some documentation here.
     28  1.1      adam 
     29  1.1      adam    the SIGPIPE signal should be ignored (is ignored in this code)
     30  1.1      adam 
     31  1.1      adam    This library is not thread safe. You cannot share TFILE objects between
     32  1.1      adam    threads and expect to be able to read and write from them in different
     33  1.1      adam    threads. All the state is in the TFILE object so calls to this library on
     34  1.1      adam    different objects can be done in parallel.
     35  1.1      adam 
     36  1.1      adam */
     37  1.1      adam 
     38  1.2  christos #ifndef COMMON__TIO_H
     39  1.2  christos #define COMMON__TIO_H
     40  1.1      adam 
     41  1.1      adam #include <sys/time.h>
     42  1.1      adam #include <sys/types.h>
     43  1.1      adam 
     44  1.1      adam #include "attrs.h"
     45  1.1      adam 
     46  1.1      adam /* This is a generic file handle used for reading and writing
     47  1.1      adam    (something like FILE from stdio.h). */
     48  1.1      adam typedef struct tio_fileinfo TFILE;
     49  1.1      adam 
     50  1.1      adam /* Open a new TFILE based on the file descriptor. The timeout is set for any
     51  1.2  christos    operation (value in milliseconds). */
     52  1.2  christos TFILE *tio_fdopen(int fd, int readtimeout, int writetimeout,
     53  1.2  christos                   size_t initreadsize, size_t maxreadsize,
     54  1.2  christos                   size_t initwritesize, size_t maxwritesize)
     55  1.1      adam   LIKE_MALLOC MUST_USE;
     56  1.1      adam 
     57  1.1      adam /* Read the specified number of bytes from the stream. */
     58  1.2  christos int tio_read(TFILE *fp, void *buf, size_t count);
     59  1.1      adam 
     60  1.1      adam /* Read and discard the specified number of bytes from the stream. */
     61  1.2  christos int tio_skip(TFILE *fp, size_t count);
     62  1.2  christos 
     63  1.2  christos /* Read all available data from the stream and empty the read buffer. */
     64  1.2  christos int tio_skipall(TFILE *fp, int timeout);
     65  1.1      adam 
     66  1.1      adam /* Write the specified buffer to the stream. */
     67  1.2  christos int tio_write(TFILE *fp, const void *buf, size_t count);
     68  1.1      adam 
     69  1.1      adam /* Write out all buffered data to the stream. */
     70  1.1      adam int tio_flush(TFILE *fp);
     71  1.1      adam 
     72  1.1      adam /* Flush the streams and closes the underlying file descriptor. */
     73  1.1      adam int tio_close(TFILE *fp);
     74  1.1      adam 
     75  1.1      adam /* Store the current position in the stream so that we can jump back to it
     76  1.1      adam    with the tio_reset() function. */
     77  1.1      adam void tio_mark(TFILE *fp);
     78  1.1      adam 
     79  1.1      adam /* Rewinds the stream to the point set by tio_mark(). Note that this only
     80  1.1      adam    resets the read stream and not the write stream. This function returns
     81  1.1      adam    whether the reset was successful (this function may fail if the buffers
     82  1.1      adam    were full). */
     83  1.1      adam int tio_reset(TFILE *fp);
     84  1.1      adam 
     85  1.2  christos #endif /* COMMON__TIO_H */
     86