--------------------- PatchSet 10316 Date: 2007/12/26 16:02:50 Author: adri Branch: s27_adri Tag: (none) Log: Add a simple function to populate a membuf from a filedescriptor read(). It'll be useful in the near future in http.c. Members: src/MemBuf.c:1.11->1.11.26.1 src/protos.h:1.146.2.4.4.30->1.146.2.4.4.31 Index: squid/src/MemBuf.c =================================================================== RCS file: /cvsroot/squid-sf//squid/src/MemBuf.c,v retrieving revision 1.11 retrieving revision 1.11.26.1 diff -u -r1.11 -r1.11.26.1 --- squid/src/MemBuf.c 16 Aug 2006 00:53:02 -0000 1.11 +++ squid/src/MemBuf.c 26 Dec 2007 16:02:50 -0000 1.11.26.1 @@ -1,6 +1,6 @@ /* - * $Id: MemBuf.c,v 1.11 2006/08/16 00:53:02 squidadm Exp $ + * $Id: MemBuf.c,v 1.11.26.1 2007/12/26 16:02:50 adri Exp $ * * DEBUG: section 59 auto-growing Memory Buffer with printf * AUTHOR: Alex Rousskov @@ -297,6 +297,21 @@ return ff; } +int +memBufFill(MemBuf *mb, int fd) +{ + int ret; + + memBufGrow(mb, mb->size + 8192); + + ret = FD_READ_METHOD(fd, mb->buf + mb->size, mb->capacity - mb->size - 1); + if (ret > 0) { + mb->size += ret; + mb->buf[mb->size] = '\0'; + } + return ret; +} + /* grows (doubles) internal buffer to satisfy required minimal capacity */ static void memBufGrow(MemBuf * mb, mb_size_t min_cap) Index: squid/src/protos.h =================================================================== RCS file: /cvsroot/squid-sf//squid/src/protos.h,v retrieving revision 1.146.2.4.4.30 retrieving revision 1.146.2.4.4.31 diff -u -r1.146.2.4.4.30 -r1.146.2.4.4.31 --- squid/src/protos.h 22 Dec 2007 14:32:13 -0000 1.146.2.4.4.30 +++ squid/src/protos.h 26 Dec 2007 16:02:50 -0000 1.146.2.4.4.31 @@ -1,6 +1,6 @@ /* - * $Id: protos.h,v 1.146.2.4.4.30 2007/12/22 14:32:13 adri Exp $ + * $Id: protos.h,v 1.146.2.4.4.31 2007/12/26 16:02:50 adri Exp $ * * * SQUID Web Proxy Cache http://www.squid-cache.org/ @@ -628,6 +628,7 @@ extern FREE *memBufFreeFunc(MemBuf * mb); /* puts report on MemBuf _module_ usage into mb */ extern void memBufReport(MemBuf * mb); +extern int memBufFill(MemBuf *mb, int fd); extern char *mime_get_header(const char *mime, const char *header); extern char *mime_get_header_field(const char *mime, const char *name, const char *prefix);