]> err.no Git - varnish/commitdiff
Add vca_write() and vca_flush(), two functions which will attempt to
authorphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 1 May 2006 12:45:20 +0000 (12:45 +0000)
committerphk <phk@d4fa192b-c00b-0410-8231-f00ffab90ce4>
Mon, 1 May 2006 12:45:20 +0000 (12:45 +0000)
use writev() if possible.

vca_flush() must be called before any memory previosly given to
vca_write is overwritten, and after the last call to vca_write()

git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@164 d4fa192b-c00b-0410-8231-f00ffab90ce4

varnish-cache/bin/varnishd/cache.h
varnish-cache/bin/varnishd/cache_acceptor.c

index 9d7dc4002e020c2ebc4022098afd6c0758abc18c..379caf45da45e85d91334b3f7ad64d51382ca110 100644 (file)
@@ -63,6 +63,8 @@ extern struct stevedore *stevedore;
 
 
 /* cache_acceptor.c */
+void vca_write(struct sess *sp, void *ptr, size_t len);
+void vca_flush(struct sess *sp);
 void *vca_main(void *arg);
 void vca_retire_session(struct sess *sp);
 void vca_recycle_session(struct sess *sp);
index fb6fae040d2f65e3ad535023196f5265ee1de44a..4e276b766d28cf023a4b0e9d49d215c777207d92 100644 (file)
@@ -12,6 +12,7 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#include <sys/uio.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 
@@ -32,13 +33,60 @@ static struct event_base *evb;
 static struct event pipe_e;
 static int pipes[2];
 
+#define SESS_IOVS      5
+
 static struct event accept_e[2 * HERITAGE_NSOCKS];
 
 struct sessmem {
        struct sess     s;
        struct event    e;
+       struct iovec    iov[SESS_IOVS];
+       int             niov;
+       size_t          liov;
 };
 
+/*--------------------------------------------------------------------
+ * Write data to client
+ * We try to use writev() if possible in order to minimize number of
+ * syscalls made and packets sent.  It also just might allow the worker
+ * thread to complete the request without holding stuff locked.
+ */
+
+void
+vca_flush(struct sess *sp)
+{
+       int i;
+
+       if (sp->fd < 0 || sp->mem->niov == 0)
+               return;
+       i = writev(sp->fd, sp->mem->iov, sp->mem->niov);
+       if (i != sp->mem->liov) {
+               VSL(SLT_SessionClose, sp->fd, "Premature %d of %d",
+                   i,  sp->mem->liov);
+               close(sp->fd);
+               sp->fd = -1;
+       }
+       sp->mem->liov = 0;
+       sp->mem->niov = 0;
+}
+
+void
+vca_write(struct sess *sp, void *ptr, size_t len)
+{
+
+       if (sp->fd < 0 || len == 0)
+               return;
+       if (sp->mem->niov == SESS_IOVS)
+               vca_flush(sp);
+       if (sp->fd < 0)
+               return;
+       sp->mem->iov[sp->mem->niov].iov_base = ptr;
+       sp->mem->iov[sp->mem->niov++].iov_len = len;
+       sp->mem->liov += len;
+}
+
+/*--------------------------------------------------------------------*/
+
 static void
 pipe_f(int fd, short event, void *arg)
 {