From: phk Date: Mon, 26 May 2008 08:38:00 +0000 (+0000) Subject: Add TCP_blocking() and TCP_nonblocking() and use them instead of X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2013a437289e1397e36111823b83c84800fd8f5b;p=varnish Add TCP_blocking() and TCP_nonblocking() and use them instead of fondling fcntl(2) directly. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@2637 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/bin/varnishd/cache_fetch.c b/varnish-cache/bin/varnishd/cache_fetch.c index 34a2ff52..ac523c8b 100644 --- a/varnish-cache/bin/varnishd/cache_fetch.c +++ b/varnish-cache/bin/varnishd/cache_fetch.c @@ -65,9 +65,7 @@ fetch_straight(struct sess *sp, struct http_conn *htc, const char *b) sp->obj->len = cl; p = st->ptr; - i = fcntl(htc->fd, F_GETFL); /* XXX ? */ - i &= ~O_NONBLOCK; - i = fcntl(htc->fd, F_SETFL, i); + TCP_blocking(htc->fd); while (cl > 0) { i = HTC_Read(htc, p, cl); @@ -211,9 +209,7 @@ fetch_eof(struct sess *sp, struct http_conn *htc) struct storage *st; unsigned v; - i = fcntl(htc->fd, F_GETFL); /* XXX ? */ - i &= ~O_NONBLOCK; - i = fcntl(htc->fd, F_SETFL, i); + TCP_blocking(htc->fd); p = NULL; v = 0; diff --git a/varnish-cache/bin/varnishd/common.h b/varnish-cache/bin/varnishd/common.h index 5b21dad5..62dcecd9 100644 --- a/varnish-cache/bin/varnishd/common.h +++ b/varnish-cache/bin/varnishd/common.h @@ -44,5 +44,7 @@ extern struct varnish_stats *VSL_stats; void TCP_name(const struct sockaddr *addr, unsigned l, char *abuf, unsigned alen, char *pbuf, unsigned plen); void TCP_myname(int sock, char *abuf, unsigned alen, char *pbuf, unsigned plen); int TCP_filter_http(int sock); +void TCP_blocking(int sock); +void TCP_nonblocking(int sock); #define TRUST_ME(ptr) ((void*)(uintptr_t)(ptr)) diff --git a/varnish-cache/bin/varnishd/tcp.c b/varnish-cache/bin/varnishd/tcp.c index cb023035..0d1d7d62 100644 --- a/varnish-cache/bin/varnishd/tcp.c +++ b/varnish-cache/bin/varnishd/tcp.c @@ -37,6 +37,7 @@ #include #include +#include #include #include #include @@ -110,3 +111,29 @@ TCP_filter_http(int sock) return (0); #endif } + +/*--------------------------------------------------------------------*/ + +void +TCP_blocking(int sock) +{ + int i; + + i = fcntl(sock, F_GETFL); + assert(i != -1); + i &= ~O_NONBLOCK; + i = fcntl(sock, F_SETFL, i); + assert(i != -1); +} + +void +TCP_nonblocking(int sock) +{ + int i; + + i = fcntl(sock, F_GETFL); + assert(i != -1); + i |= O_NONBLOCK; + i = fcntl(sock, F_SETFL, i); + assert(i != -1); +}