ostream-failure-at.c revision 2bee4c37862d33fe09544d865225d140bd533225
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2015 Dovecot authors, see the included COPYING file */
65f8fb656051f1059f7b5a2da9c5555adcc30439Timo Sirainenstatic void o_stream_failure_at_destroy(struct iostream_private *stream)
a64adf62fa33f2463a86f990217b0c9078531a40Timo Siraineno_stream_failure_at_sendv(struct ostream_private *stream,
a64adf62fa33f2463a86f990217b0c9078531a40Timo Sirainen const struct const_iovec *iov, unsigned int iov_count)
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen unsigned int i;
2615df45a8027948a474abe5e817b34b0499c171Timo Sirainen if (fstream->failure_offset <= stream->ostream.offset) {
3e564425db51f3921ce4de11859777135fdedd15Timo Sirainen bytes_until_failure = fstream->failure_offset - stream->ostream.offset;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen iov_dup = i_new(struct const_iovec, iov_count);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen for (i = 0; i < iov_count; i++) {
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen if (iov_dup[i].iov_len >= bytes_until_failure) {
e5fd6dfd0a492e4708d4dbb7971d7fc5d7b8fd85Timo Sirainen ret = o_stream_sendv(stream->parent, iov_dup, iov_dup_count);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Siraineno_stream_failure_at_flush(struct ostream_private *stream)
f1743785713e7632459d623d5df2108f4b93accbTimo Siraineno_stream_create_failure_at(struct ostream *output, uoff_t failure_offset,
8d630c15a8ed6f85553467c3a231a273defca5f6Timo Sirainen fstream = i_new(struct failure_at_ostream, 1);
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fstream->ostream.sendv = o_stream_failure_at_sendv;
ee116df08d0fdab703483e18fe8076b2ef9fd9d7Timo Sirainen fstream->ostream.flush = o_stream_failure_at_flush;
c5ab90cfad9cc3e33bcb1baeb30ffc82a7b7053aTimo Sirainen fstream->ostream.iostream.destroy = o_stream_failure_at_destroy;
fdc557286bc9f92c5f3bb49096ff6e2bcec0ea79Timo Sirainen fstream->error_string = i_strdup(error_string);
8e371a3ce32bd64288786855b8ce0cb63f19f7d1Timo Sirainen return o_stream_create(&fstream->ostream, output,
b9f564d00b7a115f465ffd6840341c7b8f9bfc8aTimo Siraineno_stream_create_failure_at_flush(struct ostream *output, const char *error_string)
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen fstream = i_new(struct failure_at_ostream, 1);
6ef7e31619edfaa17ed044b45861d106a86191efTimo Sirainen fstream->ostream.flush = o_stream_failure_at_flush;
0cb2e8eb55e70f8ebe1e8349bdf49e4cbe5d8834Timo Sirainen fstream->ostream.iostream.destroy = o_stream_failure_at_destroy;
a2f250a332dfc1e6cd4ffd196c621eb9dbf7b8a1Timo Sirainen fstream->error_string = i_strdup(error_string);