chiark / gitweb /
Merge branch 'master' of login.chiark.greenend.org.uk:public-git/inn-innduct
authorIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 30 Apr 2010 23:25:38 +0000 (00:25 +0100)
committerIan Jackson <ian@liberator.relativity.greenend.org.uk>
Fri, 30 Apr 2010 23:25:38 +0000 (00:25 +0100)
backends/innduct.c

index 3225a897963bf40cbc4ba84441f26c8b2d0cfef1..b08205ca4156681b9404caa0590f8579bf946138 100644 (file)
@@ -1709,15 +1709,18 @@ static void *peer_rd_ok(oop_source *lp, oop_read *oread, oop_rd_event ev,
     return OOP_CONTINUE;
   }
 
+  int conn_busy=
+    conn->waiting.count ||
+    conn->priority.count ||
+    conn->sent.count ||
+    conn->xmitu;
+
   if (conn->quitting) {
     if (code!=205 && code!=503) {
       connfail(conn, "peer gave unexpected response to QUIT: %s", sani);
     } else {
-      notice("C%d idle connection closed", conn->fd);
-      assert(!conn->waiting.count);
-      assert(!conn->priority.count);
-      assert(!conn->sent.count);
-      assert(!conn->xmitu);
+      notice("C%d idle connection closed by us", conn->fd);
+      assert(!conn_busy);
       LIST_REMOVE(conns,conn);
       conn_dispose(conn);
     }
@@ -1727,25 +1730,36 @@ static void *peer_rd_ok(oop_source *lp, oop_read *oread, oop_rd_event ev,
   conn->since_activity= 0;
   Article *art;
 
-#define GET_ARTICLE(musthavesent)                                          \
-  art= article_reply_check(conn, data, code_streaming, musthavesent, sani); \
-  if (art) ; else return OOP_CONTINUE /* reply_check has failed the conn */
+#define GET_ARTICLE(musthavesent) do{                                        \
+    art= article_reply_check(conn, data, code_streaming, musthavesent, sani); \
+    if (!art) return OOP_CONTINUE; /* reply_check has failed the conn */      \
+  }while(0) 
 
-#define ARTICLE_DEALTWITH(streaming,musthavesent,how)          \
-  code_streaming= (streaming);                                 \
-  GET_ARTICLE(musthavesent);                                   \
-  article_done(conn, art, RC_##how);  break;
+#define ARTICLE_DEALTWITH(streaming,musthavesent,how) do{      \
+    code_streaming= (streaming);                               \
+    GET_ARTICLE(musthavesent);                                 \
+    article_done(conn, art, RC_##how);                         \
+    goto dealtwith;                                            \
+  }while(0)
 
-#define PEERBADMSG(m) connfail(conn, m ": %s", sani);  return OOP_CONTINUE
+#define PEERBADMSG(m) do {                                     \
+    connfail(conn, m ": %s", sani);  return OOP_CONTINUE;      \
+  }while(0)
 
   int code_streaming= 0;
 
   switch (code) {
 
   case 400: PEERBADMSG("peer stopped accepting articles");
-  case 503: PEERBADMSG("peer timed us out");
   default:  PEERBADMSG("peer sent unexpected message");
 
+  case 503:
+    if (conn_busy) PEERBADMSG("peer timed us out");
+    notice("C%d idle connection closed by peer", conn->fd);
+    LIST_REMOVE(conns,conn);
+    conn_dispose(conn);
+    return OOP_CONTINUE;
+
   case 435: ARTICLE_DEALTWITH(0,0,unwanted); /* IHAVE says they have it */
   case 438: ARTICLE_DEALTWITH(1,0,unwanted); /* CHECK/TAKETHIS: they have it */
 
@@ -1777,6 +1791,7 @@ static void *peer_rd_ok(oop_source *lp, oop_read *oread, oop_rd_event ev,
     break;
 
   }
+dealtwith:
 
   conn_maybe_write(conn);
   check_assign_articles();
@@ -2042,7 +2057,7 @@ static void *filemon_inotify_readable(oop_source *lp, int fd,
       die("inotify read %d bytes wanted struct of %d", r, (int)sizeof(iev));
     }
     InputFile *ipf= filemon_inotify_wd2ipf[iev.wd];
-    debug("filemon inotify readable read %d wd=%p", iev.wd, ipf);
+    debug("filemon inotify readable read %p wd=%d", ipf, iev.wd);
     filemon_callback(ipf);
   }
   return OOP_CONTINUE;