Networker: if there is no file, quit the way it should.
[citadel.git] / citadel / modules / network / serv_networkclient.c
index c62e3f3ca9f9d894d43b1f9115f4362564b3bcd5..24e354a5c37e2006f124baa55f99389ff3c5308d 100644 (file)
@@ -437,6 +437,7 @@ eNextState NWC_SendNUOP(AsyncNetworker *NW)
                NW->State = eQUIT;
                rc = NWC_SendQUIT(NW);
                NWC_DBG_SEND();
+               return rc;
        }
 
        if (fstat(fd, &statbuf) == -1) {
@@ -497,19 +498,19 @@ eNextState NWC_SendBlobDone(AsyncNetworker *NW)
 {
        AsyncIO *IO = &NW->IO;
        eNextState rc;
-       if (NW->IO.IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
+       if (IO->IOB.TotalSendSize == NW->IO.IOB.TotalSentAlready)
        {
                NW->State ++;
 
-               FDIOBufferDelete(&NW->IO.IOB);
-               rc =  NWC_DispatchWriteDone(&NW->IO);
+               FDIOBufferDelete(&IO->IOB);
+               rc =  NWC_DispatchWriteDone(IO);
                NW->State --;
                return rc;
        }
        else {
                NW->State --;
-               NW->IO.IOB.ChunkSendRemain = NW->IO.IOB.ChunkSize;
-               return NWC_DispatchWriteDone(&NW->IO);
+               IO->IOB.ChunkSendRemain = IO->IOB.ChunkSize;
+               return NWC_DispatchWriteDone(IO);
        }
 }
 
@@ -822,7 +823,6 @@ eNextState nwc_connect_ip(AsyncIO *IO)
        AsyncNetworker *NW = IO->Data;
 
        EVN_syslog(LOG_DEBUG, "%s\n", __FUNCTION__);
-       EVN_syslog(LOG_DEBUG, "network: polling <%s>\n", ChrPtr(NW->node));
        EVN_syslog(LOG_NOTICE, "Connecting to <%s> at %s:%s\n", 
                   ChrPtr(NW->node), 
                   ChrPtr(NW->host),
@@ -834,8 +834,14 @@ eNextState nwc_connect_ip(AsyncIO *IO)
                             1);
 }
 
+static int NetworkerCount = 0;
 void RunNetworker(AsyncNetworker *NW)
 {
+       AsyncIO *IO = &NW->IO;
+
+       NW->n = NetworkerCount++;
+       network_talking_to(SKEY(NW->node), NTT_ADD);
+       syslog(LOG_DEBUG, "NW[%s][%ld]: polling\n", ChrPtr(NW->node), NW->n);
        ParseURL(&NW->IO.ConnectMe, NW->Url, 504);
 
        InitIOStruct(&NW->IO,
@@ -929,7 +935,9 @@ void network_poll_other_citadel_nodes(int full_poll, char *working_ignetcfg)
                                        }
                                }
                        }
-                       if (poll && (StrLength (NW->host) > 0) && (!strcmp(ChrPtr(NW->host), "0.0.0.0")))
+                       if (poll && 
+                           (StrLength(NW->host) > 0) && 
+                           strcmp("0.0.0.0", ChrPtr(NW->host)))
                        {
                                NW->Url = NewStrBufPlain(NULL, StrLength(Line));
                                StrBufPrintf(NW->Url, "citadel://:%s@%s:%s", 
@@ -938,7 +946,6 @@ void network_poll_other_citadel_nodes(int full_poll, char *working_ignetcfg)
                                             ChrPtr(NW->port));
                                if (!network_talking_to(SKEY(NW->node), NTT_CHECK))
                                {
-                                       network_talking_to(SKEY(NW->node), NTT_ADD);
                                        RunNetworker(NW);
                                        continue;
                                }