if (network_talking_to(node, NTT_CHECK)) return;
network_talking_to(node, NTT_ADD);
+ CtdlLogPrintf(CTDL_DEBUG, "network: polling <%s>\n", node);
CtdlLogPrintf(CTDL_NOTICE, "Connecting to <%s> at %s:%s\n", node, host, port);
sock = sock_connect(host, port, "tcp");
CCC->sReadBuf = NewStrBuf();
CCC->sMigrateBuf = NewStrBuf();
CCC->sPos = NULL;
+
/* Read the server greeting */
if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
extract_token (connected_to, buf, 1, ' ', sizeof connected_to);
if (strcmp(connected_to, node))
{
- snprintf (err_buf, sizeof(err_buf), "Connected to node \"%s\" but I was expecting to connect to node \"%s\".", connected_to, node);
+ snprintf(err_buf, sizeof(err_buf),
+ "Connected to node \"%s\" but I was expecting to connect to node \"%s\".",
+ connected_to, node
+ );
CtdlLogPrintf(CTDL_ERR, "%s\n", err_buf);
CtdlAideMessage(err_buf, "Network error");
}
if (sock_puts(&sock, buf) <0) goto bail;
if (sock_getln(&sock, buf, sizeof buf) < 0) goto bail;
CtdlLogPrintf(CTDL_DEBUG, ">%s\n", buf);
- if (buf[0] != '2') goto bail;
+ if (buf[0] != '2') {
+ goto bail;
+ }
/* At this point we are authenticated. */
if (!CtdlThreadCheckStop())
char spoolfile[256];
if (working_ignetcfg == NULL) {
- CtdlLogPrintf(CTDL_DEBUG, "No nodes defined - not polling\n");
+ CtdlLogPrintf(CTDL_DEBUG, "network: no neighbor nodes are configured - not polling.\n");
return;
}
poll = full_poll;
if (poll == 0) {
snprintf(spoolfile,
- sizeof spoolfile,
- "%s/%s",
- ctdl_netout_dir,
- node);
+ sizeof spoolfile,
+ "%s/%s",
+ ctdl_netout_dir,
+ node
+ );
if (access(spoolfile, R_OK) == 0) {
poll = 1;
}
*/
if ( (time(NULL) - last_run) < config.c_net_freq ) {
full_processing = 0;
- CtdlLogPrintf(CTDL_DEBUG, "Network full processing in %ld seconds.\n", config.c_net_freq - (time(NULL)- last_run));
+ CtdlLogPrintf(CTDL_DEBUG, "Network full processing in %ld seconds.\n",
+ config.c_net_freq - (time(NULL)- last_run)
+ );
}
/*
* don't really require extremely fine granularity here, we'll do it
* with a static variable instead.
*/
- if (doing_queue) return NULL;
+ if (doing_queue) {
+ return NULL;
+ }
doing_queue = 1;
/* Load the IGnet Configuration into memory */
}
/* If there is anything in the inbound queue, process it */
- if (!CtdlThreadCheckStop())
+ if (!CtdlThreadCheckStop()) {
network_do_spoolin();
+ }
/* Save the network map back to disk */
write_network_map();
}
doing_queue = 0;
- if (!CtdlThreadCheckStop()) // Only reschedule if system is not stopping
- CtdlThreadSchedule("IGnet Network", CTDLTHREAD_BIGSTACK, network_do_queue, NULL, time(NULL) + 60);
- else
+
+ /* Reschedule this task to happen again periodically, unless the thread system indicates
+ * that the server is shutting down.
+ */
+ if (!CtdlThreadCheckStop()) {
+ CtdlThreadSchedule("IGnet Network", CTDLTHREAD_BIGSTACK,
+ network_do_queue, NULL, time(NULL) + 60
+ );
+ }
+ else {
CtdlLogPrintf(CTDL_DEBUG, "network: Task STOPPED.\n");
+ }
return NULL;
}