Renamed spdylay_session_init as spdylay_session_new. Added session arg to cb.
Now recv_callback and send_callback accepts session argument. spdylay_session_free was also renamed as spdylay_session_del.
This commit is contained in:
parent
9c8270436f
commit
a52ff39850
|
@ -46,25 +46,27 @@ typedef enum {
|
|||
SPDYLAY_MSG_MORE
|
||||
} spdylay_io_flag;
|
||||
|
||||
struct spdylay_session;
|
||||
typedef struct spdylay_session spdylay_session;
|
||||
|
||||
typedef ssize_t (*spdylay_send_callback)
|
||||
(const uint8_t *data, size_t length, int flags, void *user_data);
|
||||
(spdylay_session *session,
|
||||
const uint8_t *data, size_t length, int flags, void *user_data);
|
||||
|
||||
typedef ssize_t (*spdylay_recv_callback)
|
||||
(uint8_t *buf, size_t length, int flags, void *user_data);
|
||||
(spdylay_session *session,
|
||||
uint8_t *buf, size_t length, int flags, void *user_data);
|
||||
|
||||
typedef struct {
|
||||
spdylay_send_callback send_callback;
|
||||
spdylay_recv_callback recv_callback;
|
||||
} spdylay_session_callbacks;
|
||||
|
||||
struct spdylay_session;
|
||||
typedef struct spdylay_session spdylay_session;
|
||||
|
||||
int spdylay_session_client_init(spdylay_session **session_ptr,
|
||||
int spdylay_session_client_new(spdylay_session **session_ptr,
|
||||
const spdylay_session_callbacks *callbacks,
|
||||
void *user_data);
|
||||
|
||||
void spdylay_session_free(struct spdylay_session *session);
|
||||
void spdylay_session_del(spdylay_session *session);
|
||||
|
||||
int spdylay_session_send(spdylay_session *session);
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ int spdylay_outbound_item_compar(const void *lhsx, const void *rhsx)
|
|||
return lhs->pri-rhs->pri;
|
||||
}
|
||||
|
||||
int spdylay_session_client_init(spdylay_session **session_ptr,
|
||||
int spdylay_session_client_new(spdylay_session **session_ptr,
|
||||
const spdylay_session_callbacks *callbacks,
|
||||
void *user_data)
|
||||
{
|
||||
|
@ -109,7 +109,7 @@ static void spdylay_outbound_item_free(spdylay_outbound_item *item)
|
|||
free(item->frame);
|
||||
}
|
||||
|
||||
void spdylay_session_free(spdylay_session *session)
|
||||
void spdylay_session_del(spdylay_session *session)
|
||||
{
|
||||
spdylay_map_each(&session->streams, spdylay_free_streams);
|
||||
spdylay_map_free(&session->streams);
|
||||
|
@ -239,7 +239,7 @@ int spdylay_session_send(spdylay_session *session)
|
|||
}
|
||||
data = session->aob.framebuf + session->aob.framebufoff;
|
||||
datalen = session->aob.framebuflen - session->aob.framebufoff;
|
||||
sentlen = session->callbacks.send_callback(data, datalen, 0,
|
||||
sentlen = session->callbacks.send_callback(session, data, datalen, 0,
|
||||
session->user_data);
|
||||
if(sentlen < 0) {
|
||||
if(sentlen == SPDYLAY_ERR_WOULDBLOCK) {
|
||||
|
@ -281,7 +281,7 @@ static ssize_t spdylay_recv(spdylay_session *session)
|
|||
}
|
||||
recv_max = session->ibuf.buf+sizeof(session->ibuf.buf)-session->ibuf.limit;
|
||||
r = session->callbacks.recv_callback
|
||||
(session->ibuf.limit, recv_max, 0, session->user_data);
|
||||
(session, session->ibuf.limit, recv_max, 0, session->user_data);
|
||||
if(r > 0) {
|
||||
if(r > recv_max) {
|
||||
return SPDYLAY_ERR_CALLBACK_FAILURE;
|
||||
|
|
|
@ -60,7 +60,8 @@ static void scripted_data_feed_init(scripted_data_feed *df,
|
|||
df->feedseq[0] = data_length;
|
||||
}
|
||||
|
||||
static ssize_t scripted_recv_callback(uint8_t* data, size_t len, int flags,
|
||||
static ssize_t scripted_recv_callback(spdylay_session *session,
|
||||
uint8_t* data, size_t len, int flags,
|
||||
void *user_data)
|
||||
{
|
||||
scripted_data_feed *df = ((my_user_data*)user_data)->df;
|
||||
|
@ -75,7 +76,8 @@ static ssize_t scripted_recv_callback(uint8_t* data, size_t len, int flags,
|
|||
return wlen;
|
||||
}
|
||||
|
||||
static ssize_t accumulator_send_callback(const uint8_t *buf, size_t len,
|
||||
static ssize_t accumulator_send_callback(spdylay_session *session,
|
||||
const uint8_t *buf, size_t len,
|
||||
int flags, void* user_data)
|
||||
{
|
||||
accumulator *acc = ((my_user_data*)user_data)->acc;
|
||||
|
@ -115,7 +117,7 @@ void test_spdylay_session_recv()
|
|||
spdylay_frame frame;
|
||||
|
||||
user_data.df = &df;
|
||||
spdylay_session_client_init(&session, &callbacks, &user_data);
|
||||
spdylay_session_client_new(&session, &callbacks, &user_data);
|
||||
spdylay_frame_syn_stream_init(&frame.syn_stream, 0, 0, 0, 3, dup_nv(nv));
|
||||
framelen = spdylay_frame_pack_syn_stream(&framedata, &frame.syn_stream,
|
||||
&session->hd_deflater);
|
||||
|
@ -124,7 +126,7 @@ void test_spdylay_session_recv()
|
|||
spdylay_frame_syn_stream_free(&frame.syn_stream);
|
||||
|
||||
CU_ASSERT(0 == spdylay_session_recv(session));
|
||||
spdylay_session_free(session);
|
||||
spdylay_session_del(session);
|
||||
}
|
||||
|
||||
void test_spdylay_session_add_frame()
|
||||
|
@ -150,7 +152,7 @@ void test_spdylay_session_add_frame()
|
|||
uint32_t temp32;
|
||||
acc.length = 0;
|
||||
user_data.acc = &acc;
|
||||
CU_ASSERT(0 == spdylay_session_client_init(&session, &callbacks, &user_data));
|
||||
CU_ASSERT(0 == spdylay_session_client_new(&session, &callbacks, &user_data));
|
||||
|
||||
frame = malloc(sizeof(spdylay_frame));
|
||||
spdylay_frame_syn_stream_init(&frame->syn_stream, 0, 0, 0, 3, dup_nv(nv));
|
||||
|
@ -171,5 +173,5 @@ void test_spdylay_session_add_frame()
|
|||
temp32 = (acc.buf[16] >> 6) & 0x3;
|
||||
CU_ASSERT(3 == temp32);
|
||||
|
||||
spdylay_session_free(session);
|
||||
spdylay_session_del(session);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue