diff --git a/src/main.c b/src/main.c index 64d94ce..5dfe020 100644 --- a/src/main.c +++ b/src/main.c @@ -32,8 +32,8 @@ #include // srand() #include // strerror() #include // time_t size_t -#include // getopt() chdir() close() #include // time() +#include // getopt() chdir() close() #define UIRC_IRCV3 #define UIRC_HELPERS @@ -322,8 +322,13 @@ main(int argc, char* argv[]) connection.info.active = true; } else LOG(LOG_WARN, "%s", "Received invalid IRC message (see RFC2812)."); - } else if (len == -1) + } else if (len == -1) { connection.info.state = CONN_RECONNECTING; + } else if (buf.fifo.append_pos == 512) { + LOG(LOG_WARN, "%s. %s.", "FIFO buffer is full and no message could be parsed", "Discarding buffer"); + buf.fifo.append_pos = 0; + *buf.fifo.buffer = '\0'; + } } else { char pathbuf[UIRCD_LIMITS_PATH]; if (get_path(pathbuf, sizeof(pathbuf), &connection, NULL, true, true, false) >= 0) { @@ -336,7 +341,11 @@ main(int argc, char* argv[]) /* Buffer reader */ if ((brd = read(buf.recv.fd, buf.recv.buffer + buf.recv.append_pos, sizeof(buf.recv.buffer) - buf.recv.append_pos - 1)) > 0) { *(buf.recv.buffer + (buf.recv.append_pos += (size_t) brd)) = '\0'; - LOG(LOG_DEBUG, "Read %li bytes from socket buffer. Now appending at %li", brd, buf.recv.append_pos); + LOG(LOG_DEBUG, + "Read %li bytes from socket buffer. Now appending at %li with \"%s\" so far.", + brd, + buf.recv.append_pos, + buf.recv.buffer); connection.info.active = true; } else if (brd == -1 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { LOG(LOG_ERROR, "Failed to read inbound traffic. " ERRNOFMT, strerror(errno), errno); @@ -373,8 +382,12 @@ main(int argc, char* argv[]) connection.info.active = true; } else LOG(LOG_WARN, "%s", "Received invalid IRC message (see RFC2812)."); - } else if (len == -1) + } else if (len == -1) { connection.info.state = CONN_RECONNECTING; + } else if (buf.recv.append_pos == 512) { + LOG(LOG_WARN, "%s.", "Read buffer is full and no message could be parsed"); + connection.info.state = CONN_RECONNECTING; + } } LOG(LOG_VERBOSE, "%s", "Exiting gracefully."); return EXIT_SUCCESS;