From 38f5f6389a0d7c17c0f11cc7927625012ae90888 Mon Sep 17 00:00:00 2001 From: Ludovic Pouzenc Date: Sun, 2 Oct 2016 13:12:23 +0200 Subject: Failed bug fix for partial write (uftp choosen as temporary mcastseed remplacement) --- mcastseed/src/Makefile.am | 4 +-- mcastseed/src/dgrambuf.c | 86 ++++++++++++++++++++++++---------------------- mcastseed/src/mcastleech.c | 4 +-- 3 files changed, 48 insertions(+), 46 deletions(-) (limited to 'mcastseed/src') diff --git a/mcastseed/src/Makefile.am b/mcastseed/src/Makefile.am index c49cf70..2f2a735 100644 --- a/mcastseed/src/Makefile.am +++ b/mcastseed/src/Makefile.am @@ -5,9 +5,7 @@ AM_CFLAGS =\ -Wall \ -Wextra \ -pedantic \ - -Wno-format\ - -O0\ - -g + -Wno-format bin_PROGRAMS = mcastseed mcastleech random_speed_dd diff --git a/mcastseed/src/dgrambuf.c b/mcastseed/src/dgrambuf.c index b440390..5d4c302 100644 --- a/mcastseed/src/dgrambuf.c +++ b/mcastseed/src/dgrambuf.c @@ -237,7 +237,7 @@ int dgrambuf_have_data_ready_to_write(dgrambuf_t dbuf) { unsigned int next_dgram_seq; /* Last write was partial, so there is more to write */ - if ( dbuf->partial_write_remaining_bytes > 0 ) { + if ( dbuf->partial_write_remaining_bytes ) { return 1; } @@ -248,7 +248,7 @@ int dgrambuf_have_data_ready_to_write(dgrambuf_t dbuf) { /* Nothing to write if next dgram is not in buffer at all */ next_dgram_seq = ((struct indexed_uint *) gl_list_get_at(dbuf->dgram_used_slots, 0))->value; - fprintf(stderr, "DEBUG : dgram_seq_base==%u next_dgram_seq == %u\n", dbuf->dgram_seq_base, next_dgram_seq); + /*fprintf(stderr, "DEBUG : dgram_seq_base==%u next_dgram_seq == %u\n", dbuf->dgram_seq_base, next_dgram_seq);*/ if ( next_dgram_seq != dbuf->dgram_seq_base ) { return 0; } @@ -262,9 +262,9 @@ int dgrambuf_have_received_everything(dgrambuf_t dbuf) { } ssize_t dgrambuf_write(dgrambuf_t dbuf, int fd, int *info) { - size_t dgram_index, i, vlen, used_count; + size_t dgram_index, i, vlen, total, len, remain, used_count; unsigned int curr_seq, prev_seq, dgram_len; - ssize_t nwrite, total, remain, len; + ssize_t nwrite; struct iovec *iov; struct indexed_uint *active_slot; bool pos; @@ -272,7 +272,7 @@ ssize_t dgrambuf_write(dgrambuf_t dbuf, int fd, int *info) { /* FIXME Info ptr is mandatory */ *info = 0; - if ( dbuf->partial_write_remaining_bytes > 0 ) { + if ( dbuf->partial_write_remaining_bytes ) { /* Previous writev() was partial, continue it */ iov = dbuf->partial_write_iov; vlen = dbuf->partial_write_remaining_iovcnt; @@ -364,49 +364,53 @@ ssize_t dgrambuf_write(dgrambuf_t dbuf, int fd, int *info) { return -1; } + dbuf->partial_write_remaining_bytes = total - nwrite; if ( nwrite > 0 ) { dbuf->stats.write_byte += nwrite; *info |= DGRAMBUF_WRITE_SUCCESS; - } - /* Check if the write was partially done */ - dbuf->partial_write_remaining_bytes = total - nwrite; - if ( dbuf->partial_write_remaining_bytes > 0 ) { - *info |= DGRAMBUF_WRITE_PARTIAL; - dbuf->stats.write_partial++; - /* Find the partially written iov and update it */ - remain = nwrite; - for (i=0; iiov_write[i].iov_len; - if ( remain < len ) { - dbuf->partial_write_remaining_iovcnt = vlen - i; - dbuf->partial_write_iov = dbuf->iov_write + i; - - dbuf->iov_write[i].iov_base = - (uint8_t *) dbuf->iov_write[i].iov_base + remain; - dbuf->iov_write[i].iov_len -= remain; - break; + if ( dbuf->partial_write_remaining_bytes ) { + /* If the write was partially done */ + *info |= DGRAMBUF_WRITE_PARTIAL; + dbuf->stats.write_partial++; + /* Find the partially written iov and update it */ + remain = nwrite; + for (i=0; iiov_write[i].iov_len; + if ( remain < len ) { + dbuf->partial_write_remaining_iovcnt = vlen - i; + if ( dbuf->partial_write_iov ) { + dbuf->partial_write_iov += i; + } else { + dbuf->partial_write_iov = dbuf->iov_write + i; + } + + dbuf->iov_write[i].iov_base = + (uint8_t *) dbuf->iov_write[i].iov_base + remain; + dbuf->iov_write[i].iov_len -= remain; + break; + } + remain -= len; + } + if ( i == vlen ) { + fprintf(stderr, "Fatal : failed to find partial iov after partial write\n"); + return -3; } - remain -= len; - } - if ( i == vlen ) { - fprintf(stderr, "Fatal : failed to find partial iov after partial write\n"); - return -3; - } - } else { - /* Full write has happened */ - for (i=0; idgram_write_active_slots_count; i++) { - active_slot = (struct indexed_uint *) dbuf->dgram_write_active_slots[i]; - active_slot->value = 0; - pos = gl_sortedlist_nx_add(dbuf->dgram_empty_slots, _compare_indexed_uint, active_slot); - if ( !pos ) /*TODO: better oom handling */ - return -4; + } else { + /* Full write has happened */ + for (i=0; idgram_write_active_slots_count; i++) { + active_slot = (struct indexed_uint *) dbuf->dgram_write_active_slots[i]; + active_slot->value = 0; + pos = gl_sortedlist_nx_add(dbuf->dgram_empty_slots, _compare_indexed_uint, active_slot); + if ( !pos ) /*TODO: better oom handling ? */ + return -4; + } + dbuf->dgram_write_active_slots_count = 0; + /* Wipe outdated partial_* values */ + dbuf->partial_write_iov = NULL; + dbuf->partial_write_remaining_iovcnt = 0; } - dbuf->dgram_write_active_slots_count = 0; - /* Wipe outdated partial_* values for clarity in debug mode (only _bytes is use on branching) */ - dbuf->partial_write_iov = NULL; - dbuf->partial_write_remaining_iovcnt = 0; } return nwrite; diff --git a/mcastseed/src/mcastleech.c b/mcastseed/src/mcastleech.c index 76e1e79..3345665 100644 --- a/mcastseed/src/mcastleech.c +++ b/mcastseed/src/mcastleech.c @@ -218,10 +218,10 @@ int receive_data() { return nwrite; } - fprintf(stderr, "receive_data(): nread == %zi, nwrite == %zi\n", nread, nwrite); + /*fprintf(stderr, "receive_data(): nread == %zi, nwrite == %zi\n", nread, nwrite);*/ /* XXX Crapy dead state detection */ - if ( nread == 0 && nwrite == 0 ) { + if ( nread == 0 /* TEST && nwrite == 0 */ ) { if ( noop_calls_count > 10 ) { return 0; } -- cgit v1.2.3