summaryrefslogtreecommitdiff
path: root/lib/tcp.c
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2013-01-22 15:52:09 +0100
committerLinus Nordberg <linus@nordberg.se>2013-01-22 15:52:09 +0100
commitcb5f2c040965f3a48498c002cd0bdb1a016a807f (patch)
treef848b4fab3c3a93a78ee7c47502ed548891dccd2 /lib/tcp.c
parent4322f9984f471da0bf9a239fb3d456d34f3a06a0 (diff)
Add docstrings and a comment.
Diffstat (limited to 'lib/tcp.c')
-rw-r--r--lib/tcp.c18
1 files changed, 15 insertions, 3 deletions
diff --git a/lib/tcp.c b/lib/tcp.c
index d0bc62c..588d046 100644
--- a/lib/tcp.c
+++ b/lib/tcp.c
@@ -25,8 +25,7 @@
#include <event2/buffer.h>
#endif
-/* Read one RADIUS packet header. Return !0 on error. A return value
- of 0 means that we need more data. */
+/** Read one RADIUS packet header. Return !0 on error. */
static int
_read_header (struct rs_packet *pkt)
{
@@ -64,6 +63,13 @@ _read_header (struct rs_packet *pkt)
return 0;
}
+/** Read a message, check that it's valid RADIUS and hand it off to
+ registered user callback.
+
+ The packet is read from the bufferevent associated with \a pkt and
+ the data is stored in \a pkt->rpkt.
+
+ Return 0 on success and !0 on failure. */
static int
_read_packet (struct rs_packet *pkt)
{
@@ -141,8 +147,14 @@ tcp_read_cb (struct bufferevent *bev, void *user_data)
assert (pkt->rpkt);
pkt->rpkt->sockfd = pkt->conn->fd;
- pkt->rpkt->vps = NULL;
+ pkt->rpkt->vps = NULL; /* FIXME: can this be done when initializing pkt? */
+
+ /* Read a message header if not already read, return if that
+ fails. Read a message and have it dispatched to the user
+ registered callback.
+ Room for improvement: Peek inside buffer (evbuffer_copyout()) to
+ avoid the extra copying. */
if ((pkt->flags & rs_packet_hdr_read_flag) == 0)
if (_read_header (pkt))
return; /* Error. */