Added handling of EOF from recv_callback
This commit is contained in:
parent
06dae79b28
commit
925078c199
|
@ -45,6 +45,7 @@ typedef enum {
|
||||||
SPDYLAY_ERR_WOULDBLOCK = -504,
|
SPDYLAY_ERR_WOULDBLOCK = -504,
|
||||||
SPDYLAY_ERR_PROTO = -505,
|
SPDYLAY_ERR_PROTO = -505,
|
||||||
SPDYLAY_ERR_INVALID_FRAME = -506,
|
SPDYLAY_ERR_INVALID_FRAME = -506,
|
||||||
|
SPDYLAY_ERR_EOF = -507,
|
||||||
|
|
||||||
/* The errors < SPDYLAY_ERR_FATAL mean that the library is under
|
/* The errors < SPDYLAY_ERR_FATAL mean that the library is under
|
||||||
unexpected condition that it cannot process any further data
|
unexpected condition that it cannot process any further data
|
||||||
|
@ -165,6 +166,14 @@ typedef ssize_t (*spdylay_send_callback)
|
||||||
(spdylay_session *session,
|
(spdylay_session *session,
|
||||||
const uint8_t *data, size_t length, int flags, void *user_data);
|
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)
|
typedef ssize_t (*spdylay_recv_callback)
|
||||||
(spdylay_session *session,
|
(spdylay_session *session,
|
||||||
uint8_t *buf, size_t length, int flags, void *user_data);
|
uint8_t *buf, size_t length, int flags, void *user_data);
|
||||||
|
|
|
@ -1077,7 +1077,7 @@ int spdylay_session_recv(spdylay_session *session)
|
||||||
uint32_t payloadlen;
|
uint32_t payloadlen;
|
||||||
if(spdylay_inbound_buffer_avail(&session->ibuf) < SPDYLAY_HEAD_LEN) {
|
if(spdylay_inbound_buffer_avail(&session->ibuf) < SPDYLAY_HEAD_LEN) {
|
||||||
r = spdylay_recv(session);
|
r = spdylay_recv(session);
|
||||||
/* TODO handle EOF */
|
/* If EOF is reached, r == SPDYLAY_ERR_EOF */
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
if(r == SPDYLAY_ERR_WOULDBLOCK) {
|
if(r == SPDYLAY_ERR_WOULDBLOCK) {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -1114,12 +1114,10 @@ int spdylay_session_recv(spdylay_session *session)
|
||||||
if(spdylay_inbound_buffer_avail(&session->ibuf) == 0 &&
|
if(spdylay_inbound_buffer_avail(&session->ibuf) == 0 &&
|
||||||
rempayloadlen > 0) {
|
rempayloadlen > 0) {
|
||||||
r = spdylay_recv(session);
|
r = spdylay_recv(session);
|
||||||
if(r <= 0) {
|
if(r == 0 || r == SPDYLAY_ERR_WOULDBLOCK) {
|
||||||
if(r == SPDYLAY_ERR_WOULDBLOCK) {
|
return 0;
|
||||||
return 0;
|
} else if(r < 0) {
|
||||||
} else {
|
return r;
|
||||||
return r;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bufavail = spdylay_inbound_buffer_avail(&session->ibuf);
|
bufavail = spdylay_inbound_buffer_avail(&session->ibuf);
|
||||||
|
|
Loading…
Reference in New Issue