diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-15 15:09:53 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-06-15 15:09:53 +0300 |
commit | 8535eb69257ab1212fc2dc8a6c1f98e68612e397 (patch) | |
tree | 7ed7224caed54831b2f71bb01518bb897a5d370f | |
parent | aeebcf6ba6349c859b567595ed706e6af95a7e52 (diff) | |
download | smap-8535eb69257ab1212fc2dc8a6c1f98e68612e397.tar.gz smap-8535eb69257ab1212fc2dc8a6c1f98e68612e397.tar.bz2 |
Fix handling of very long queries/replies.
* lib/sockmapstr.c (smap_sockmap_stream_create2): Set
SMAP_STREAM_EXPBUF on input buffer.
* lib/stream.c (_force_flush_buffer): New static.
(_stream_flush_buffer): Handle expandable buffers for
line-buffered streams.
-rw-r--r-- | lib/sockmapstr.c | 1 | ||||
-rw-r--r-- | lib/stream.c | 33 |
2 files changed, 24 insertions, 10 deletions
diff --git a/lib/sockmapstr.c b/lib/sockmapstr.c index 16ccbe3..dffe4c8 100644 --- a/lib/sockmapstr.c +++ b/lib/sockmapstr.c @@ -505,6 +505,7 @@ smap_sockmap_stream_create2(smap_stream_t *pstream, int fd[], int flags) smap_stream_set_buffer(str->out, smap_buffer_line, 1024); smap_stream_set_flags(str->out, SMAP_STREAM_EXPBUF); smap_stream_set_buffer(str->in, smap_buffer_full, 1024); + smap_stream_set_flags(str->in, SMAP_STREAM_EXPBUF); str->base.read = _sockmap_stream_read; str->base.write = _sockmap_stream_write; diff --git a/lib/stream.c b/lib/stream.c index 4ec380d..7daa6a7 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -171,6 +171,18 @@ _stream_buffer_full_p(struct _smap_stream *stream) } static int +_force_flush_buffer(struct _smap_stream *stream) +{ + int rc = smap_stream_write_unbuffered(stream, + stream->cur, + stream->level, + 1, NULL); + if (rc == 0) + _stream_advance_buffer(stream, stream->level); + return rc; +} + +static int _stream_flush_buffer(struct _smap_stream *stream, int all) { int rc; @@ -211,18 +223,19 @@ _stream_flush_buffer(struct _smap_stream *stream, int all) return rc; _stream_advance_buffer(stream, size); } - if ((all && stream->level) || BUFFER_FULL_P(stream)) { - rc = smap_stream_write_unbuffered(stream, - stream->cur, - stream->level, - 1, NULL); - if (rc) - return rc; - _stream_advance_buffer(stream, stream->level); + if (stream->level) { + if (all) { + if (rc = _force_flush_buffer(stream)) + return rc; + } else if (BUFFER_FULL_P(stream)) { + if (stream->flags & SMAP_STREAM_EXPBUF) + return _stream_realloc_buffer(stream, 0); + if (rc = _force_flush_buffer(stream)) + return rc; + } } } - } - else if (all) + } else if (all) _stream_advance_buffer(stream, stream->level); if (stream->level) { |