Added window_buffer_resize function

This commit is contained in:
frekky 2015-08-23 22:11:28 +08:00
parent 5df91ed775
commit 391bf5224a
2 changed files with 27 additions and 1 deletions

View File

@ -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)
{

View File

@ -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) */