Lines Matching defs:pump
6 #include "iostream-pump.h"
29 void iostream_pump_copy(struct iostream_pump *pump)
33 o_stream_cork(pump->output);
34 size_t old_size = o_stream_get_max_buffer_size(pump->output);
35 o_stream_set_max_buffer_size(pump->output,
37 o_stream_get_max_buffer_size(pump->output)));
38 res = o_stream_send_istream(pump->output, pump->input);
39 o_stream_set_max_buffer_size(pump->output, old_size);
40 o_stream_uncork(pump->output);
44 io_remove(&pump->io);
45 pump->callback(IOSTREAM_PUMP_STATUS_INPUT_ERROR, pump->context);
48 io_remove(&pump->io);
49 pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, pump->context);
52 pump->waiting_output = TRUE;
53 io_remove(&pump->io);
56 pump->waiting_output = FALSE;
57 io_remove(&pump->io);
59 switch (o_stream_flush(pump->output)) {
61 pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, pump->context);
64 pump->waiting_output = TRUE;
65 pump->completed = TRUE;
68 pump->callback(IOSTREAM_PUMP_STATUS_INPUT_EOF, pump->context);
73 pump->waiting_output = FALSE;
80 int iostream_pump_flush(struct iostream_pump *pump)
83 if ((ret = o_stream_flush(pump->output)) <= 0) {
85 pump->callback(IOSTREAM_PUMP_STATUS_OUTPUT_ERROR, pump->context);
88 pump->waiting_output = FALSE;
89 if (pump->completed) {
90 pump->callback(IOSTREAM_PUMP_STATUS_INPUT_EOF, pump->context);
94 if (pump->io == NULL) {
95 pump->io = io_add_istream(pump->input, iostream_pump_copy, pump);
96 io_set_pending(pump->io);
111 /* create pump */
112 struct iostream_pump *pump = i_new(struct iostream_pump, 1);
113 pump->input = input;
114 pump->output = output;
116 pump->ref = 1;
118 return pump;
121 void iostream_pump_start(struct iostream_pump *pump)
123 i_assert(pump != NULL);
124 i_assert(pump->callback != NULL);
127 o_stream_set_flush_callback(pump->output, iostream_pump_flush, pump);
130 pump->io = io_add_istream(pump->input, iostream_pump_copy, pump);
133 io_set_pending(pump->io);
136 struct istream *iostream_pump_get_input(struct iostream_pump *pump)
138 i_assert(pump != NULL);
139 return pump->input;
142 struct ostream *iostream_pump_get_output(struct iostream_pump *pump)
144 i_assert(pump != NULL);
145 return pump->output;
148 void iostream_pump_set_completion_callback(struct iostream_pump *pump,
151 i_assert(pump != NULL);
152 pump->callback = callback;
153 pump->context = context;
156 void iostream_pump_ref(struct iostream_pump *pump)
158 i_assert(pump != NULL && pump->ref > 0);
159 pump->ref++;
165 struct iostream_pump *pump = *pump_r;
168 i_assert(pump->ref > 0);
169 if (--pump->ref == 0) {
170 iostream_pump_stop(pump);
171 o_stream_unref(&pump->output);
172 i_stream_unref(&pump->input);
173 i_free(pump);
177 void iostream_pump_stop(struct iostream_pump *pump)
179 i_assert(pump != NULL);
181 o_stream_unset_flush_callback(pump->output);
183 io_remove(&pump->io);
186 bool iostream_pump_is_waiting_output(struct iostream_pump *pump)
188 return pump->waiting_output;
191 void iostream_pump_switch_ioloop(struct iostream_pump *pump)
193 i_assert(pump != NULL);
194 if (pump->io != NULL)
195 pump->io = io_loop_move_io(&pump->io);
196 o_stream_switch_ioloop(pump->output);
197 i_stream_switch_ioloop(pump->input);