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