ostream.h revision cd56a23e21f1df3f79648cf07e2f4385e2fadebb
#ifndef __OSTREAM_H
#define __OSTREAM_H
#include "ioloop.h"
struct ostream {
int stream_errno;
/* overflow is set when some of the data given to send()
functions was neither sent nor buffered. It's never unset inside
ostream code. */
unsigned int overflow:1;
unsigned int closed:1;
struct _ostream *real_stream;
};
/* Returns 1 if all data is sent (not necessarily flushed), 0 if not.
Pretty much the only real reason to return 0 is if you wish to send more
data to client which isn't buffered, eg. o_stream_send_istream(). */
typedef int stream_flush_callback_t(void *context);
/* Create new output stream from given file descriptor.
If max_buffer_size is 0, an "optimal" buffer size is used (max 128kB). */
struct ostream *
bool autoclose_fd);
/* o_stream_close() + o_stream_unref() */
/* Reference counting. References start from 1, so calling o_stream_unref()
destroys the stream if o_stream_ref() is never used. */
/* Unreferences the stream and sets stream pointer to NULL. */
/* Mark the stream closed. Nothing will be sent after this call. */
/* Set IO_WRITE callback. Default will just try to flush the output and
finishes when the buffer is empty. */
void *context);
/* Change the maximum size for stream's output buffer to grow. */
/* Delays sending as far as possible, writing only full buffers. Also sets
TCP_CORK on if supported. */
/* Flush the output stream, blocks until everything is sent.
Returns 1 if ok, -1 if error. */
/* Set "flush pending" state of stream. If set, the flush callback is called
when more data is allowed to be sent, even if the buffer itself is empty. */
/* Returns number of bytes currently in buffer. */
/* Seek to specified position from beginning of file. This works only for
files. Returns 1 if successful, -1 if error. */
/* Returns number of bytes sent, -1 = error */
unsigned int iov_count);
/* Send data from input stream. Returns number of bytes sent, or -1 if error.
Note that this function may block if either instream or outstream is
blocking.
It's also possible to use this function to copy data within same file
descriptor. If the file must be grown, you have to do it manually before
calling this function. */
#endif