Implement irc_try_read()

This commit is contained in:
Přemysl Eric Janouch 2014-07-12 23:06:39 +02:00
parent 13d3299816
commit 93450332fe
1 changed files with 31 additions and 2 deletions

View File

@ -380,8 +380,37 @@ irc_process_message (const struct irc_message *msg,
static bool
irc_try_read (struct connection *conn)
{
// TODO
struct str *buf = &conn->read_buffer;
ssize_t n_read;
while (true)
{
str_ensure_space (buf, 512);
n_read = recv (conn->socket_fd, buf->str + buf->len,
buf->alloc - buf->len - 1 /* null byte */, 0);
if (n_read > 0)
{
buf->str[buf->len += n_read] = '\0';
// TODO: discard characters above the 512 character limit
irc_process_buffer (buf, irc_process_message, conn);
continue;
}
if (n_read == 0)
{
connection_abort (conn, NULL);
return false;
}
if (errno == EAGAIN)
return true;
if (errno == EINTR)
continue;
print_debug ("%s: %s: %s", __func__, "recv", strerror (errno));
connection_abort (conn, strerror (errno));
return false;
}
}
static bool