Revision: 14899
Author:   adrian.chadd
Date:     Sun Jul 10 06:19:10 2011
Log: Migrate the neighbor health check code to use the new connect framework.


http://code.google.com/p/lusca-cache/source/detail?r=14899

Modified:
 /playpen/LUSCA_HEAD_ipv6/src/cache_cf.c
 /playpen/LUSCA_HEAD_ipv6/src/neighbors.c
 /playpen/LUSCA_HEAD_ipv6/src/structs.h

=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/cache_cf.c     Sun Jul 10 02:23:22 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/cache_cf.c     Sun Jul 10 06:19:10 2011
@@ -1911,7 +1911,7 @@
        p->connect_fail_limit = 1;
     p->tcp_up = p->connect_fail_limit;
     p->icp.version = ICP_VERSION_CURRENT;
-    p->test_fd = -1;
+    p->test_fd_pending = 0;
 #if USE_CACHE_DIGESTS
     if (!p->options.no_digest) {
        p->digest = peerDigestCreate(p);
=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/neighbors.c    Sun Jul 10 02:54:48 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/neighbors.c    Sun Jul 10 06:19:10 2011
@@ -36,6 +36,8 @@
 #include "squid.h"
 #include "icmp.h"

+#include "comm2.h"
+
 #include "../libsqurl/domain.h"

 /* count mcast group peers every 15 minutes */
@@ -1150,8 +1152,9 @@
 peerProbeConnectTimeout(int fd, void *data)
 {
     peer *p = data;
-    comm_close(fd);
-    p->test_fd = -1;
+    if (fd != -1)
+        comm_close(fd);
+    p->test_fd_pending = 0;
     peerConnectFailedSilent(p);
 }

@@ -1161,27 +1164,34 @@
 static int
 peerProbeConnect(peer * p)
 {
-    int fd;
     time_t ctimeout = p->connect_timeout > 0 ? p->connect_timeout
     : Config.Timeout.peer_connect;
int ret = squid_curtime - p->stats.last_connect_failure > ctimeout * 10;
-    if (p->test_fd != -1)
+    struct in_addr outgoing_v4;
+    sqaddr_t outgoing_v6;
+    ConnectStateDataNew *cs;
+
+    if (p->test_fd_pending == 1)
        return ret;             /* probe already running */
     if (squid_curtime - p->stats.last_connect_probe == 0)
        return ret;             /* don't probe to often */
-    fd = comm_open(SOCK_STREAM, IPPROTO_TCP, getOutgoingAddr(NULL),
-       0, COMM_NONBLOCKING, COMM_TOS_DEFAULT, p->name);
-    if (fd < 0)
-       return ret;
-    commSetTimeout(fd, ctimeout, peerProbeConnectTimeout, p);
-    p->test_fd = fd;
+
+    outgoing_v4 = getOutgoingAddr(NULL);
+    sqinet_init(&outgoing_v6);
+    getOutgoingAddrV6(NULL, &outgoing_v6);
+
+    p->test_fd_pending = 1;
     p->stats.last_connect_probe = squid_curtime;
-    commConnectStart(p->test_fd,
-       p->host,
-       p->http_port,
-       peerProbeConnectDone,
-       p,
-       NULL);
+
+    cs = commConnectStartNewSetup(p->host, p->http_port,
+      peerProbeConnectDone, p, NULL, 0, NULL);
+
+    commConnectNewSetupOutgoingV4(cs, outgoing_v4);
+    commConnectNewSetupOutgoingV6(cs, &outgoing_v6);
+    commConnectNewSetTimeout(cs, ctimeout);
+    commConnectStartNewBegin(cs);
+    sqinet_done(&outgoing_v6);
+
     return ret;
 }

@@ -1189,13 +1199,20 @@
 peerProbeConnectDone(int fd, int status, void *data)
 {
     peer *p = data;
+
+    p->test_fd_pending = 0;
+
+    if (status == COMM_TIMEOUT) {
+        peerProbeConnectTimeout(fd, p);
+        return;
+    }
+
     if (status == COMM_OK) {
        peerConnectSucceded(p);
     } else {
        peerConnectFailedSilent(p);
     }
     comm_close(fd);
-    p->test_fd = -1;
     return;
 }

=======================================
--- /playpen/LUSCA_HEAD_ipv6/src/structs.h      Sun Jul 10 02:19:03 2011
+++ /playpen/LUSCA_HEAD_ipv6/src/structs.h      Sun Jul 10 06:19:10 2011
@@ -1255,7 +1255,7 @@
     int n_addresses;
     int rr_count;
     peer *next;
-    int test_fd;
+    int test_fd_pending;
     struct {
        unsigned int hash;
        double load_multiplier;

--
You received this message because you are subscribed to the Google Groups 
"lusca-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/lusca-commit?hl=en.

Reply via email to