Added handling of EOF from recv_callback

This commit is contained in:
Tatsuhiro Tsujikawa 2012-01-29 16:46:18 +09:00
parent 06dae79b28
commit 925078c199
2 changed files with 14 additions and 7 deletions

View File

@ -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);

View File

@ -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,14 +1114,12 @@ 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) {
if(r == 0 || r == SPDYLAY_ERR_WOULDBLOCK) {
return 0;
} else {
} else if(r < 0) {
return r;
}
}
}
bufavail = spdylay_inbound_buffer_avail(&session->ibuf);
readlen = bufavail < rempayloadlen ? bufavail : rempayloadlen;
if(spdylay_frame_is_ctrl_frame(session->iframe.headbuf[0])) {