diff --git a/src/window.c b/src/window.c index 45bc2fd..a99e061 100644 --- a/src/window.c +++ b/src/window.c @@ -25,6 +25,12 @@ #include "common.h" #include "window.h" +void +window_buffer_reset(struct frag_buffer *w) +{ + +} + struct frag_buffer * window_buffer_init(size_t length, unsigned windowsize, unsigned fragsize, int dir) { @@ -53,6 +59,26 @@ window_buffer_init(size_t length, unsigned windowsize, unsigned fragsize, int di return buf; } +void +window_buffer_resize(struct frag_buffer *w, size_t length) +{ + if (w->length == length) return; + if (w->numitems > 0) { + warnx("Resizing window buffer with things still in it! This will cause problems!"); + } + if (w->frags) free(w->frags); + w->frags = calloc(length, sizeof(fragment)); + if (!w->frags) { + errx(1, "Failed to resize window buffer!"); + } + w->length = length; + w->numitems = 0; + w->window_start = 0; + w->start_seq_id = 0; + w->cur_seq_id = 0; + w->window_end = AFTER(w, w->windowsize); +} + void window_buffer_destroy(struct frag_buffer *w) { diff --git a/src/window.h b/src/window.h index 2d71910..fc9e506 100644 --- a/src/window.h +++ b/src/window.h @@ -46,7 +46,6 @@ struct frag_buffer { size_t numitems; /* number of non-empty fragments stored in buffer */ size_t window_start; /* Start of window */ size_t window_end; /* End of window (index) */ -// size_t last_sent; /* Last fragment sent (index) */ size_t last_write; /* Last fragment read/written */ size_t chunk_start; /* Start of current chunk of fragments, ie where fragno = 0 */ unsigned cur_seq_id; /* Most recent sequence ID */ @@ -73,6 +72,7 @@ struct frag_buffer { #define WRAP(x) ((x) % w->length) struct frag_buffer *window_buffer_init(size_t length, unsigned windowsize, unsigned fragsize, int dir); +void window_buffer_resize(struct frag_buffer *w, size_t length); void window_buffer_destroy(struct frag_buffer *w); /* Returns number of available fragment slots (NOT BYTES) */