Commit d537633b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Add TCP_blocking() and TCP_nonblocking() and use them instead of

fondling fcntl(2) directly.


git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@2637 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 3750fe22
......@@ -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;
......
......@@ -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))
......@@ -37,6 +37,7 @@
#include <netinet/in.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment