Blame common/tio.h

Packit 6bd9ab
/*
Packit 6bd9ab
   tio.h - timed io functions
Packit 6bd9ab
   This file is part of the nss-pam-ldapd library.
Packit 6bd9ab
Packit 6bd9ab
   Copyright (C) 2007, 2008, 2010, 2012, 2013 Arthur de Jong
Packit 6bd9ab
Packit 6bd9ab
   This library is free software; you can redistribute it and/or
Packit 6bd9ab
   modify it under the terms of the GNU Lesser General Public
Packit 6bd9ab
   License as published by the Free Software Foundation; either
Packit 6bd9ab
   version 2.1 of the License, or (at your option) any later version.
Packit 6bd9ab
Packit 6bd9ab
   This library is distributed in the hope that it will be useful,
Packit 6bd9ab
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6bd9ab
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6bd9ab
   Lesser General Public License for more details.
Packit 6bd9ab
Packit 6bd9ab
   You should have received a copy of the GNU Lesser General Public
Packit 6bd9ab
   License along with this library; if not, write to the Free Software
Packit 6bd9ab
   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
Packit 6bd9ab
   02110-1301 USA
Packit 6bd9ab
*/
Packit 6bd9ab
Packit 6bd9ab
/*
Packit 6bd9ab
Packit 6bd9ab
   TODO: Add some documentation here.
Packit 6bd9ab
Packit 6bd9ab
   the SIGPIPE signal should be ignored (is ignored in this code)
Packit 6bd9ab
Packit 6bd9ab
   This library is not thread safe. You cannot share TFILE objects between
Packit 6bd9ab
   threads and expect to be able to read and write from them in different
Packit 6bd9ab
   threads. All the state is in the TFILE object so calls to this library on
Packit 6bd9ab
   different objects can be done in parallel.
Packit 6bd9ab
Packit 6bd9ab
*/
Packit 6bd9ab
Packit 6bd9ab
#ifndef COMMON__TIO_H
Packit 6bd9ab
#define COMMON__TIO_H
Packit 6bd9ab
Packit 6bd9ab
#include <sys/time.h>
Packit 6bd9ab
#include <sys/types.h>
Packit 6bd9ab
Packit 6bd9ab
#include "compat/attrs.h"
Packit 6bd9ab
Packit 6bd9ab
/* This is a generic file handle used for reading and writing
Packit 6bd9ab
   (something like FILE from stdio.h). */
Packit 6bd9ab
typedef struct tio_fileinfo TFILE;
Packit 6bd9ab
Packit 6bd9ab
/* Open a new TFILE based on the file descriptor. The timeout is set for any
Packit 6bd9ab
   operation (value in milliseconds). */
Packit 6bd9ab
TFILE *tio_fdopen(int fd, int readtimeout, int writetimeout,
Packit 6bd9ab
                  size_t initreadsize, size_t maxreadsize,
Packit 6bd9ab
                  size_t initwritesize, size_t maxwritesize)
Packit 6bd9ab
  LIKE_MALLOC MUST_USE;
Packit 6bd9ab
Packit 6bd9ab
/* Read the specified number of bytes from the stream. */
Packit 6bd9ab
int tio_read(TFILE *fp, void *buf, size_t count);
Packit 6bd9ab
Packit 6bd9ab
/* Read and discard the specified number of bytes from the stream. */
Packit 6bd9ab
int tio_skip(TFILE *fp, size_t count);
Packit 6bd9ab
Packit 6bd9ab
/* Read all available data from the stream and empty the read buffer. */
Packit 6bd9ab
int tio_skipall(TFILE *fp, int timeout);
Packit 6bd9ab
Packit 6bd9ab
/* Write the specified buffer to the stream. */
Packit 6bd9ab
int tio_write(TFILE *fp, const void *buf, size_t count);
Packit 6bd9ab
Packit 6bd9ab
/* Write out all buffered data to the stream. */
Packit 6bd9ab
int tio_flush(TFILE *fp);
Packit 6bd9ab
Packit 6bd9ab
/* Flush the streams and closes the underlying file descriptor. */
Packit 6bd9ab
int tio_close(TFILE *fp);
Packit 6bd9ab
Packit 6bd9ab
/* Store the current position in the stream so that we can jump back to it
Packit 6bd9ab
   with the tio_reset() function. */
Packit 6bd9ab
void tio_mark(TFILE *fp);
Packit 6bd9ab
Packit 6bd9ab
/* Rewinds the stream to the point set by tio_mark(). Note that this only
Packit 6bd9ab
   resets the read stream and not the write stream. This function returns
Packit 6bd9ab
   whether the reset was successful (this function may fail if the buffers
Packit 6bd9ab
   were full). */
Packit 6bd9ab
int tio_reset(TFILE *fp);
Packit 6bd9ab
Packit 6bd9ab
#endif /* COMMON__TIO_H */