~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/lib/ostream-rawlog.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2011-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2011-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "iostream-rawlog-private.h"
10
10
        struct rawlog_iostream riostream;
11
11
};
12
12
 
13
 
static void o_stream_rawlog_close(struct iostream_private *stream)
 
13
static void o_stream_rawlog_close(struct iostream_private *stream,
 
14
                                  bool close_parent)
14
15
{
15
16
        struct rawlog_ostream *rstream = (struct rawlog_ostream *)stream;
16
17
 
17
 
        o_stream_flush(rstream->ostream.parent);
 
18
        (void)o_stream_flush(rstream->ostream.parent);
18
19
        iostream_rawlog_close(&rstream->riostream);
 
20
 
 
21
        if (close_parent)
 
22
                o_stream_close(rstream->ostream.parent);
19
23
}
20
24
 
21
25
static ssize_t
24
28
{
25
29
        struct rawlog_ostream *rstream = (struct rawlog_ostream *)stream;
26
30
        unsigned int i;
27
 
        ssize_t ret;
28
 
 
29
 
        for (i = 0; i < iov_count; i++) {
30
 
                iostream_rawlog_write(&rstream->riostream,
31
 
                                      iov[i].iov_base, iov[i].iov_len);
32
 
        }
 
31
        ssize_t ret, bytes;
33
32
 
34
33
        if ((ret = o_stream_sendv(stream->parent, iov, iov_count)) < 0) {
35
34
                o_stream_copy_error_from_parent(stream);
36
35
                return -1;
37
36
        }
 
37
        bytes = ret;
 
38
        for (i = 0; i < iov_count && bytes > 0; i++) {
 
39
                if (iov[i].iov_len < (size_t)bytes) {
 
40
                        iostream_rawlog_write(&rstream->riostream,
 
41
                                              iov[i].iov_base, iov[i].iov_len);
 
42
                        bytes -= iov[i].iov_len;
 
43
                } else {
 
44
                        iostream_rawlog_write(&rstream->riostream,
 
45
                                              iov[i].iov_base, bytes);
 
46
                        break;
 
47
                }
 
48
        }
38
49
 
39
50
        stream->ostream.offset += ret;
40
51
        return ret;
42
53
 
43
54
struct ostream *
44
55
o_stream_create_rawlog(struct ostream *output, const char *rawlog_path,
45
 
                       int rawlog_fd, bool autoclose_fd)
 
56
                       int rawlog_fd, enum iostream_rawlog_flags flags)
46
57
{
47
58
        struct rawlog_ostream *rstream;
48
59
 
55
66
 
56
67
        rstream->riostream.rawlog_path = i_strdup(rawlog_path);
57
68
        rstream->riostream.rawlog_fd = rawlog_fd;
58
 
        rstream->riostream.autoclose_fd = autoclose_fd;
59
 
        rstream->riostream.write_timestamp = TRUE;
 
69
        iostream_rawlog_init(&rstream->riostream, flags, FALSE);
60
70
 
61
 
        return o_stream_create(&rstream->ostream, output);
 
71
        return o_stream_create(&rstream->ostream, output, -1);
62
72
}