diff options
Diffstat (limited to 'code')
-rw-r--r-- | code/ecp/rbuf.c | 59 | ||||
-rw-r--r-- | code/ecp/rbuf.h | 9 | ||||
-rw-r--r-- | code/ecp/rbuf_recv.c | 36 | ||||
-rw-r--r-- | code/ecp/rbuf_send.c | 18 |
4 files changed, 64 insertions, 58 deletions
diff --git a/code/ecp/rbuf.c b/code/ecp/rbuf.c index 080ba42..534381c 100644 --- a/code/ecp/rbuf.c +++ b/code/ecp/rbuf.c @@ -1,5 +1,35 @@ #include "core.h" +int ecp_rbuf_create(ECPConnection *conn, ECPRBSend *buf_s, ECPRBMessage *msg_s, unsigned int msg_s_size, ECPRBRecv *buf_r, ECPRBMessage *msg_r, unsigned int msg_r_size) { + int rv; + + if (buf_s) { + rv = ecp_rbuf_send_create(conn, buf_s, msg_s, msg_s_size); + if (rv) return rv; + + rv = ecp_rbuf_send_start(conn); + if (rv) { + ecp_rbuf_send_destroy(conn); + return rv; + } + } + + if (buf_r) { + rv = ecp_rbuf_recv_create(conn, buf_r, msg_r, msg_r_size); + if (rv) { + if (buf_s) ecp_rbuf_send_destroy(conn); + return rv; + } + } + + return ECP_OK; +} + +void ecp_rbuf_destroy(ECPConnection *conn) { + ecp_rbuf_send_destroy(conn); + ecp_rbuf_recv_destroy(conn); +} + int ecp_rbuf_init(ECPRBuffer *rbuf, ECPRBMessage *msg, unsigned int msg_size) { rbuf->msg = msg; if (msg_size) { @@ -65,32 +95,3 @@ ssize_t ecp_rbuf_pld_send(ECPConnection *conn, ECPBuffer *packet, ECPBuffer *pay return rv; } -int ecp_rbuf_create(ECPConnection *conn, ECPRBSend *buf_s, ECPRBMessage *msg_s, unsigned int msg_s_size, ECPRBRecv *buf_r, ECPRBMessage *msg_r, unsigned int msg_r_size) { - int rv; - - if (buf_s) { - rv = ecp_rbuf_send_create(conn, buf_s, msg_s, msg_s_size); - if (rv) return rv; - - rv = ecp_rbuf_send_start(conn); - if (rv) { - ecp_rbuf_send_destroy(conn); - return rv; - } - } - - if (buf_r) { - rv = ecp_rbuf_recv_create(conn, buf_r, msg_r, msg_r_size); - if (rv) { - if (buf_s) ecp_rbuf_send_destroy(conn); - return rv; - } - } - - return ECP_OK; -} - -void ecp_rbuf_destroy(ECPConnection *conn) { - ecp_rbuf_send_destroy(conn); - ecp_rbuf_recv_destroy(conn); -} diff --git a/code/ecp/rbuf.h b/code/ecp/rbuf.h index c4ea08e..b7c4078 100644 --- a/code/ecp/rbuf.h +++ b/code/ecp/rbuf.h @@ -89,11 +89,12 @@ typedef struct ECPConnRBuffer { ECPRBSend *send; } ECPConnRBuffer; + int ecp_rbuf_init(ECPRBuffer *rbuf, ECPRBMessage *msg, unsigned int msg_size); int ecp_rbuf_start(ECPRBuffer *rbuf, ecp_seq_t seq); int ecp_rbuf_msg_idx(ECPRBuffer *rbuf, ecp_seq_t seq); -ssize_t ecp_rbuf_msg_store(ECPRBuffer *rbuf, ecp_seq_t seq, int idx, unsigned char *msg, size_t msg_size, unsigned char test_flags, unsigned char set_flags); +ssize_t ecp_rbuf_msg_store(ECPRBuffer *rbuf, ecp_seq_t seq, int idx, unsigned char *msg, size_t msg_size, unsigned char test_flags, unsigned char set_flags); ssize_t ecp_rbuf_pld_send(struct ECPConnection *conn, struct ECPBuffer *packet, struct ECPBuffer *payload, size_t pld_size, unsigned char flags, ecp_seq_t seq); int ecp_rbuf_create(struct ECPConnection *conn, ECPRBSend *buf_s, ECPRBMessage *msg_s, unsigned int msg_s_size, ECPRBRecv *buf_r, ECPRBMessage *msg_r, unsigned int msg_r_size); @@ -101,14 +102,18 @@ void ecp_rbuf_destroy(struct ECPConnection *conn); int ecp_rbuf_recv_create(struct ECPConnection *conn, ECPRBRecv *buf, ECPRBMessage *msg, unsigned int msg_size); void ecp_rbuf_recv_destroy(struct ECPConnection *conn); +int ecp_rbuf_recv_start(struct ECPConnection *conn, ecp_seq_t seq); int ecp_rbuf_recv_set_hole(struct ECPConnection *conn, unsigned short hole_max); int ecp_rbuf_recv_set_delay(struct ECPConnection *conn, ecp_pts_t delay); -int ecp_rbuf_recv_start(struct ECPConnection *conn, ecp_seq_t seq); + ssize_t ecp_rbuf_recv_store(struct ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, size_t msg_size, struct ECP2Buffer *b); int ecp_rbuf_send_create(struct ECPConnection *conn, ECPRBSend *buf, ECPRBMessage *msg, unsigned int msg_size); void ecp_rbuf_send_destroy(struct ECPConnection *conn); int ecp_rbuf_send_start(struct ECPConnection *conn); +int ecp_rbuf_send_flush(ECPConnection *conn); +int ecp_rbuf_send_set_wsize(ECPConnection *conn, ecp_win_t size); + int ecp_rbuf_pkt_prep(ECPRBSend *buf, struct ECPSeqItem *si, unsigned char mtype); ssize_t ecp_rbuf_pkt_send(ECPRBSend *buf, struct ECPSocket *sock, ECPNetAddr *addr, struct ECPBuffer *packet, size_t pkt_size, unsigned char flags, ECPTimerItem *ti, struct ECPSeqItem *si); diff --git a/code/ecp/rbuf_recv.c b/code/ecp/rbuf_recv.c index 6ebfc64..4bd76cc 100644 --- a/code/ecp/rbuf_recv.c +++ b/code/ecp/rbuf_recv.c @@ -245,24 +245,6 @@ void ecp_rbuf_recv_destroy(ECPConnection *conn) { conn->rbuf.recv = NULL; } -int ecp_rbuf_recv_set_hole(ECPConnection *conn, unsigned short hole_max) { - ECPRBRecv *buf = conn->rbuf.recv; - - buf->hole_max = hole_max; - buf->hole_mask_full = ~(~((ecp_ack_t)1) << (hole_max * 2)); - buf->hole_mask_empty = ~(~((ecp_ack_t)1) << (hole_max + 1)); - - return ECP_OK; -} - -int ecp_rbuf_recv_set_delay(ECPConnection *conn, ecp_pts_t delay) { - ECPRBRecv *buf = conn->rbuf.recv; - - buf->deliver_delay = delay; - - return ECP_OK; -} - int ecp_rbuf_recv_start(ECPConnection *conn, ecp_seq_t seq) { int rv; ECPRBRecv *buf = conn->rbuf.recv; @@ -284,6 +266,24 @@ int ecp_rbuf_recv_start(ECPConnection *conn, ecp_seq_t seq) { return ECP_OK; } +int ecp_rbuf_recv_set_hole(ECPConnection *conn, unsigned short hole_max) { + ECPRBRecv *buf = conn->rbuf.recv; + + buf->hole_max = hole_max; + buf->hole_mask_full = ~(~((ecp_ack_t)1) << (hole_max * 2)); + buf->hole_mask_empty = ~(~((ecp_ack_t)1) << (hole_max + 1)); + + return ECP_OK; +} + +int ecp_rbuf_recv_set_delay(ECPConnection *conn, ecp_pts_t delay) { + ECPRBRecv *buf = conn->rbuf.recv; + + buf->deliver_delay = delay; + + return ECP_OK; +} + ssize_t ecp_rbuf_recv_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, size_t msg_size, ECP2Buffer *b) { ECPRBRecv *buf = conn->rbuf.recv; ecp_seq_t ack_pkt = 0; diff --git a/code/ecp/rbuf_send.c b/code/ecp/rbuf_send.c index 975306a..82c4272 100644 --- a/code/ecp/rbuf_send.c +++ b/code/ecp/rbuf_send.c @@ -235,6 +235,14 @@ void ecp_rbuf_send_destroy(ECPConnection *conn) { conn->rbuf.send = NULL; } +int ecp_rbuf_send_start(ECPConnection *conn) { + ECPRBSend *buf = conn->rbuf.send; + + if (buf == NULL) return ECP_ERR; + + return ecp_rbuf_start(&buf->rbuf, conn->seq_out); +} + int ecp_rbuf_send_set_wsize(ECPConnection *conn, ecp_win_t size) { ECPRBSend *buf = conn->rbuf.send; @@ -254,15 +262,7 @@ int ecp_rbuf_send_set_wsize(ECPConnection *conn, ecp_win_t size) { return ECP_OK; } -int ecp_rbuf_send_start(ECPConnection *conn) { - ECPRBSend *buf = conn->rbuf.send; - - if (buf == NULL) return ECP_ERR; - - return ecp_rbuf_start(&buf->rbuf, conn->seq_out); -} - -int ecp_rbuf_flush(ECPConnection *conn) { +int ecp_rbuf_send_flush(ECPConnection *conn) { ECPRBSend *buf = conn->rbuf.send; ecp_seq_t seq; |