[dovecot-cvs] dovecot/src/lib ostream-crlf.c, 1.9,
1.10 ostream-file.c, 1.46, 1.47 ostream-internal.h, 1.4,
1.5 ostream.c, 1.11, 1.12 ostream.h, 1.10, 1.11
cras at dovecot.org
cras at dovecot.org
Tue Apr 26 13:43:59 EEST 2005
Update of /var/lib/cvs/dovecot/src/lib
In directory talvi:/tmp/cvs-serv16222/lib
Modified Files:
ostream-crlf.c ostream-file.c ostream-internal.h ostream.c
ostream.h
Log Message:
o_stream_uncork() was previously always setting IO_WRITE handler even if
there was no reason for it. This was relied on in imap/pop3 code when a
handler could just send as much data as it can without actually buffering
anything.
So, removed the IO_WRITE handler forcing. It's only set if there's actually
data in buffer or if flush_pending is set (via o_stream_set_flush_pending()
or by returning 0 from flush callback handler).
All in all, a minor optimization.
Index: ostream-crlf.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream-crlf.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- ostream-crlf.c 16 Dec 2004 01:37:14 -0000 1.9
+++ ostream-crlf.c 26 Apr 2005 10:43:57 -0000 1.10
@@ -55,6 +55,13 @@
return o_stream_flush(cstream->output);
}
+static void _flush_pending(struct _ostream *stream, int set)
+{
+ struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
+
+ o_stream_set_flush_pending(cstream->output, set);
+}
+
static size_t _get_used_size(struct _ostream *stream)
{
struct crlf_ostream *cstream = (struct crlf_ostream *)stream;
@@ -352,6 +359,7 @@
cstream->ostream.cork = _cork;
cstream->ostream.flush = _flush;
+ cstream->ostream.flush_pending = _flush_pending;
cstream->ostream.get_used_size = _get_used_size;
cstream->ostream.seek = _seek;
cstream->ostream.send_istream = _send_istream;
Index: ostream-file.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream-file.c,v
retrieving revision 1.46
retrieving revision 1.47
diff -u -d -r1.46 -r1.47
--- ostream-file.c 29 Mar 2005 10:28:07 -0000 1.46
+++ ostream-file.c 26 Apr 2005 10:43:57 -0000 1.47
@@ -45,6 +45,7 @@
unsigned int full:1; /* if head == tail, is buffer empty or full? */
unsigned int file:1;
unsigned int corked:1;
+ unsigned int flush_pending:1;
unsigned int no_socket_cork:1;
unsigned int no_sendfile:1;
unsigned int autoclose_fd:1;
@@ -226,10 +227,12 @@
if (set && fstream->io != NULL) {
io_remove(fstream->io);
fstream->io = NULL;
- } else if (!set && fstream->io == NULL) {
+ } else if (!set) {
if (fstream->file)
buffer_flush(fstream);
- else {
+ else if (fstream->io == NULL &&
+ (!IS_STREAM_EMPTY(fstream) ||
+ fstream->flush_pending)) {
fstream->io = io_add(fstream->fd, IO_WRITE,
stream_send_io, fstream);
}
@@ -244,6 +247,17 @@
return buffer_flush(fstream);
}
+static void _flush_pending(struct _ostream *stream, int set)
+{
+ struct file_ostream *fstream = (struct file_ostream *) stream;
+
+ fstream->flush_pending = set;
+ if (set && !fstream->corked && fstream->io == NULL) {
+ fstream->io = io_add(fstream->fd, IO_WRITE,
+ stream_send_io, fstream);
+ }
+}
+
static size_t get_unused_space(struct file_ostream *fstream)
{
if (fstream->head > fstream->tail) {
@@ -347,6 +361,8 @@
io_remove(fstream->io);
fstream->io = NULL;
}
+ fstream->flush_pending = ret <= 0;
+
o_stream_unref(&fstream->ostream.ostream);
}
@@ -711,6 +727,7 @@
fstream->ostream.cork = _cork;
fstream->ostream.flush = _flush;
+ fstream->ostream.flush_pending = _flush_pending;
fstream->ostream.get_used_size = _get_used_size;
fstream->ostream.seek = _seek;
fstream->ostream.sendv = _sendv;
Index: ostream-internal.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream-internal.h,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -d -r1.4 -r1.5
--- ostream-internal.h 20 Oct 2004 17:07:32 -0000 1.4
+++ ostream-internal.h 26 Apr 2005 10:43:57 -0000 1.5
@@ -11,6 +11,7 @@
/* methods: */
void (*cork)(struct _ostream *stream, int set);
int (*flush)(struct _ostream *stream);
+ void (*flush_pending)(struct _ostream *stream, int set);
size_t (*get_used_size)(struct _ostream *stream);
int (*seek)(struct _ostream *stream, uoff_t offset);
ssize_t (*sendv)(struct _ostream *stream, const struct const_iovec *iov,
Index: ostream.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- ostream.c 20 Oct 2004 17:07:32 -0000 1.11
+++ ostream.c 26 Apr 2005 10:43:57 -0000 1.12
@@ -66,6 +66,13 @@
return _stream->flush(_stream);
}
+void o_stream_set_flush_pending(struct ostream *stream, int set)
+{
+ struct _ostream *_stream = stream->real_stream;
+
+ _stream->flush_pending(_stream, set);
+}
+
size_t o_stream_get_buffer_used_size(struct ostream *stream)
{
struct _ostream *_stream = stream->real_stream;
Index: ostream.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib/ostream.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- ostream.h 20 Oct 2004 17:07:32 -0000 1.10
+++ ostream.h 26 Apr 2005 10:43:57 -0000 1.11
@@ -46,6 +46,9 @@
/* Flush the output stream, blocks until everything is sent.
Returns 1 if ok, -1 if error. */
int o_stream_flush(struct ostream *stream);
+/* Set "flush pending" state of stream. If set, the flush callback is called
+ when more data is allowed to be sent, even if the buffer itself is empty. */
+void o_stream_set_flush_pending(struct ostream *stream, int set);
/* Returns number of bytes currently in buffer. */
size_t o_stream_get_buffer_used_size(struct ostream *stream);
More information about the dovecot-cvs
mailing list