Mercurial > dovecot > original-hg > dovecot-1.2
changeset 15:e01bf167b27c HEAD
message_send() buffers data now instead of making lots of write() calls, so
it should be faster.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 23 Aug 2002 01:01:10 +0300 |
parents | af70462f5ca1 |
children | 3de6ef1b50cb |
files | src/lib-mail/message-send.c src/lib-mail/message-send.h |
diffstat | 2 files changed, 38 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-mail/message-send.c Thu Aug 22 20:59:45 2002 +0300 +++ b/src/lib-mail/message-send.c Fri Aug 23 01:01:10 2002 +0300 @@ -5,20 +5,23 @@ #include "message-send.h" #include "message-size.h" +#define OUTPUT_BUFFER_SIZE 1024 + int message_send(IOBuffer *outbuf, IOBuffer *inbuf, MessageSize *msg_size, off_t virtual_skip, off_t max_virtual_size) { - unsigned char *msg; - unsigned int i, size; + unsigned char *msg, *buf; + unsigned int i, size, pos; int cr_skipped, add_cr; + if (msg_size->physical_size == 0 || + virtual_skip >= (off_t)msg_size->virtual_size) + return TRUE; + if (max_virtual_size == -1 || max_virtual_size > (off_t)msg_size->virtual_size - virtual_skip) max_virtual_size = msg_size->virtual_size - virtual_skip; - if (msg_size->physical_size == 0 || virtual_skip >= max_virtual_size) - return TRUE; - if (msg_size->physical_size == msg_size->virtual_size) { /* no need to kludge with CRs, we can use sendfile() */ io_buffer_skip(inbuf, virtual_skip); @@ -28,6 +31,10 @@ message_skip_virtual(inbuf, virtual_skip, NULL, &cr_skipped); /* go through the message data and insert CRs where needed. */ + buf = io_buffer_get_space(outbuf, OUTPUT_BUFFER_SIZE); + i_assert(buf != NULL); + + pos = 0; while (io_buffer_read_data(inbuf, &msg, &size, 0) >= 0) { add_cr = FALSE; for (i = 0; i < size; i++) { @@ -51,15 +58,30 @@ } } - /* send the data read so far */ - if (io_buffer_send(outbuf, msg, i) <= 0) - return FALSE; + if (pos + i >= OUTPUT_BUFFER_SIZE) { + /* buffer is full, flush it */ + if (io_buffer_send_buffer(outbuf, pos) <= 0) + return FALSE; + pos = 0; + } + + if (i >= OUTPUT_BUFFER_SIZE) { + /* data larger than buffer, send it directly */ + if (io_buffer_send(outbuf, msg, i) <= 0) + return FALSE; - if (add_cr) { - if (io_buffer_send(outbuf, "\r", 1) <= 0) - return FALSE; + i_assert(pos == 0); + } else { + /* put the data into buffer */ + memcpy(buf + pos, msg, i); + pos += i; + + i_assert(pos < OUTPUT_BUFFER_SIZE); } + if (add_cr) + buf[pos++] = '\r'; + /* see if we've reached the limit */ if (max_virtual_size == 0) break; @@ -68,5 +90,8 @@ io_buffer_skip(inbuf, i); } + if (io_buffer_send_buffer(outbuf, pos) <= 0) + return FALSE; + return TRUE; }
--- a/src/lib-mail/message-send.h Thu Aug 22 20:59:45 2002 +0300 +++ b/src/lib-mail/message-send.h Fri Aug 23 01:01:10 2002 +0300 @@ -4,8 +4,8 @@ #include "message-parser.h" /* Send message to client inserting CRs if needed. If max_virtual_size is - not negative, only that much of the message is sent. If msg_fd is -1, only - msg is used. Returns TRUE if successful. */ + not negative, only that much of the message is sent (relative to + virtual_skip). Returns TRUE if successful. */ int message_send(IOBuffer *outbuf, IOBuffer *inbuf, MessageSize *msg_size, off_t virtual_skip, off_t max_virtual_size);