Merged spdylay_session_pack_data_overwrite() into spdylay_session_pack_data().
spdylay_session_pack_data() now takes the maximum length of DATA payload.
This commit is contained in:
parent
05627f7712
commit
5408a21ce9
|
@ -37,8 +37,8 @@
|
|||
#define SPDYLAY_LENGTH_MASK 0xffffff
|
||||
#define SPDYLAY_VERSION_MASK 0x7fff
|
||||
|
||||
/* DATA frame length. This is 8+4KiB */
|
||||
#define SPDYLAY_DATA_FRAME_LENGTH 4104
|
||||
/* The length of DATA frame payload. */
|
||||
#define SPDYLAY_DATA_PAYLOAD_LENGTH 4096
|
||||
|
||||
/* The number of bytes of frame header. */
|
||||
#define SPDYLAY_FRAME_HEAD_LENGTH 8
|
||||
|
|
|
@ -560,6 +560,7 @@ ssize_t spdylay_session_prep_frame(spdylay_session *session,
|
|||
framebuflen = spdylay_session_pack_data(session,
|
||||
&session->aob.framebuf,
|
||||
&session->aob.framebufmax,
|
||||
SPDYLAY_DATA_PAYLOAD_LENGTH,
|
||||
&item->frame->data);
|
||||
if(framebuflen == SPDYLAY_ERR_DEFERRED) {
|
||||
spdylay_stream *stream = spdylay_session_get_stream
|
||||
|
@ -788,12 +789,11 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
|
|||
/* If priority of this stream is higher or equal to other stream
|
||||
waiting at the top of the queue, we continue to send this
|
||||
data. */
|
||||
/* We assume that buffer has at least
|
||||
SPDYLAY_DATA_FRAME_LENGTH. */
|
||||
r = spdylay_session_pack_data_overwrite(session,
|
||||
session->aob.framebuf,
|
||||
SPDYLAY_DATA_FRAME_LENGTH,
|
||||
&frame->data);
|
||||
r = spdylay_session_pack_data(session,
|
||||
&session->aob.framebuf,
|
||||
&session->aob.framebufmax,
|
||||
SPDYLAY_DATA_PAYLOAD_LENGTH,
|
||||
&frame->data);
|
||||
if(r == SPDYLAY_ERR_DEFERRED) {
|
||||
spdylay_stream *stream =
|
||||
spdylay_session_get_stream(session, frame->data.stream_id);
|
||||
|
@ -1661,44 +1661,36 @@ int spdylay_session_add_goaway(spdylay_session *session,
|
|||
|
||||
ssize_t spdylay_session_pack_data(spdylay_session *session,
|
||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||
size_t datamax,
|
||||
spdylay_data *frame)
|
||||
{
|
||||
ssize_t framelen = SPDYLAY_DATA_FRAME_LENGTH;
|
||||
int r;
|
||||
ssize_t framelen = datamax+8, r;
|
||||
int eof;
|
||||
uint8_t flags;
|
||||
r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
||||
if(r != 0) {
|
||||
return r;
|
||||
}
|
||||
framelen = spdylay_session_pack_data_overwrite(session, *buf_ptr, framelen,
|
||||
frame);
|
||||
return framelen;
|
||||
}
|
||||
|
||||
ssize_t spdylay_session_pack_data_overwrite(spdylay_session *session,
|
||||
uint8_t *buf, size_t len,
|
||||
spdylay_data *frame)
|
||||
{
|
||||
ssize_t r;
|
||||
int eof = 0;
|
||||
uint8_t flags = 0;
|
||||
eof = 0;
|
||||
r = frame->data_prd.read_callback
|
||||
(session, frame->stream_id, buf+8, len-8, &eof, &frame->data_prd.source,
|
||||
session->user_data);
|
||||
(session, frame->stream_id, (*buf_ptr)+8, datamax,
|
||||
&eof, &frame->data_prd.source, session->user_data);
|
||||
if(r < 0) {
|
||||
return r;
|
||||
} else if(len < r) {
|
||||
} else if(datamax < r) {
|
||||
return SPDYLAY_ERR_CALLBACK_FAILURE;
|
||||
}
|
||||
memset(buf, 0, SPDYLAY_HEAD_LEN);
|
||||
spdylay_put_uint32be(&buf[0], frame->stream_id);
|
||||
spdylay_put_uint32be(&buf[4], r);
|
||||
memset(*buf_ptr, 0, SPDYLAY_HEAD_LEN);
|
||||
spdylay_put_uint32be(&(*buf_ptr)[0], frame->stream_id);
|
||||
spdylay_put_uint32be(&(*buf_ptr)[4], r);
|
||||
flags = 0;
|
||||
if(eof) {
|
||||
frame->eof = 1;
|
||||
if(frame->flags & SPDYLAY_FLAG_FIN) {
|
||||
flags |= SPDYLAY_FLAG_FIN;
|
||||
}
|
||||
}
|
||||
buf[4] = flags;
|
||||
(*buf_ptr)[4] = flags;
|
||||
return r+8;
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ typedef struct {
|
|||
message block of SSLv3/TLSv1 */
|
||||
#define SPDYLAY_INBOUND_BUFFER_LENGTH 16384
|
||||
|
||||
#define SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH SPDYLAY_DATA_FRAME_LENGTH
|
||||
#define SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH (SPDYLAY_DATA_PAYLOAD_LENGTH+8)
|
||||
#define SPDYLAY_INITIAL_INBOUND_FRAMEBUF_LENGTH \
|
||||
SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH
|
||||
#define SPDYLAY_INITIAL_NV_BUFFER_LENGTH 4096
|
||||
|
@ -384,7 +384,8 @@ spdylay_stream* spdylay_session_get_stream(spdylay_session *session,
|
|||
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
|
||||
* length. This function expands |*buf_ptr| as necessary to store
|
||||
* given |frame|. It packs header in first 8 bytes. Remaining bytes
|
||||
* are filled using frame->data_prd.
|
||||
* are the DATA apyload and are filled using |frame->data_prd|. The
|
||||
* length of payload is at most |datamax| bytes.
|
||||
*
|
||||
* This function returns the size of packed frame if it succeeds, or
|
||||
* one of the following negative error codes:
|
||||
|
@ -398,26 +399,9 @@ spdylay_stream* spdylay_session_get_stream(spdylay_session *session,
|
|||
*/
|
||||
ssize_t spdylay_session_pack_data(spdylay_session *session,
|
||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||
size_t datamax,
|
||||
spdylay_data *frame);
|
||||
|
||||
/*
|
||||
* Packs DATA frame |frame| in wire frame format and store it in
|
||||
* |buf|. |len| must be greater than or equal to 8.
|
||||
*
|
||||
* This function returns the size of packed frame if it succeeds, or
|
||||
* one of the following negative error codes:
|
||||
*
|
||||
* SPDYLAY_ERR_NOMEM
|
||||
* Out of memory.
|
||||
* SPDYLAY_ERR_DEFERRED
|
||||
* The DATA frame is postponed.
|
||||
* SPDYLAY_ERR_CALLBACK_FAILURE
|
||||
* The read_callback failed.
|
||||
*/
|
||||
ssize_t spdylay_session_pack_data_overwrite(spdylay_session *session,
|
||||
uint8_t *buf, size_t len,
|
||||
spdylay_data *frame);
|
||||
|
||||
/*
|
||||
* Returns next unique ID which can be used with PING.
|
||||
*/
|
||||
|
|
Loading…
Reference in New Issue