From: Amos Jeffries Date: Tue, 11 Nov 2014 13:37:41 +0000 (-0800) Subject: Allow limiting of read(2) operations in SBuf I/O API X-Git-Tag: merge-candidate-3-v1~240^2~19 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=983de17ba395ac4366eac1fe2dbce8eb7694aba5;p=thirdparty%2Fsquid.git Allow limiting of read(2) operations in SBuf I/O API If params.size is non-zero limit size of the read to either the buffer free space or params.size, whichever is smallest. --- diff --git a/src/comm/Read.cc b/src/comm/Read.cc index b881adc5ad..58d2c8d864 100644 --- a/src/comm/Read.cc +++ b/src/comm/Read.cc @@ -82,7 +82,9 @@ Comm::ReadNow(CommIoCbParams ¶ms, SBuf &buf) { /* Attempt a read */ ++ statCounter.syscalls.sock.reads; - const SBuf::size_type sz = buf.spaceSize(); + SBuf::size_type sz = buf.spaceSize(); + if (params.size > 0 && params.size < sz) + sz = params.size; char *inbuf = buf.rawSpace(sz); errno = 0; const int retval = FD_READ_METHOD(params.conn->fd, inbuf, sz); diff --git a/src/comm/Read.h b/src/comm/Read.h index 90cb7560fd..dfc7823735 100644 --- a/src/comm/Read.h +++ b/src/comm/Read.h @@ -32,6 +32,9 @@ bool MonitorsRead(int fd); /** * Perform a read(2) on a connection immediately. * + * If params.size is non-zero will limit size of the read to either + * the buffer free space or params.size, whichever is smallest. + * * The returned flag is also placed in params.flag. * * \retval Comm::OK data has been read and placed in buf, amount in params.size