Mailing List Archive

r60 - trunk/varnish-cache/bin/varnishd
Author: phk
Date: 2006-03-23 09:45:44 +0100 (Thu, 23 Mar 2006)
New Revision: 60

Added:
trunk/varnish-cache/bin/varnishd/tcp.c
Modified:
trunk/varnish-cache/bin/varnishd/Makefile.am
trunk/varnish-cache/bin/varnishd/heritage.h
trunk/varnish-cache/bin/varnishd/mgt.h
trunk/varnish-cache/bin/varnishd/varnishd.c
Log:
Open TCP sockets


Modified: trunk/varnish-cache/bin/varnishd/Makefile.am
===================================================================
--- trunk/varnish-cache/bin/varnishd/Makefile.am 2006-03-17 13:41:32 UTC (rev 59)
+++ trunk/varnish-cache/bin/varnishd/Makefile.am 2006-03-23 08:45:44 UTC (rev 60)
@@ -8,6 +8,7 @@
cache_main.c \
cli_event.c \
mgt_child.c \
+ tcp.c \
varnishd.c

varnishd_LDADD = \

Modified: trunk/varnish-cache/bin/varnishd/heritage.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/heritage.h 2006-03-17 13:41:32 UTC (rev 59)
+++ trunk/varnish-cache/bin/varnishd/heritage.h 2006-03-23 08:45:44 UTC (rev 60)
@@ -5,7 +5,21 @@
*/

struct heritage {
+
+ /*
+ * Two pipe(2)'s for CLI connection between cache and mgt.
+ * cache reads [2] and writes [1]. Mgt reads [0] and writes [3].
+ */
int fds[4];
+
+ /*
+ * Two sockets from which to accept connections, one bound to
+ * loopback only and one bound for wildcard (or possibly a specific
+ * interface IP number).
+ */
+#define HERITAGE_NSOCKS 2 /* IPv4 + IPv6 */
+ int sock_local[HERITAGE_NSOCKS];
+ int sock_remote[HERITAGE_NSOCKS];
};

extern struct heritage heritage;

Modified: trunk/varnish-cache/bin/varnishd/mgt.h
===================================================================
--- trunk/varnish-cache/bin/varnishd/mgt.h 2006-03-17 13:41:32 UTC (rev 59)
+++ trunk/varnish-cache/bin/varnishd/mgt.h 2006-03-23 08:45:44 UTC (rev 60)
@@ -10,3 +10,6 @@

typedef void mgt_ccb_f(unsigned, const char *, void *);
void mgt_child_request(mgt_ccb_f *, void *, char **argv, const char *fmt, ...);
+
+/* tcp.c */
+int open_tcp(const char *port);

Added: trunk/varnish-cache/bin/varnishd/tcp.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/tcp.c 2006-03-17 13:41:32 UTC (rev 59)
+++ trunk/varnish-cache/bin/varnishd/tcp.c 2006-03-23 08:45:44 UTC (rev 60)
@@ -0,0 +1,66 @@
+/*
+ * $Id$
+ */
+
+#include <string.h>
+#include <assert.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netdb.h>
+
+#include "heritage.h"
+
+static void
+create_listen_socket(const char *addr, const char *port, int *sp, int nsp)
+{
+ struct addrinfo ai, *r0, *r1;
+ int i, j, s;
+
+ memset(&ai, 0, sizeof ai);
+ ai.ai_family = PF_UNSPEC;
+ ai.ai_socktype = SOCK_STREAM;
+ ai.ai_flags = AI_PASSIVE;
+ i = getaddrinfo(addr, port, &ai, &r0);
+
+ if (i) {
+ fprintf("getaddrinfo failed: %s\n", gai_strerror(i));
+ return;
+ }
+
+ for (r1 = r0; r1 != NULL && nsp > 0; r1 = r1->ai_next) {
+ s = socket(r1->ai_family, r1->ai_socktype, r1->ai_protocol);
+ if (s < 0)
+ continue;
+ j = 1;
+ i = setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &j, sizeof j);
+ assert(i == 0);
+
+ i = bind(s, r1->ai_addr, r1->ai_addrlen);
+ assert(i == 0);
+ *sp = s;
+ sp++;
+ nsp--;
+ }
+
+ freeaddrinfo(r0);
+}
+
+int
+open_tcp(const char *port)
+{
+ unsigned u;
+
+ for (u = 0; u < HERITAGE_NSOCKS; u++) {
+ heritage.sock_local[u] = -1;
+ heritage.sock_remote[u] = -1;
+ }
+
+ create_listen_socket("localhost", port,
+ &heritage.sock_local[0], HERITAGE_NSOCKS);
+
+ create_listen_socket(NULL, port,
+ &heritage.sock_remote[0], HERITAGE_NSOCKS);
+
+ return (0);
+}

Modified: trunk/varnish-cache/bin/varnishd/varnishd.c
===================================================================
--- trunk/varnish-cache/bin/varnishd/varnishd.c 2006-03-17 13:41:32 UTC (rev 59)
+++ trunk/varnish-cache/bin/varnishd/varnishd.c 2006-03-23 08:45:44 UTC (rev 60)
@@ -169,6 +169,9 @@

/*--------------------------------------------------------------------*/

+/* for development purposes */
+#include <printf.h>
+
int
main(int argc, char *argv[])
{
@@ -176,6 +179,10 @@
unsigned portnumber = 8080;
unsigned dflag = 1; /* XXX: debug=on for now */

+ register_printf_render_std((const unsigned char *)"HVQ");
+
+ open_tcp("8080");
+
while ((o = getopt(argc, argv, "dp:")) != -1)
switch (o) {
case 'd':