1202719Sgabor/*	$NetBSD$	*/
2202719Sgabor
3202719Sgabor/*
4202719Sgabor   tio.h - timed io functions
5202719Sgabor   This file is part of the nss-pam-ldapd library.
6202719Sgabor
7202719Sgabor   Copyright (C) 2007, 2008 Arthur de Jong
8202719Sgabor
9202719Sgabor   This library is free software; you can redistribute it and/or
10202719Sgabor   modify it under the terms of the GNU Lesser General Public
11202719Sgabor   License as published by the Free Software Foundation; either
12202719Sgabor   version 2.1 of the License, or (at your option) any later version.
13202719Sgabor
14202719Sgabor   This library is distributed in the hope that it will be useful,
15202719Sgabor   but WITHOUT ANY WARRANTY; without even the implied warranty of
16202719Sgabor   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17202719Sgabor   Lesser General Public License for more details.
18202719Sgabor
19202719Sgabor   You should have received a copy of the GNU Lesser General Public
20202719Sgabor   License along with this library; if not, write to the Free Software
21202719Sgabor   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22202719Sgabor   02110-1301 USA
23202719Sgabor*/
24202719Sgabor
25202719Sgabor/*
26202719Sgabor
27202719Sgabor   TODO: Add some documentation here.
28202719Sgabor
29202719Sgabor   the SIGPIPE signal should be ignored (is ignored in this code)
30202719Sgabor
31202719Sgabor   This library is not thread safe. You cannot share TFILE objects between
32202719Sgabor   threads and expect to be able to read and write from them in different
33202719Sgabor   threads. All the state is in the TFILE object so calls to this library on
34202719Sgabor   different objects can be done in parallel.
35202719Sgabor
36202719Sgabor*/
37202719Sgabor
38202719Sgabor#ifndef _TIO_H
39202719Sgabor#define _TIO_H
40202719Sgabor
41202719Sgabor#include <sys/time.h>
42202719Sgabor#include <sys/types.h>
43203498Sdelphij
44202719Sgabor#include "attrs.h"
45202719Sgabor
46202719Sgabor/* This is a generic file handle used for reading and writing
47202719Sgabor   (something like FILE from stdio.h). */
48202719Sgabortypedef struct tio_fileinfo TFILE;
49202719Sgabor
50202719Sgabor/* Open a new TFILE based on the file descriptor. The timeout is set for any
51232994Skevlo   operation. The timeout value is copied so may be dereferenced after the
52202719Sgabor   call. */
53202719SgaborTFILE *tio_fdopen(int fd,struct timeval *readtimeout,struct timeval *writetimeout,
54202719Sgabor                  size_t initreadsize,size_t maxreadsize,
55202719Sgabor                  size_t initwritesize,size_t maxwritesize)
56202719Sgabor  LIKE_MALLOC MUST_USE;
57202719Sgabor
58202719Sgabor/* Read the specified number of bytes from the stream. */
59202719Sgaborint tio_read(TFILE *fp,void *buf,size_t count);
60202719Sgabor
61202719Sgabor/* Read and discard the specified number of bytes from the stream. */
62202719Sgaborint tio_skip(TFILE *fp,size_t count);
63202719Sgabor
64202719Sgabor/* Write the specified buffer to the stream. */
65202719Sgaborint tio_write(TFILE *fp,const void *buf,size_t count);
66202719Sgabor
67202719Sgabor/* Write out all buffered data to the stream. */
68202719Sgaborint tio_flush(TFILE *fp);
69203443Sgabor
70202719Sgabor/* Flush the streams and closes the underlying file descriptor. */
71202719Sgaborint tio_close(TFILE *fp);
72202719Sgabor
73202719Sgabor/* Store the current position in the stream so that we can jump back to it
74202719Sgabor   with the tio_reset() function. */
75202719Sgaborvoid tio_mark(TFILE *fp);
76202719Sgabor
77202719Sgabor/* Rewinds the stream to the point set by tio_mark(). Note that this only
78202719Sgabor   resets the read stream and not the write stream. This function returns
79202719Sgabor   whether the reset was successful (this function may fail if the buffers
80202719Sgabor   were full). */
81202719Sgaborint tio_reset(TFILE *fp);
82202719Sgabor
83202719Sgabor#endif /* _TIO_H */
84202719Sgabor