diff options
author | Uros Majstorovic <majstor@majstor.org> | 2017-08-14 19:56:03 +0200 |
---|---|---|
committer | Uros Majstorovic <majstor@majstor.org> | 2017-08-14 19:56:03 +0200 |
commit | db44820eb01106f7780c7126e53885e8b34c8aea (patch) | |
tree | 1afc52869291ddd4dc2279296d35c39999743095 /code/core | |
parent | 8a59506a23eb3133fa510c19993865f661aec0f4 (diff) |
fixed race condition in send rbuf
Diffstat (limited to 'code/core')
-rw-r--r-- | code/core/rbuf_send.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/code/core/rbuf_send.c b/code/core/rbuf_send.c index 4176726..78c60c3 100644 --- a/code/core/rbuf_send.c +++ b/code/core/rbuf_send.c @@ -20,16 +20,23 @@ static void cc_flush(ECPConnection *conn) { int i; if (pkt_to_send) { - unsigned int _idx = ecp_rbuf_msg_idx(rbuf, buf->seq_cc); + unsigned int idx = ecp_rbuf_msg_idx(rbuf, buf->seq_cc); + unsigned int _idx = idx; + + for (i=0; i<pkt_to_send; i++) { + if (!(rbuf->msg[_idx].flags & ECP_RBUF_FLAG_CCWAIT)) break; + rbuf->msg[_idx].flags &= ~ECP_RBUF_FLAG_CCWAIT; + _idx = ECP_RBUF_IDX_MASK(_idx + 1, rbuf->msg_size); + } + pkt_to_send = i; + _idx = idx; #ifdef ECP_WITH_PTHREAD pthread_mutex_unlock(&buf->mutex); #endif for (i=0; i<pkt_to_send; i++) { - if (!(rbuf->msg[_idx].flags & ECP_RBUF_FLAG_CCWAIT)) break; ecp_pkt_send(conn->sock, &conn->node.addr, rbuf->msg[_idx].msg, rbuf->msg[_idx].size); - rbuf->msg[_idx].flags &= ~ECP_RBUF_FLAG_CCWAIT; _idx = ECP_RBUF_IDX_MASK(_idx + 1, rbuf->msg_size); } @@ -37,9 +44,9 @@ static void cc_flush(ECPConnection *conn) { pthread_mutex_lock(&buf->mutex); #endif - buf->in_transit += (ecp_win_t)i; - buf->cc_wait -= (ecp_win_t)i; - buf->seq_cc += (ecp_seq_t)i; + buf->in_transit += (ecp_win_t)pkt_to_send; + buf->cc_wait -= (ecp_win_t)pkt_to_send; + buf->seq_cc += (ecp_seq_t)pkt_to_send; } } |