Set connection states everywhere, combine arg string, remove few commands and sleep on every loop iteration
This commit is contained in:
parent
cf8391ed77
commit
18df38bb2d
22
src/main.c
22
src/main.c
|
@ -37,15 +37,7 @@ int main(int argc, char* argv[])
|
|||
* -v Version and license information
|
||||
* -h Help/Usage
|
||||
*/
|
||||
while ((c = getopt(argc, argv, /* "C:" */
|
||||
"m:"
|
||||
"c:"
|
||||
"l:"
|
||||
"j:"
|
||||
"V:"
|
||||
"v"
|
||||
"h"))
|
||||
!= -1) {
|
||||
while ((c = getopt(argc, argv, /* "C:" */ "m:c:l:j:V:vh")) != -1) {
|
||||
switch (c) {
|
||||
case 'c': {
|
||||
cons[totcon].data.chans = point_after(optarg, ',');
|
||||
|
@ -127,6 +119,9 @@ int run_main(Connection* conn, unsigned int recon_inter, unsigned int ping_inter
|
|||
|
||||
get_connstr(connstr, sizeof(connstr), conn);
|
||||
for (;;) {
|
||||
struct timespec sleep = {0, 10000000L};
|
||||
nanosleep(&sleep, NULL);
|
||||
|
||||
/* Connection manager */
|
||||
ctime = time(NULL);
|
||||
if (!run || connstate == CONN_CLOSING) {
|
||||
|
@ -219,8 +214,6 @@ int run_main(Connection* conn, unsigned int recon_inter, unsigned int ping_inter
|
|||
lastping = ctime;
|
||||
}
|
||||
}
|
||||
struct timespec sleep = {0, 10000000L};
|
||||
nanosleep(&sleep, NULL);
|
||||
}
|
||||
|
||||
/* Buffer reader */
|
||||
|
@ -257,7 +250,7 @@ int run_main(Connection* conn, unsigned int recon_inter, unsigned int ping_inter
|
|||
path[1] = category[CAT_USER];
|
||||
bprint = buffer.name.nick;
|
||||
}
|
||||
} else if (buffer.cmd == RPL_TOPIC || buffer.cmd == RPL_NOTOPIC || buffer.cmd == MODE || buffer.cmd == TOPIC || buffer.cmd == RPL_BANLIST || buffer.cmd == RPL_ENDOFBANLIST) {
|
||||
} else if (buffer.cmd == RPL_BANLIST || buffer.cmd == RPL_ENDOFBANLIST) {
|
||||
path[1] = category[CAT_CHAN];
|
||||
bprint = buffer.args[0];
|
||||
} else if (buffer.cmd == KILL || buffer.cmd == RPL_AWAY) {
|
||||
|
@ -297,6 +290,7 @@ int run_main(Connection* conn, unsigned int recon_inter, unsigned int ping_inter
|
|||
if ((sendbufpos = Assm_mesg(sendbuf, Assm_cmd_PONG(buffer.args[0], NULL), sizeof(sendbuf))) > 0)
|
||||
if (flush_buffer(sendbuf, sendbufpos, fds[0]) == -1) {
|
||||
LOG(LOG_WARN, "Couldn't pong " ADDRFMT ". " ERRNOFMT, conn->data.addr, conn->data.port, strerror(errno), errno);
|
||||
connstate = CONN_PENDING;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -310,6 +304,7 @@ int run_main(Connection* conn, unsigned int recon_inter, unsigned int ping_inter
|
|||
if ((sendbufpos = Assm_mesg(sendbuf, mesg, sizeof(sendbuf))) > 0)
|
||||
if (flush_buffer(sendbuf, sendbufpos, fds[0]) == -1) {
|
||||
LOG(LOG_WARN, "Couldn't auto-join channels \"%s\" " ADDRFMT ". " ERRNOFMT, conn->data.chans, conn->data.addr, conn->data.port, strerror(errno), errno);
|
||||
connstate = CONN_PENDING;
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
|
@ -336,6 +331,7 @@ int run_main(Connection* conn, unsigned int recon_inter, unsigned int ping_inter
|
|||
*(fifobuf + (fifobufpos += brd)) = '\0';
|
||||
} else if (brd == -1 && errno != EAGAIN && errno != EINTR) {
|
||||
LOG(LOG_ERROR, "Failed to read FIFO input for connection " ADDRFMT ". " ERRNOFMT, conn->data.addr, conn->data.port, strerror(errno), errno);
|
||||
connstate = CONN_PENDING;
|
||||
continue;
|
||||
}
|
||||
|
||||
|
@ -350,6 +346,7 @@ int run_main(Connection* conn, unsigned int recon_inter, unsigned int ping_inter
|
|||
if ((sendbufpos = Assm_mesg(sendbuf, &buffer, sizeof(sendbuf))) > 0) {
|
||||
if (flush_buffer(sendbuf, sendbufpos, fds[0]) == -1) {
|
||||
LOG(LOG_WARN, "Couldn't send FIFO input to " ADDRFMT ". " ERRNOFMT, conn->data.addr, conn->data.port, strerror(errno), errno);
|
||||
connstate = CONN_PENDING;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
@ -364,6 +361,7 @@ int run_main(Connection* conn, unsigned int recon_inter, unsigned int ping_inter
|
|||
LOG(LOG_VERBOSE, "Exiting thread with connection " ADDRFMT " gracefully.", conn->data.addr, conn->data.port);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
void print_help(void)
|
||||
{
|
||||
struct help {
|
||||
|
|
Reference in New Issue