summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2014-07-12 23:06:39 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2014-07-12 23:17:38 +0200
commit93450332fe1fb28922b6f701d15e2733bf6d8961 (patch)
tree9bb6e0b314dcd3ad2347c43f80eb548c085db92d /src
parent13d3299816ffb5de07c2178a83af7661d63e1dea (diff)
downloadxK-93450332fe1fb28922b6f701d15e2733bf6d8961.tar.gz
xK-93450332fe1fb28922b6f701d15e2733bf6d8961.tar.xz
xK-93450332fe1fb28922b6f701d15e2733bf6d8961.zip
Implement irc_try_read()
Diffstat (limited to 'src')
-rw-r--r--src/kike.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/src/kike.c b/src/kike.c
index 80e554c..f79b537 100644
--- a/src/kike.c
+++ b/src/kike.c
@@ -380,8 +380,37 @@ irc_process_message (const struct irc_message *msg,
static bool
irc_try_read (struct connection *conn)
{
- // TODO
- return true;
+ 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