Handle cases where the buffer is full
This commit is contained in:
parent
77e4d79599
commit
17fb6344bd
21
src/main.c
21
src/main.c
|
@ -32,8 +32,8 @@
|
|||
#include <stdlib.h> // srand()
|
||||
#include <string.h> // strerror()
|
||||
#include <sys/types.h> // time_t size_t
|
||||
#include <unistd.h> // getopt() chdir() close()
|
||||
#include <time.h> // time()
|
||||
#include <unistd.h> // 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;
|
||||
|
|
Reference in New Issue