]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Allow limiting of read(2) operations in SBuf I/O API
authorAmos Jeffries <squid3@treenet.co.nz>
Tue, 11 Nov 2014 13:37:41 +0000 (05:37 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Tue, 11 Nov 2014 13:37:41 +0000 (05:37 -0800)
If params.size is non-zero limit size of the read to either the buffer
free space or params.size, whichever is smallest.

src/comm/Read.cc
src/comm/Read.h

index b881adc5ada811ebd9b28aecfb5c525fe7de8093..58d2c8d86420cf26219cfae9d2af06c1caeefb66 100644 (file)
@@ -82,7 +82,9 @@ Comm::ReadNow(CommIoCbParams &params, 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);
index 90cb7560fd4db1008ea609c836f9bafdef227062..dfc78237351a8acd3a2d1449a10f1283280a15fd 100644 (file)
@@ -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