From: Andre Noll Date: Tue, 25 May 2010 07:23:44 +0000 (+0200) Subject: Merge commit 'meins/master' X-Git-Tag: v0.4.3~20 X-Git-Url: http://git.tuebingen.mpg.de/?p=paraslash.git;a=commitdiff_plain;h=80ce39491e340c83d05c2fa433f5033bd7bd80d4;hp=64304d6ac539be6aa08d2f022b69f60089dee7ce Merge commit 'meins/master' --- diff --git a/fecdec_filter.c b/fecdec_filter.c index 10f1c642..939f7e3d 100644 --- a/fecdec_filter.c +++ b/fecdec_filter.c @@ -61,6 +61,8 @@ struct fecdec_group { struct fec_header h; /** How many slices received so far. */ int num_received_slices; + /** Bitmap of received slices. */ + uint8_t received_slices[32]; /** The size of the \a idx and the \a data arrays below. */ int num_slices; /** Array of indices of the received slices. */ @@ -102,18 +104,11 @@ static void clear_group(struct fecdec_group *fg) { int i; - for (i = 0; i < fg->num_slices; i++) { + for (i = 0; i < fg->num_slices; i++) free(fg->data[i]); - fg->data[i] = NULL; - fg->idx[i] = -1; - } free(fg->data); - fg->data = NULL; free(fg->idx); - fg->idx = NULL; - fg->num_slices = 0; - memset(&fg->h, 0, sizeof(struct fec_header)); - fg->num_received_slices = 0; + memset(fg, 0, sizeof(*fg)); } static int find_group(struct fec_header *h, @@ -213,29 +208,40 @@ success: return ret; } +static bool test_and_set_slice_bit(struct fecdec_group *fg, uint8_t slice_num) +{ + uint8_t *p = fg->received_slices + slice_num / 8, old = *p; + + *p |= 1 << (slice_num % 8); + return old == *p; +} + /* * returns 1 if slice was added, zero otherwise (because the group was already - * complete). In any case the number of received slices is being increased by - * one. + * complete or a slice has been received twice). */ static int add_slice(char *buf, struct fecdec_group *fg) { - int r, slice_num; + int r; + uint8_t slice_num = fg->h.slice_num; if (group_complete(fg)) { PARA_DEBUG_LOG("group %d complete, ignoring slice %d\n", - fg->h.group_num, fg->h.slice_num); - fg->num_received_slices++; + fg->h.group_num, slice_num); return 0; } - slice_num = fg->h.slice_num; if (fg->num_slices == 0) { fg->num_slices = fg->h.slices_per_group; fg->idx = para_malloc(fg->num_slices * sizeof(int)); - fg->data = para_malloc(fg->num_slices * sizeof(unsigned char *)); - memset(fg->data, 0, fg->num_slices * sizeof(unsigned char *)); + fg->data = para_calloc(fg->num_slices * sizeof(unsigned char *)); } r = fg->num_received_slices; + /* Check if we already have this slice. */ + if (test_and_set_slice_bit(fg, slice_num)) { + PARA_INFO_LOG("ignoring duplicate slice %d:%d\n", fg->h.group_num, + slice_num); + return 0; + } fg->idx[r] = slice_num; fg->data[r] = para_malloc(fg->h.slice_bytes); memcpy(fg->data[r], buf, fg->h.slice_bytes); diff --git a/string.c b/string.c index 05febebf..c228c24c 100644 --- a/string.c +++ b/string.c @@ -521,9 +521,9 @@ __printf_2_3 int para_printf(struct para_buffer *b, const char *fmt, ...) } } -/** \cond LLONG_MAX and LLONG_LIN might not be defined. */ +/** \cond LLONG_MAX and LLONG_MIN might not be defined. */ #ifndef LLONG_MAX -#define LLONG_MAX (1 << (sizeof(long) - 1)) +#define LLONG_MAX 9223372036854775807LL #endif #ifndef LLONG_MIN #define LLONG_MIN (-LLONG_MAX - 1LL)