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_LENGTH_MASK 0xffffff
|
||||||
#define SPDYLAY_VERSION_MASK 0x7fff
|
#define SPDYLAY_VERSION_MASK 0x7fff
|
||||||
|
|
||||||
/* DATA frame length. This is 8+4KiB */
|
/* The length of DATA frame payload. */
|
||||||
#define SPDYLAY_DATA_FRAME_LENGTH 4104
|
#define SPDYLAY_DATA_PAYLOAD_LENGTH 4096
|
||||||
|
|
||||||
/* The number of bytes of frame header. */
|
/* The number of bytes of frame header. */
|
||||||
#define SPDYLAY_FRAME_HEAD_LENGTH 8
|
#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,
|
framebuflen = spdylay_session_pack_data(session,
|
||||||
&session->aob.framebuf,
|
&session->aob.framebuf,
|
||||||
&session->aob.framebufmax,
|
&session->aob.framebufmax,
|
||||||
|
SPDYLAY_DATA_PAYLOAD_LENGTH,
|
||||||
&item->frame->data);
|
&item->frame->data);
|
||||||
if(framebuflen == SPDYLAY_ERR_DEFERRED) {
|
if(framebuflen == SPDYLAY_ERR_DEFERRED) {
|
||||||
spdylay_stream *stream = spdylay_session_get_stream
|
spdylay_stream *stream = spdylay_session_get_stream
|
||||||
|
@ -788,11 +789,10 @@ static int spdylay_session_after_frame_sent(spdylay_session *session)
|
||||||
/* If priority of this stream is higher or equal to other stream
|
/* If priority of this stream is higher or equal to other stream
|
||||||
waiting at the top of the queue, we continue to send this
|
waiting at the top of the queue, we continue to send this
|
||||||
data. */
|
data. */
|
||||||
/* We assume that buffer has at least
|
r = spdylay_session_pack_data(session,
|
||||||
SPDYLAY_DATA_FRAME_LENGTH. */
|
&session->aob.framebuf,
|
||||||
r = spdylay_session_pack_data_overwrite(session,
|
&session->aob.framebufmax,
|
||||||
session->aob.framebuf,
|
SPDYLAY_DATA_PAYLOAD_LENGTH,
|
||||||
SPDYLAY_DATA_FRAME_LENGTH,
|
|
||||||
&frame->data);
|
&frame->data);
|
||||||
if(r == SPDYLAY_ERR_DEFERRED) {
|
if(r == SPDYLAY_ERR_DEFERRED) {
|
||||||
spdylay_stream *stream =
|
spdylay_stream *stream =
|
||||||
|
@ -1661,44 +1661,36 @@ int spdylay_session_add_goaway(spdylay_session *session,
|
||||||
|
|
||||||
ssize_t spdylay_session_pack_data(spdylay_session *session,
|
ssize_t spdylay_session_pack_data(spdylay_session *session,
|
||||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
|
size_t datamax,
|
||||||
spdylay_data *frame)
|
spdylay_data *frame)
|
||||||
{
|
{
|
||||||
ssize_t framelen = SPDYLAY_DATA_FRAME_LENGTH;
|
ssize_t framelen = datamax+8, r;
|
||||||
int r;
|
int eof;
|
||||||
|
uint8_t flags;
|
||||||
r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
r = spdylay_reserve_buffer(buf_ptr, buflen_ptr, framelen);
|
||||||
if(r != 0) {
|
if(r != 0) {
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
framelen = spdylay_session_pack_data_overwrite(session, *buf_ptr, framelen,
|
eof = 0;
|
||||||
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;
|
|
||||||
r = frame->data_prd.read_callback
|
r = frame->data_prd.read_callback
|
||||||
(session, frame->stream_id, buf+8, len-8, &eof, &frame->data_prd.source,
|
(session, frame->stream_id, (*buf_ptr)+8, datamax,
|
||||||
session->user_data);
|
&eof, &frame->data_prd.source, session->user_data);
|
||||||
if(r < 0) {
|
if(r < 0) {
|
||||||
return r;
|
return r;
|
||||||
} else if(len < r) {
|
} else if(datamax < r) {
|
||||||
return SPDYLAY_ERR_CALLBACK_FAILURE;
|
return SPDYLAY_ERR_CALLBACK_FAILURE;
|
||||||
}
|
}
|
||||||
memset(buf, 0, SPDYLAY_HEAD_LEN);
|
memset(*buf_ptr, 0, SPDYLAY_HEAD_LEN);
|
||||||
spdylay_put_uint32be(&buf[0], frame->stream_id);
|
spdylay_put_uint32be(&(*buf_ptr)[0], frame->stream_id);
|
||||||
spdylay_put_uint32be(&buf[4], r);
|
spdylay_put_uint32be(&(*buf_ptr)[4], r);
|
||||||
|
flags = 0;
|
||||||
if(eof) {
|
if(eof) {
|
||||||
frame->eof = 1;
|
frame->eof = 1;
|
||||||
if(frame->flags & SPDYLAY_FLAG_FIN) {
|
if(frame->flags & SPDYLAY_FLAG_FIN) {
|
||||||
flags |= SPDYLAY_FLAG_FIN;
|
flags |= SPDYLAY_FLAG_FIN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
buf[4] = flags;
|
(*buf_ptr)[4] = flags;
|
||||||
return r+8;
|
return r+8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ typedef struct {
|
||||||
message block of SSLv3/TLSv1 */
|
message block of SSLv3/TLSv1 */
|
||||||
#define SPDYLAY_INBOUND_BUFFER_LENGTH 16384
|
#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 \
|
#define SPDYLAY_INITIAL_INBOUND_FRAMEBUF_LENGTH \
|
||||||
SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH
|
SPDYLAY_INITIAL_OUTBOUND_FRAMEBUF_LENGTH
|
||||||
#define SPDYLAY_INITIAL_NV_BUFFER_LENGTH 4096
|
#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|
|
* |*buf_ptr|. The capacity of |*buf_ptr| is |*buflen_ptr|
|
||||||
* length. This function expands |*buf_ptr| as necessary to store
|
* length. This function expands |*buf_ptr| as necessary to store
|
||||||
* given |frame|. It packs header in first 8 bytes. Remaining bytes
|
* 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
|
* This function returns the size of packed frame if it succeeds, or
|
||||||
* one of the following negative error codes:
|
* one of the following negative error codes:
|
||||||
|
@ -398,24 +399,7 @@ spdylay_stream* spdylay_session_get_stream(spdylay_session *session,
|
||||||
*/
|
*/
|
||||||
ssize_t spdylay_session_pack_data(spdylay_session *session,
|
ssize_t spdylay_session_pack_data(spdylay_session *session,
|
||||||
uint8_t **buf_ptr, size_t *buflen_ptr,
|
uint8_t **buf_ptr, size_t *buflen_ptr,
|
||||||
spdylay_data *frame);
|
size_t datamax,
|
||||||
|
|
||||||
/*
|
|
||||||
* 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);
|
spdylay_data *frame);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue