annotate src/lib/ostream.h @ 22664:fea53c2725c0

director: Fix director_max_parallel_moves/kicks type Should be uint, not time.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 09 Nov 2017 12:24:16 +0200
parents 668274a98b48
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
6410
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 6161
diff changeset
1 #ifndef OSTREAM_H
e4eb71ae8e96 Changed .h ifdef/defines to use <NAME>_H format.
Timo Sirainen <tss@iki.fi>
parents: 6161
diff changeset
2 #define OSTREAM_H
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2245
diff changeset
4 #include "ioloop.h"
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2245
diff changeset
5
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
6 struct ostream {
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 uoff_t offset;
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8
6850
c8f6eec5e996 Added last_failed_errno to ostream to make error handling easier with files.
Timo Sirainen <tss@iki.fi>
parents: 6415
diff changeset
9 /* errno for the last operation send/seek operation. cleared before
c8f6eec5e996 Added last_failed_errno to ostream to make error handling easier with files.
Timo Sirainen <tss@iki.fi>
parents: 6415
diff changeset
10 each call. */
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 int stream_errno;
6850
c8f6eec5e996 Added last_failed_errno to ostream to make error handling easier with files.
Timo Sirainen <tss@iki.fi>
parents: 6415
diff changeset
12 /* errno of the last failed send/seek. never cleared. */
c8f6eec5e996 Added last_failed_errno to ostream to make error handling easier with files.
Timo Sirainen <tss@iki.fi>
parents: 6415
diff changeset
13 int last_failed_errno;
c8f6eec5e996 Added last_failed_errno to ostream to make error handling easier with files.
Timo Sirainen <tss@iki.fi>
parents: 6415
diff changeset
14
3618
a16f27ce2eda Changed iov_count to be unsigned int, it's large enough. Added overflow-flag
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
15 /* overflow is set when some of the data given to send()
a16f27ce2eda Changed iov_count to be unsigned int, it's large enough. Added overflow-flag
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
16 functions was neither sent nor buffered. It's never unset inside
a16f27ce2eda Changed iov_count to be unsigned int, it's large enough. Added overflow-flag
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
17 ostream code. */
a16f27ce2eda Changed iov_count to be unsigned int, it's large enough. Added overflow-flag
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
18 unsigned int overflow:1;
20860
668274a98b48 lib: Added ostream.blocking boolean
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 18165
diff changeset
19 /* o_stream_send() writes all the data or returns failure */
668274a98b48 lib: Added ostream.blocking boolean
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 18165
diff changeset
20 unsigned int blocking:1;
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 unsigned int closed:1;
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22
6415
b0096861c390 Renamed struct _[io]stream to struct [io]stream_private. Also removed _
Timo Sirainen <tss@iki.fi>
parents: 6410
diff changeset
23 struct ostream_private *real_stream;
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 };
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
26 /* Returns 1 if all data is sent (not necessarily flushed), 0 if not.
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
27 Pretty much the only real reason to return 0 is if you wish to send more
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
28 data to client which isn't buffered, eg. o_stream_send_istream(). */
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
29 typedef int stream_flush_callback_t(void *context);
18164
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
30 typedef void ostream_callback_t(void *context);
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
31
2245
95fe82bbda7a Allow giving 0 max_buffer_size, in which case "optimal" size is used.
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
32 /* Create new output stream from given file descriptor.
95fe82bbda7a Allow giving 0 max_buffer_size, in which case "optimal" size is used.
Timo Sirainen <tss@iki.fi>
parents: 1499
diff changeset
33 If max_buffer_size is 0, an "optimal" buffer size is used (max 128kB). */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
34 struct ostream *
6161
c62f7ee79446 Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
35 o_stream_create_fd(int fd, size_t max_buffer_size, bool autoclose_fd);
17479
0bcb43692d91 lib: Added [io]_stream_create_fd_*autoclose()
Timo Sirainen <tss@iki.fi>
parents: 17384
diff changeset
36 /* The fd is set to -1 immediately to avoid accidentally closing it twice. */
0bcb43692d91 lib: Added [io]_stream_create_fd_*autoclose()
Timo Sirainen <tss@iki.fi>
parents: 17384
diff changeset
37 struct ostream *o_stream_create_fd_autoclose(int *fd, size_t max_buffer_size);
6161
c62f7ee79446 Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
38 /* Create an output stream from a regular file which begins at given offset.
c62f7ee79446 Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
39 If offset==(uoff_t)-1, the current offset isn't known. */
c62f7ee79446 Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
40 struct ostream *
c62f7ee79446 Split o_stream_create_file() to _create_fd() and _create_fd_file().
Timo Sirainen <tss@iki.fi>
parents: 6142
diff changeset
41 o_stream_create_fd_file(int fd, uoff_t offset, bool autoclose_fd);
17479
0bcb43692d91 lib: Added [io]_stream_create_fd_*autoclose()
Timo Sirainen <tss@iki.fi>
parents: 17384
diff changeset
42 struct ostream *o_stream_create_fd_file_autoclose(int *fd, uoff_t offset);
9558
320d2164bc17 Added o_stream_create_buffer() for having output stream write to a buffer.
Timo Sirainen <tss@iki.fi>
parents: 8923
diff changeset
43 /* Create an output stream to a buffer. */
320d2164bc17 Added o_stream_create_buffer() for having output stream write to a buffer.
Timo Sirainen <tss@iki.fi>
parents: 8923
diff changeset
44 struct ostream *o_stream_create_buffer(buffer_t *buf);
15174
f860cdf156cf Added [io]_stream_create_error() for creating streams that always fail reads/writes.
Timo Sirainen <tss@iki.fi>
parents: 14921
diff changeset
45 /* Create an output streams that always fails the writes. */
f860cdf156cf Added [io]_stream_create_error() for creating streams that always fail reads/writes.
Timo Sirainen <tss@iki.fi>
parents: 14921
diff changeset
46 struct ostream *o_stream_create_error(int stream_errno);
16813
a919c43ab91b lib: Added [io]_stream_create_error_str()
Timo Sirainen <tss@iki.fi>
parents: 16772
diff changeset
47 struct ostream *
a919c43ab91b lib: Added [io]_stream_create_error_str()
Timo Sirainen <tss@iki.fi>
parents: 16772
diff changeset
48 o_stream_create_error_str(int stream_errno, const char *fmt, ...)
a919c43ab91b lib: Added [io]_stream_create_error_str()
Timo Sirainen <tss@iki.fi>
parents: 16772
diff changeset
49 ATTR_FORMAT(2, 3);
18165
071e46b032c8 lib: Added o_stream_create_passthrough() for creating simple wrapper ostreams
Timo Sirainen <tss@iki.fi>
parents: 18164
diff changeset
50 /* Create an output stream that simply passes through data. This is mainly
071e46b032c8 lib: Added o_stream_create_passthrough() for creating simple wrapper ostreams
Timo Sirainen <tss@iki.fi>
parents: 18164
diff changeset
51 useful as a wrapper when combined with destroy callbacks. */
071e46b032c8 lib: Added o_stream_create_passthrough() for creating simple wrapper ostreams
Timo Sirainen <tss@iki.fi>
parents: 18164
diff changeset
52 struct ostream *o_stream_create_passthrough(struct ostream *output);
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53
10847
5f16e488e7f6 i/ostreams can now have a name (e.g. file path).
Timo Sirainen <tss@iki.fi>
parents: 10084
diff changeset
54 /* Set name (e.g. path) for output stream. */
5f16e488e7f6 i/ostreams can now have a name (e.g. file path).
Timo Sirainen <tss@iki.fi>
parents: 10084
diff changeset
55 void o_stream_set_name(struct ostream *stream, const char *name);
5f16e488e7f6 i/ostreams can now have a name (e.g. file path).
Timo Sirainen <tss@iki.fi>
parents: 10084
diff changeset
56 /* Get output stream's name. Returns "" if stream has no name. */
5f16e488e7f6 i/ostreams can now have a name (e.g. file path).
Timo Sirainen <tss@iki.fi>
parents: 10084
diff changeset
57 const char *o_stream_get_name(struct ostream *stream);
5f16e488e7f6 i/ostreams can now have a name (e.g. file path).
Timo Sirainen <tss@iki.fi>
parents: 10084
diff changeset
58
14851
4bcd507e8907 Added o_stream_get_fd().
Timo Sirainen <tss@iki.fi>
parents: 14702
diff changeset
59 /* Return file descriptor for stream, or -1 if none is available. */
4bcd507e8907 Added o_stream_get_fd().
Timo Sirainen <tss@iki.fi>
parents: 14702
diff changeset
60 int o_stream_get_fd(struct ostream *stream);
16772
e35be66003e2 iostream: Added ability to set/get error strings for streams.
Timo Sirainen <tss@iki.fi>
parents: 16020
diff changeset
61 /* Returns error string for the previous error (stream_errno,
e35be66003e2 iostream: Added ability to set/get error strings for streams.
Timo Sirainen <tss@iki.fi>
parents: 16020
diff changeset
62 not last_failed_errno). */
e35be66003e2 iostream: Added ability to set/get error strings for streams.
Timo Sirainen <tss@iki.fi>
parents: 16020
diff changeset
63 const char *o_stream_get_error(struct ostream *stream);
14851
4bcd507e8907 Added o_stream_get_fd().
Timo Sirainen <tss@iki.fi>
parents: 14702
diff changeset
64
16020
6cabb95d32ec iostreams: Added close_parent flag to close() handler and clarified close/destroy APIs.
Timo Sirainen <tss@iki.fi>
parents: 15174
diff changeset
65 /* Close this stream (but not its parents) and unreference it. */
4070
71b8faa84ec6 Added i_stream_destroy() and o_stream_destroy() and used them instead of
Timo Sirainen <tss@iki.fi>
parents: 3879
diff changeset
66 void o_stream_destroy(struct ostream **stream);
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 /* Reference counting. References start from 1, so calling o_stream_unref()
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 destroys the stream if o_stream_ref() is never used. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
69 void o_stream_ref(struct ostream *stream);
3879
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
70 /* Unreferences the stream and sets stream pointer to NULL. */
928229f8b3e6 deinit, unref, destroy, close, free, etc. functions now take a pointer to
Timo Sirainen <tss@iki.fi>
parents: 3863
diff changeset
71 void o_stream_unref(struct ostream **stream);
18164
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
72 /* Call the given callback function when stream is destroyed. */
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
73 void o_stream_add_destroy_callback(struct ostream *stream,
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
74 ostream_callback_t *callback, void *context)
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
75 ATTR_NULL(3);
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
76 #define o_stream_add_destroy_callback(stream, callback, context) \
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
77 o_stream_add_destroy_callback(stream + \
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
78 CALLBACK_TYPECHECK(callback, void (*)(typeof(context))), \
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
79 (ostream_callback_t *)callback, context)
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
80 /* Remove the destroy callback. */
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
81 void o_stream_remove_destroy_callback(struct ostream *stream,
4723cecff76c lib: Added o_stream_add_destroy_callback()
Timo Sirainen <tss@iki.fi>
parents: 17930
diff changeset
82 void (*callback)());
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
16020
6cabb95d32ec iostreams: Added close_parent flag to close() handler and clarified close/destroy APIs.
Timo Sirainen <tss@iki.fi>
parents: 15174
diff changeset
84 /* Mark the stream and all of its parent streams closed. Nothing will be
6cabb95d32ec iostreams: Added close_parent flag to close() handler and clarified close/destroy APIs.
Timo Sirainen <tss@iki.fi>
parents: 15174
diff changeset
85 sent after this call. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
86 void o_stream_close(struct ostream *stream);
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
88 /* Set IO_WRITE callback. Default will just try to flush the output and
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
89 finishes when the buffer is empty. */
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2245
diff changeset
90 void o_stream_set_flush_callback(struct ostream *stream,
2790
02c0b8d532c2 Changed ostream's flush callback to have return value which can tell if
Timo Sirainen <tss@iki.fi>
parents: 2421
diff changeset
91 stream_flush_callback_t *callback,
14629
c93ca5e46a8a Marked functions parameters that are allowed to be NULL. Some APIs were also changed.
Timo Sirainen <tss@iki.fi>
parents: 13417
diff changeset
92 void *context) ATTR_NULL(3);
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
93 #define o_stream_set_flush_callback(stream, callback, context) \
14921
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14851
diff changeset
94 o_stream_set_flush_callback(stream + \
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14851
diff changeset
95 CALLBACK_TYPECHECK(callback, int (*)(typeof(context))), \
d3db2ba15d00 Removed CONTEXT_TYPE_SAFETY macro and reimplemented its functionality better.
Timo Sirainen <tss@iki.fi>
parents: 14851
diff changeset
96 (stream_flush_callback_t *)callback, context)
4903
204d7edc7cdc Added context parameter type safety checks for most callback APIs.
Timo Sirainen <tss@iki.fi>
parents: 4070
diff changeset
97 void o_stream_unset_flush_callback(struct ostream *stream);
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 /* Change the maximum size for stream's output buffer to grow. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
99 void o_stream_set_max_buffer_size(struct ostream *stream, size_t max_size);
17250
6abe16ff8108 Added o_stream_get_max_buffer_size()
Timo Sirainen <tss@iki.fi>
parents: 16813
diff changeset
100 /* Returns the current max. buffer size. */
6abe16ff8108 Added o_stream_get_max_buffer_size()
Timo Sirainen <tss@iki.fi>
parents: 16813
diff changeset
101 size_t o_stream_get_max_buffer_size(struct ostream *stream);
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 /* Delays sending as far as possible, writing only full buffers. Also sets
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2245
diff changeset
104 TCP_CORK on if supported. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
105 void o_stream_cork(struct ostream *stream);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2245
diff changeset
106 void o_stream_uncork(struct ostream *stream);
17384
8ab8327400cd lib: Added o_stream_is_corked().
Timo Sirainen <tss@iki.fi>
parents: 17250
diff changeset
107 bool o_stream_is_corked(struct ostream *stream);
8107
dfae8a7d695b Updated o_stream_flush() comment.
Timo Sirainen <tss@iki.fi>
parents: 7912
diff changeset
108 /* Try to flush the output stream. Returns 1 if all sent, 0 if not,
dfae8a7d695b Updated o_stream_flush() comment.
Timo Sirainen <tss@iki.fi>
parents: 7912
diff changeset
109 -1 if error. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
110 int o_stream_flush(struct ostream *stream);
3336
a3a72d5bdfce o_stream_uncork() was previously always setting IO_WRITE handler even if
Timo Sirainen <tss@iki.fi>
parents: 2790
diff changeset
111 /* Set "flush pending" state of stream. If set, the flush callback is called
a3a72d5bdfce o_stream_uncork() was previously always setting IO_WRITE handler even if
Timo Sirainen <tss@iki.fi>
parents: 2790
diff changeset
112 when more data is allowed to be sent, even if the buffer itself is empty. */
3863
55df57c028d4 Added "bool" type and changed all ints that were used as booleans to bool.
Timo Sirainen <tss@iki.fi>
parents: 3618
diff changeset
113 void o_stream_set_flush_pending(struct ostream *stream, bool set);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2245
diff changeset
114 /* Returns number of bytes currently in buffer. */
7912
81806d402514 Added more consts, ATTR_CONSTs and ATTR_PUREs.
Timo Sirainen <tss@iki.fi>
parents: 6850
diff changeset
115 size_t o_stream_get_buffer_used_size(const struct ostream *stream) ATTR_PURE;
10084
ede6701cfe7a Added o_stream_get_buffer_avail_size().
Timo Sirainen <tss@iki.fi>
parents: 9558
diff changeset
116 /* Returns number of bytes we can still write without failing. */
ede6701cfe7a Added o_stream_get_buffer_avail_size().
Timo Sirainen <tss@iki.fi>
parents: 9558
diff changeset
117 size_t o_stream_get_buffer_avail_size(const struct ostream *stream) ATTR_PURE;
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
119 /* Seek to specified position from beginning of file. This works only for
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
120 files. Returns 1 if successful, -1 if error. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
121 int o_stream_seek(struct ostream *stream, uoff_t offset);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2245
diff changeset
122 /* Returns number of bytes sent, -1 = error */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
123 ssize_t o_stream_send(struct ostream *stream, const void *data, size_t size);
2421
d141e1bfdd63 We never do blocking reads/writes to network anymore. Changed imap and pop3
Timo Sirainen <tss@iki.fi>
parents: 2245
diff changeset
124 ssize_t o_stream_sendv(struct ostream *stream, const struct const_iovec *iov,
3618
a16f27ce2eda Changed iov_count to be unsigned int, it's large enough. Added overflow-flag
Timo Sirainen <tss@iki.fi>
parents: 3336
diff changeset
125 unsigned int iov_count);
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
126 ssize_t o_stream_send_str(struct ostream *stream, const char *str);
14681
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
127 /* Send with delayed error handling. o_stream_has_errors() or
14702
3d3689c2c81d o_stream_nsend() comment update
Timo Sirainen <tss@iki.fi>
parents: 14681
diff changeset
128 o_stream_ignore_last_errors() must be called after these functions before
3d3689c2c81d o_stream_nsend() comment update
Timo Sirainen <tss@iki.fi>
parents: 14681
diff changeset
129 the stream is destroyed. */
14681
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
130 void o_stream_nsend(struct ostream *stream, const void *data, size_t size);
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
131 void o_stream_nsendv(struct ostream *stream, const struct const_iovec *iov,
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
132 unsigned int iov_count);
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
133 void o_stream_nsend_str(struct ostream *stream, const char *str);
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
134 void o_stream_nflush(struct ostream *stream);
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
135 /* Flushes the stream and returns -1 if stream->last_failed_errno is
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
136 non-zero. Marks the stream's error handling as completed. errno is also set
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
137 to last_failed_errno. */
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
138 int o_stream_nfinish(struct ostream *stream);
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
139 /* Marks the stream's error handling as completed to avoid i_panic() on
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
140 destroy. */
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
141 void o_stream_ignore_last_errors(struct ostream *stream);
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
142 /* If error handling is disabled, the i_panic() on destroy is never called.
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
143 This function can be called immediately after the stream is created.
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
144 When creating wrapper streams, they copy this behavior from the parent
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
145 stream. */
ca37d1577291 Added o_stream_nsend*() and related functions to make delayed error handling safer.
Timo Sirainen <tss@iki.fi>
parents: 14629
diff changeset
146 void o_stream_set_no_error_handling(struct ostream *stream, bool set);
17930
af382aaad0e8 lib: Updated comment to o_stream_send_istream()
Timo Sirainen <tss@iki.fi>
parents: 17479
diff changeset
147 /* Send data from input stream. Returns number of bytes sent, or -1 if error
af382aaad0e8 lib: Updated comment to o_stream_send_istream()
Timo Sirainen <tss@iki.fi>
parents: 17479
diff changeset
148 in either outstream or instream. Note that this function may block if either
af382aaad0e8 lib: Updated comment to o_stream_send_istream()
Timo Sirainen <tss@iki.fi>
parents: 17479
diff changeset
149 instream or outstream is blocking.
1197
e86f259048cf o_stream_send_istream() is now safe to use for moving data within file.
Timo Sirainen <tss@iki.fi>
parents: 1027
diff changeset
150
5275
49efad884ed1 Updated o_stream_send_istream() comments
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
151 Also note that this function may not add anything to the output buffer, so
49efad884ed1 Updated o_stream_send_istream() comments
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
152 if you want the flush callback to be called when more data can be written,
49efad884ed1 Updated o_stream_send_istream() comments
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
153 you'll need to call o_stream_set_flush_pending() manually.
49efad884ed1 Updated o_stream_send_istream() comments
Timo Sirainen <tss@iki.fi>
parents: 4903
diff changeset
154
1197
e86f259048cf o_stream_send_istream() is now safe to use for moving data within file.
Timo Sirainen <tss@iki.fi>
parents: 1027
diff changeset
155 It's also possible to use this function to copy data within same file
e86f259048cf o_stream_send_istream() is now safe to use for moving data within file.
Timo Sirainen <tss@iki.fi>
parents: 1027
diff changeset
156 descriptor. If the file must be grown, you have to do it manually before
e86f259048cf o_stream_send_istream() is now safe to use for moving data within file.
Timo Sirainen <tss@iki.fi>
parents: 1027
diff changeset
157 calling this function. */
903
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
158 off_t o_stream_send_istream(struct ostream *outstream,
fd8888f6f037 Naming style changes, finally got tired of most of the typedefs. Also the
Timo Sirainen <tss@iki.fi>
parents: 807
diff changeset
159 struct istream *instream);
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160
8923
47076db1f911 Added o_stream_pwrite().
Timo Sirainen <tss@iki.fi>
parents: 8107
diff changeset
161 /* Write data to specified offset. Returns 0 if successful, -1 if error. */
47076db1f911 Added o_stream_pwrite().
Timo Sirainen <tss@iki.fi>
parents: 8107
diff changeset
162 int o_stream_pwrite(struct ostream *stream, const void *data, size_t size,
47076db1f911 Added o_stream_pwrite().
Timo Sirainen <tss@iki.fi>
parents: 8107
diff changeset
163 uoff_t offset);
47076db1f911 Added o_stream_pwrite().
Timo Sirainen <tss@iki.fi>
parents: 8107
diff changeset
164
13417
977dcd541f69 Added o_stream_switch_ioloop() and implemented it to all ostreams.
Timo Sirainen <tss@iki.fi>
parents: 10847
diff changeset
165 /* If there are any I/O loop items associated with the stream, move all of
977dcd541f69 Added o_stream_switch_ioloop() and implemented it to all ostreams.
Timo Sirainen <tss@iki.fi>
parents: 10847
diff changeset
166 them to current_ioloop. */
977dcd541f69 Added o_stream_switch_ioloop() and implemented it to all ostreams.
Timo Sirainen <tss@iki.fi>
parents: 10847
diff changeset
167 void o_stream_switch_ioloop(struct ostream *stream);
977dcd541f69 Added o_stream_switch_ioloop() and implemented it to all ostreams.
Timo Sirainen <tss@iki.fi>
parents: 10847
diff changeset
168
764
f57c52738f90 Renamed IBuffer and OBuffer to IStream and OStream which describes their
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 #endif