r1683 - trunk/varnish-cache/bin/varnishd

phk at projects.linpro.no phk at projects.linpro.no
Fri Jul 13 09:21:46 CEST 2007


Author: phk
Date: 2007-07-13 09:21:46 +0200 (Fri, 13 Jul 2007)
New Revision: 1683

Modified:
   trunk/varnish-cache/bin/varnishd/cache.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor.c
   trunk/varnish-cache/bin/varnishd/cache_acceptor.h
   trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c
   trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
   trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c
Log:
Unify the recycle functionality of the acceptors, all three used the same
method.



Modified: trunk/varnish-cache/bin/varnishd/cache.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache.h	2007-07-13 07:11:54 UTC (rev 1682)
+++ trunk/varnish-cache/bin/varnishd/cache.h	2007-07-13 07:21:46 UTC (rev 1683)
@@ -360,6 +360,7 @@
 void vca_close_session(struct sess *sp, const char *why);
 void VCA_Prep(struct sess *sp);
 void VCA_Init(void);
+extern int vca_pipes[2];
 
 /* cache_backend.c */
 void VBE_Init(void);

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2007-07-13 07:11:54 UTC (rev 1682)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.c	2007-07-13 07:21:46 UTC (rev 1683)
@@ -76,6 +76,8 @@
 
 static unsigned char	need_sndtimeo, need_rcvtimeo, need_linger, need_test;
 
+int vca_pipes[2];
+
 static void
 sock_test(int fd)
 {
@@ -255,7 +257,10 @@
 	CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 	AZ(sp->obj);
 	AZ(sp->vcl);
-	vca_act->recycle(sp);
+	if (sp->fd < 0)
+		SES_Delete(sp);
+	else
+		 assert(sizeof sp == write(vca_pipes[1], &sp, sizeof sp));
 }
 
 
@@ -273,6 +278,7 @@
 		fprintf(stderr, "No acceptor in program\n");
 		exit (2);
 	}
+	AZ(pipe(vca_pipes));
 	vca_act->init();
 	AZ(pthread_create(&vca_thread_acct, NULL, vca_acct, NULL));
 }

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor.h	2007-07-13 07:11:54 UTC (rev 1682)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor.h	2007-07-13 07:21:46 UTC (rev 1683)
@@ -32,12 +32,10 @@
 struct sess;
 
 typedef void acceptor_init_f(void);
-typedef void acceptor_recycle_f(struct sess *);
 
 struct acceptor {
 	const char 		*name;
 	acceptor_init_f		*init;
-	acceptor_recycle_f	*recycle;
 };
 
 #if defined(HAVE_EPOLL_CTL)

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c	2007-07-13 07:11:54 UTC (rev 1682)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_epoll.c	2007-07-13 07:21:46 UTC (rev 1683)
@@ -48,7 +48,6 @@
 
 static pthread_t vca_epoll_thread;
 static int epfd = -1;
-static int pipes[2];
 
 static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
 
@@ -79,12 +78,12 @@
 	epfd = epoll_create(16);
 	assert(epfd >= 0);
 
-	vca_add(pipes[0], pipes);
+	vca_add(vca_pipes[0], vca_pipes);
 
 	while (1) {
 		if (epoll_wait(epfd, &ev, 1, 100) > 0) {
-			if (ev.data.ptr == pipes) {
-				i = read(pipes[0], &sp, sizeof sp);
+			if (ev.data.ptr == vca_pipes) {
+				i = read(vca_pipes[0], &sp, sizeof sp);
 				assert(i == sizeof sp);
 				CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 				TAILQ_INSERT_TAIL(&sesshead, sp, list);
@@ -120,27 +119,15 @@
 /*--------------------------------------------------------------------*/
 
 static void
-vca_epoll_recycle(struct sess *sp)
-{
-
-	if (sp->fd < 0)
-		SES_Delete(sp);
-	else
-		assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
-}
-
-static void
 vca_epoll_init(void)
 {
 
-	AZ(pipe(pipes));
 	AZ(pthread_create(&vca_epoll_thread, NULL, vca_main, NULL));
 }
 
 struct acceptor acceptor_epoll = {
 	.name =		"epoll",
 	.init =		vca_epoll_init,
-	.recycle =	vca_epoll_recycle,
 };
 
 #endif /* defined(HAVE_EPOLL_CTL) */

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c	2007-07-13 07:11:54 UTC (rev 1682)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_kqueue.c	2007-07-13 07:21:46 UTC (rev 1683)
@@ -52,7 +52,6 @@
 static int kq = -1;
 
 static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
-static int pipes[2];
 
 #define NKEV	100
 
@@ -81,9 +80,9 @@
 	struct sess *ss[NKEV];
 
 	AN(kp->udata);
-	if (kp->udata == pipes) {
+	if (kp->udata == vca_pipes) {
 		j = 0;
-		i = read(pipes[0], ss, sizeof ss);
+		i = read(vca_pipes[0], ss, sizeof ss);
 		if (i == -1 && errno == EAGAIN)
 			return;
 		while (i >= sizeof ss[0]) {
@@ -135,7 +134,7 @@
 
 	j = 0;
 	EV_SET(&ke[j++], 0, EVFILT_TIMER, EV_ADD, 0, 100, NULL);
-	EV_SET(&ke[j++], pipes[0], EVFILT_READ, EV_ADD, 0, 0, pipes);
+	EV_SET(&ke[j++], vca_pipes[0], EVFILT_READ, EV_ADD, 0, 0, vca_pipes);
 	AZ(kevent(kq, ke, j, NULL, 0, NULL));
 
 	nki = 0;
@@ -173,24 +172,13 @@
 /*--------------------------------------------------------------------*/
 
 static void
-vca_kqueue_recycle(struct sess *sp)
-{
-
-	if (sp->fd < 0)
-		SES_Delete(sp);
-	else
-		assert(write(pipes[1], &sp, sizeof sp) == sizeof sp);
-}
-
-static void
 vca_kqueue_init(void)
 {
 	int i;
 
-	AZ(pipe(pipes));
-	i = fcntl(pipes[0], F_GETFL);
+	i = fcntl(vca_pipes[0], F_GETFL);
 	i |= O_NONBLOCK;
-	i = fcntl(pipes[0], F_SETFL, i);
+	i = fcntl(vca_pipes[0], F_SETFL, i);
 
 	AZ(pthread_create(&vca_kqueue_thread, NULL, vca_kqueue_main, NULL));
 }
@@ -198,7 +186,6 @@
 struct acceptor acceptor_kqueue = {
 	.name =		"kqueue",
 	.init =		vca_kqueue_init,
-	.recycle =	vca_kqueue_recycle,
 };
 
 #endif /* defined(HAVE_KQUEUE) */

Modified: trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c	2007-07-13 07:11:54 UTC (rev 1682)
+++ trunk/varnish-cache/bin/varnishd/cache_acceptor_poll.c	2007-07-13 07:21:46 UTC (rev 1683)
@@ -51,8 +51,6 @@
 static struct pollfd *pollfd;
 static unsigned npoll;
 
-static int pipes[2];
-
 static TAILQ_HEAD(,sess) sesshead = TAILQ_HEAD_INITIALIZER(sesshead);
 
 /*--------------------------------------------------------------------*/
@@ -109,13 +107,13 @@
 
 	(void)arg;
 
-	vca_poll(pipes[0]);
+	vca_poll(vca_pipes[0]);
 
 	while (1) {
 		v = poll(pollfd, npoll, 100);
-		if (v && pollfd[pipes[0]].revents) {
+		if (v && pollfd[vca_pipes[0]].revents) {
 			v--;
-			i = read(pipes[0], &sp, sizeof sp);
+			i = read(vca_pipes[0], &sp, sizeof sp);
 			assert(i == sizeof sp);
 			CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
 			TAILQ_INSERT_TAIL(&sesshead, sp, list);
@@ -153,26 +151,15 @@
 /*--------------------------------------------------------------------*/
 
 static void
-vca_poll_recycle(struct sess *sp)
-{
-
-	if (sp->fd < 0)
-		SES_Delete(sp);
-	else
-		assert(sizeof sp == write(pipes[1], &sp, sizeof sp));
-}
-
-static void
 vca_poll_init(void)
 {
-	AZ(pipe(pipes));
+
 	AZ(pthread_create(&vca_poll_thread, NULL, vca_main, NULL));
 }
 
 struct acceptor acceptor_poll = {
 	.name =		"poll",
 	.init =		vca_poll_init,
-	.recycle =	vca_poll_recycle,
 };
 
 #endif /* defined(HAVE_POLL) */




More information about the varnish-commit mailing list