diff options
author | Uros Majstorovic <majstor@majstor.org> | 2019-10-19 20:01:25 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2019-10-19 20:01:25 +0200 |
commit | 702f3716075528d6ad390615b5df9b79264b40bb (patch) | |
tree | c00d10a2920eeb26b15d365c191d56f4845c3b11 /code/ecp/rbuf_recv.c | |
parent | 3cbb9793bf5645f400545aeef904a48fe5dca64c (diff) |
fixed transport buf free/flag set interface
Diffstat (limited to 'code/ecp/rbuf_recv.c')
-rw-r--r-- | code/ecp/rbuf_recv.c | 48 |
1 files changed, 24 insertions, 24 deletions
diff --git a/code/ecp/rbuf_recv.c b/code/ecp/rbuf_recv.c index 4bd76cc..b9b16a2 100644 --- a/code/ecp/rbuf_recv.c +++ b/code/ecp/rbuf_recv.c @@ -9,9 +9,9 @@ static ssize_t msg_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, ECPRBRecv *buf = conn->rbuf.recv; unsigned char flags = ECP_RBUF_FLAG_IN_RBUF; unsigned char mtype = ecp_msg_get_type(msg) & ECP_MTYPE_MASK; - + if (mtype < ECP_MAX_MTYPE_SYS) flags |= ECP_RBUF_FLAG_SYS; - + #ifdef ECP_WITH_MSGQ if (buf->flags & ECP_RBUF_FLAG_MSGQ) { int rv = ECP_OK; @@ -20,7 +20,7 @@ static ssize_t msg_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *msg, ecp_seq_t seq_offset = seq - buf->msgq.seq_start; if (seq_offset >= buf->rbuf.msg_size) rv = ECP_ERR_RBUF_FULL; pthread_mutex_unlock(&buf->msgq.mutex); - + if (rv) return rv; } #endif @@ -42,15 +42,15 @@ static void msg_flush(ECPConnection *conn, ECP2Buffer *b) { #endif ecp_seq_t msg_cnt = buf->rbuf.seq_max - buf->rbuf.seq_start + 1; - ecp_seq_t seq_next = buf->rbuf.seq_start; + ecp_seq_t seq_next = buf->rbuf.seq_start; ecp_seq_t i = 0; unsigned int idx = buf->rbuf.msg_start; - + if (buf->timer_pts) { ecp_timer_pop(conn, ECP_MTYPE_RBFLUSH_PTS); buf->timer_pts = 0; } - + for (i=0; i<msg_cnt; i++) { if (buf->rbuf.msg[idx].flags & ECP_RBUF_FLAG_IN_RBUF) { if (buf->rbuf.msg[idx].flags & ECP_RBUF_FLAG_SYS) { @@ -65,7 +65,7 @@ static void msg_flush(ECPConnection *conn, ECP2Buffer *b) { rv = ecp_msg_get_frag(buf->rbuf.msg[idx].msg, buf->rbuf.msg[idx].size, &frag_cnt, &frag_tot); if ((rv == ECP_OK) && (frag_cnt != 0) && (seq != seq_next)) { ecp_seq_t seq_fend = seq + (ecp_seq_t)(frag_tot - frag_cnt - 1); - + if (ECP_SEQ_LT(buf->rbuf.seq_max, seq_fend) || (buf->hole_max && ((ecp_seq_t)(buf->rbuf.seq_max - seq_fend) <= buf->hole_max))) { ecp_seq_t seq_fbeg = seq - frag_cnt; ecp_seq_t seq_offset = ECP_SEQ_LT(seq_next, seq_fbeg) ? seq - seq_fbeg : seq - seq_next; @@ -91,8 +91,8 @@ static void msg_flush(ECPConnection *conn, ECP2Buffer *b) { idx = ECP_RBUF_IDX_MASK(idx - seq_offset, buf->rbuf.msg_size); break; } - } - + } + seq_next = seq + 1; if (buf->flags & ECP_RBUF_FLAG_MSGQ) { #ifdef ECP_WITH_MSGQ @@ -132,7 +132,7 @@ static int ack_send(ECPConnection *conn) { unsigned char pld_buf[ECP_SIZE_PLD_BUF(sizeof(ecp_seq_t) + sizeof(ecp_ack_t), ECP_MTYPE_RBACK, conn)]; unsigned char *buf_ = ecp_pld_get_buf(pld_buf, ECP_MTYPE_RBACK); ssize_t rv; - + packet.buffer = pkt_buf; packet.size = ECP_SIZE_PKT_BUF(sizeof(ecp_seq_t) + sizeof(ecp_ack_t), ECP_MTYPE_RBACK, conn); payload.buffer = pld_buf; @@ -161,7 +161,7 @@ static int ack_shift(ECPRBRecv *buf) { int in_rbuf = 0; int idx; int i; - + if ((buf->flags & ECP_RBUF_FLAG_RELIABLE) && ((buf->ack_map & ACK_MASK_FIRST) == 0)) return 0; while (ECP_SEQ_LT(buf->seq_ack, buf->rbuf.seq_max)) { @@ -169,7 +169,7 @@ static int ack_shift(ECPRBRecv *buf) { in_rbuf = ECP_SEQ_LT(buf->seq_ack, buf->rbuf.seq_start) ? 1 : buf->rbuf.msg[ECP_RBUF_IDX_MASK(buf->rbuf.msg_start + buf->seq_ack - buf->rbuf.seq_start, buf->rbuf.msg_size)].flags & ECP_RBUF_FLAG_IN_RBUF; if (in_rbuf && (buf->ack_map == ECP_ACK_FULL)) continue; - + buf->ack_map = buf->ack_map << 1; if (in_rbuf) { buf->ack_map |= 1; @@ -179,7 +179,7 @@ static int ack_shift(ECPRBRecv *buf) { if ((buf->ack_map & ACK_MASK_FIRST) == 0) break; } - + if (!do_ack && (buf->seq_ack == buf->rbuf.seq_max) && ((buf->ack_map & buf->hole_mask_full) != buf->hole_mask_full)) { ecp_ack_t hole_mask = buf->ack_map; @@ -191,17 +191,17 @@ static int ack_shift(ECPRBRecv *buf) { } } } - + return do_ack; } ssize_t ecp_rbuf_handle_flush(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size, ECP2Buffer *b) { if (size < 0) return size; - + ECPRBRecv *buf = conn->rbuf.recv; if (buf == NULL) return ECP_ERR; - ecp_tr_buf_free(b, ECP_SEND_FLAG_MORE); + ecp_tr_release(b->packet, 1); ack_send(conn); return 0; } @@ -209,7 +209,7 @@ ssize_t ecp_rbuf_handle_flush(ECPConnection *conn, ecp_seq_t seq, unsigned char ssize_t ecp_rbuf_handle_flush_pts(ECPConnection *conn, ecp_seq_t seq, unsigned char mtype, unsigned char *msg, ssize_t size, ECP2Buffer *b) { ECPRBRecv *buf = conn->rbuf.recv; if (buf == NULL) return ECP_ERR; - + buf->timer_pts = 0; msg_flush(conn, b); return 0; @@ -221,7 +221,7 @@ int ecp_rbuf_recv_create(ECPConnection *conn, ECPRBRecv *buf, ECPRBMessage *msg, memset(buf, 0, sizeof(ECPRBRecv)); rv = ecp_rbuf_init(&buf->rbuf, msg, msg_size); if (rv) return rv; - + buf->ack_map = ECP_ACK_FULL; buf->ack_rate = ACK_RATE; @@ -236,7 +236,7 @@ int ecp_rbuf_recv_create(ECPConnection *conn, ECPRBRecv *buf, ECPRBMessage *msg, void ecp_rbuf_recv_destroy(ECPConnection *conn) { ECPRBRecv *buf = conn->rbuf.recv; - + if (buf == NULL) return; #ifdef ECP_WITH_MSGQ ecp_conn_msgq_destroy(&buf->msgq); @@ -250,7 +250,7 @@ int ecp_rbuf_recv_start(ECPConnection *conn, ecp_seq_t seq) { ECPRBRecv *buf = conn->rbuf.recv; if (buf == NULL) return ECP_ERR; - + seq--; buf->seq_ack = seq; rv = ecp_rbuf_start(&buf->rbuf, seq); @@ -262,7 +262,7 @@ int ecp_rbuf_recv_start(ECPConnection *conn, ecp_seq_t seq) { if (rv) return rv; } #endif - + return ECP_OK; } @@ -272,7 +272,7 @@ int ecp_rbuf_recv_set_hole(ECPConnection *conn, unsigned short hole_max) { 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; } @@ -280,7 +280,7 @@ int ecp_rbuf_recv_set_delay(ECPConnection *conn, ecp_pts_t delay) { ECPRBRecv *buf = conn->rbuf.recv; buf->deliver_delay = delay; - + return ECP_OK; } @@ -289,7 +289,7 @@ ssize_t ecp_rbuf_recv_store(ECPConnection *conn, ecp_seq_t seq, unsigned char *m ecp_seq_t ack_pkt = 0; ssize_t rv; unsigned char mtype; - + mtype = ecp_msg_get_type(msg) & ECP_MTYPE_MASK; if ((mtype == ECP_MTYPE_RBACK) || (mtype == ECP_MTYPE_RBFLUSH)) return ecp_msg_handle(conn, seq, msg, msg_size, b); |