From 51f3f0903b3f32231f7e8780a5d7c4f9ae1f9203 Mon Sep 17 00:00:00 2001 From: Arthur de Jong Date: Fri, 8 Jun 2007 22:57:27 +0000 Subject: implement our own stdio-like library that handles IO with a simple configurable timeout mechanism with buffering git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-ldapd@272 ef36b2f9-881f-0410-afb5-c4e39611909c --- common/tio.h | 64 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) create mode 100644 common/tio.h (limited to 'common/tio.h') diff --git a/common/tio.h b/common/tio.h new file mode 100644 index 0000000..d627ddf --- /dev/null +++ b/common/tio.h @@ -0,0 +1,64 @@ +/* + tio.h - timed io functions + This file is part of the nss-ldapd library. + + Copyright (C) 2007 Arthur de Jong + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA +*/ + +/* + + Add some documentation here. + + the SIGPIPE signal should be ignored + +*/ + +#ifndef _TIO_H +#define _TIO_H + +#include +#include + +#include "compat/attrs.h" + +/* generic file handle used for reading and writing + (something like FILE from stdio.h) */ +typedef struct tio_fileinfo TFILE; + +/* Open a new TFILE based on the file descriptor. + The timeout is set for any operation. + the timeout value is copied so may be dereferenced after the call. */ +TFILE *tio_fdopen(int fd,struct timeval *readtimeout,struct timeval *writetimeout) + LIKE_MALLOC MUST_USE; + +/* Read the specified number of bytes from the stream. */ +int tio_read(TFILE *fp, void *buf, size_t count); + +/* Read and discard the specified number of bytes from the stream. */ +int tio_skip(TFILE *fp, size_t count); + +/* Write the specified buffer to the stream. */ +int tio_write(TFILE *fp, const void *buf, size_t count); + +/* Write out all buffered data to the stream. */ +int tio_flush(TFILE *fp); + +/* this also closes the underlying file descriptor */ +int tio_close(TFILE *fp); + +#endif /* _TIO_H */ -- cgit v1.2.3