From 925078c199b836129966ce1632a7e809d15c59fa Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 29 Jan 2012 16:46:18 +0900 Subject: [PATCH] Added handling of EOF from recv_callback --- lib/includes/spdylay/spdylay.h | 9 +++++++++ lib/spdylay_session.c | 12 +++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/includes/spdylay/spdylay.h b/lib/includes/spdylay/spdylay.h index b69f6a85..0a9593cf 100644 --- a/lib/includes/spdylay/spdylay.h +++ b/lib/includes/spdylay/spdylay.h @@ -45,6 +45,7 @@ typedef enum { SPDYLAY_ERR_WOULDBLOCK = -504, SPDYLAY_ERR_PROTO = -505, SPDYLAY_ERR_INVALID_FRAME = -506, + SPDYLAY_ERR_EOF = -507, /* The errors < SPDYLAY_ERR_FATAL mean that the library is under unexpected condition that it cannot process any further data @@ -165,6 +166,14 @@ typedef ssize_t (*spdylay_send_callback) (spdylay_session *session, const uint8_t *data, size_t length, int flags, void *user_data); +/* + * Callback function invoked when the library want to read data from + * remote peer. The implementation of this function must read at most + * |length| bytes of data and store it in |buf|. It must return the + * number of bytes written in |buf| if it succeeds. If it gets EOF + * before it reads any single byte, return SPDYLAY_ERR_EOF. For other + * errors, return SPDYLAY_ERR_CALLBACK_FAILURE. + */ typedef ssize_t (*spdylay_recv_callback) (spdylay_session *session, uint8_t *buf, size_t length, int flags, void *user_data); diff --git a/lib/spdylay_session.c b/lib/spdylay_session.c index 4b74be70..8ddf03ab 100644 --- a/lib/spdylay_session.c +++ b/lib/spdylay_session.c @@ -1077,7 +1077,7 @@ int spdylay_session_recv(spdylay_session *session) uint32_t payloadlen; if(spdylay_inbound_buffer_avail(&session->ibuf) < SPDYLAY_HEAD_LEN) { r = spdylay_recv(session); - /* TODO handle EOF */ + /* If EOF is reached, r == SPDYLAY_ERR_EOF */ if(r < 0) { if(r == SPDYLAY_ERR_WOULDBLOCK) { return 0; @@ -1114,12 +1114,10 @@ int spdylay_session_recv(spdylay_session *session) if(spdylay_inbound_buffer_avail(&session->ibuf) == 0 && rempayloadlen > 0) { r = spdylay_recv(session); - if(r <= 0) { - if(r == SPDYLAY_ERR_WOULDBLOCK) { - return 0; - } else { - return r; - } + if(r == 0 || r == SPDYLAY_ERR_WOULDBLOCK) { + return 0; + } else if(r < 0) { + return r; } } bufavail = spdylay_inbound_buffer_avail(&session->ibuf);