aboutsummaryrefslogtreecommitdiffstats
path: root/FICS
diff options
context:
space:
mode:
authorMarkus Uhlin <markus@nifty-networks.net>2023-12-13 18:30:29 +0100
committerMarkus Uhlin <markus@nifty-networks.net>2023-12-13 18:30:29 +0100
commit5cc424cb4b3a6d818ed30e8941fc11ddbd23413d (patch)
treebef263f3c00e8743611a7466300411b6de058bf6 /FICS
parenteeaefd22dc710860a72fa363dc2e9fecca42bb20 (diff)
Reformatted ngc2() and fixed compiler warnings
Diffstat (limited to 'FICS')
-rw-r--r--FICS/network.c99
1 files changed, 57 insertions, 42 deletions
diff --git a/FICS/network.c b/FICS/network.c
index f4fdeb0..453a5da 100644
--- a/FICS/network.c
+++ b/FICS/network.c
@@ -557,58 +557,73 @@ PUBLIC unsigned int net_connected_host(int fd)
return con[which].fromHost;
}
-PUBLIC void ngc2(char *com, int timeout)
+PUBLIC void
+ngc2(char *com, int timeout)
{
- struct sockaddr_in cli_addr;
- int cli_len = (int) sizeof(struct sockaddr_in);
+ fd_set readfds;
+ int fd, loop, nfound, lineComplete;
+ socklen_t cli_len = sizeof(struct sockaddr_in);
+ struct sockaddr_in cli_addr;
+ struct timeval to;
+
+ while ((fd = accept(sockfd, (struct sockaddr *) &cli_addr, &cli_len)) !=
+ -1) {
+ if (net_addConnection(fd, cli_addr.sin_addr.s_addr)) {
+ fprintf(stderr, "FICS is full. fd = %d.\n", fd);
+ psend_raw_file(fd, mess_dir, MESS_FULL);
+ close(fd);
+ } else {
+ process_new_connection(fd, net_connected_host(fd));
+ }
+ }
- int fd, loop, nfound, lineComplete;
- fd_set readfds;
- struct timeval to;
+ if (errno != EWOULDBLOCK) {
+ fprintf(stderr, "FICS: Problem with accept(). errno=%d\n",
+ errno);
+ }
+ net_flush_all_connections();
- while ((fd = accept(sockfd, (struct sockaddr *) & cli_addr, &cli_len)) != -1)
- {
- if (net_addConnection(fd, cli_addr.sin_addr.s_addr)) {
- fprintf(stderr, "FICS is full. fd = %d.\n", fd);
- psend_raw_file(fd, mess_dir, MESS_FULL);
- close(fd);
- } else
- process_new_connection(fd, net_connected_host(fd));
- }
+ FD_ZERO(&readfds);
+ for (loop = 0; loop < no_file; loop++) {
+ if (con[loop].status != NETSTAT_EMPTY)
+ FD_SET(con[loop].fd, &readfds);
+ }
- if (errno != EWOULDBLOCK)
- fprintf(stderr, "FICS: Problem with accept(). errno=%d\n", errno);
+ to.tv_usec = 0;
+ to.tv_sec = timeout;
- net_flush_all_connections();
+ nfound = select(no_file, &readfds, NULL, NULL, &to);
- FD_ZERO(&readfds);
- for (loop = 0; loop < no_file; loop++)
- if (con[loop].status != NETSTAT_EMPTY)
- FD_SET(con[loop].fd, &readfds);
+ /* XXX: unused */
+ (void) nfound;
- to.tv_usec = 0;
- to.tv_sec = timeout;
- nfound = select(no_file, &readfds, NULL, NULL, &to);
- for (loop = 0; loop < no_file; loop++) {
- if (con[loop].status != NETSTAT_EMPTY) {
- fd = con[loop].fd;
- lineComplete = readline2(com, fd);
- if (lineComplete == 0) /* partial line: do nothing with it */
- continue;
- if (lineComplete > 0) { /* complete line: process it */
+ for (loop = 0; loop < no_file; loop++) {
+ if (con[loop].status != NETSTAT_EMPTY) {
+ fd = con[loop].fd;
+
+ if ((lineComplete = readline2(com, fd)) == 0) {
+ // partial line: do nothing
+ continue;
+ }
+
+ if (lineComplete > 0) { // complete line: process it
#ifdef TIMESEAL
- if (!(parseInput(com, &con[loop]))) continue;
+ if (!parseInput(com, &con[loop]))
+ continue;
#endif
- if (process_input(fd, com) != COM_LOGOUT) {
- net_flush_connection(fd);
- continue;
+ if (process_input(fd, com) != COM_LOGOUT) {
+ net_flush_connection(fd);
+ continue;
+ }
+ }
+
+ /*
+ * Disconnect anyone who gets here
+ */
+ process_disconnection(fd);
+ net_close_connection(fd);
+ }
}
- }
- /* Disconnect anyone who gets here */
- process_disconnection(fd);
- net_close_connection(fd);
- }
- }
}
PUBLIC int net_consize(void)