mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 02:55:15 +00:00
Added window_buffer_resize function
This commit is contained in:
parent
5df91ed775
commit
391bf5224a
26
src/window.c
26
src/window.c
@ -25,6 +25,12 @@
|
|||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "window.h"
|
#include "window.h"
|
||||||
|
|
||||||
|
void
|
||||||
|
window_buffer_reset(struct frag_buffer *w)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
struct frag_buffer *
|
struct frag_buffer *
|
||||||
window_buffer_init(size_t length, unsigned windowsize, unsigned fragsize, int dir)
|
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;
|
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
|
void
|
||||||
window_buffer_destroy(struct frag_buffer *w)
|
window_buffer_destroy(struct frag_buffer *w)
|
||||||
{
|
{
|
||||||
|
@ -46,7 +46,6 @@ struct frag_buffer {
|
|||||||
size_t numitems; /* number of non-empty fragments stored in buffer */
|
size_t numitems; /* number of non-empty fragments stored in buffer */
|
||||||
size_t window_start; /* Start of window */
|
size_t window_start; /* Start of window */
|
||||||
size_t window_end; /* End of window (index) */
|
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 last_write; /* Last fragment read/written */
|
||||||
size_t chunk_start; /* Start of current chunk of fragments, ie where fragno = 0 */
|
size_t chunk_start; /* Start of current chunk of fragments, ie where fragno = 0 */
|
||||||
unsigned cur_seq_id; /* Most recent sequence ID */
|
unsigned cur_seq_id; /* Most recent sequence ID */
|
||||||
@ -73,6 +72,7 @@ struct frag_buffer {
|
|||||||
#define WRAP(x) ((x) % w->length)
|
#define WRAP(x) ((x) % w->length)
|
||||||
|
|
||||||
struct frag_buffer *window_buffer_init(size_t length, unsigned windowsize, unsigned fragsize, int dir);
|
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);
|
void window_buffer_destroy(struct frag_buffer *w);
|
||||||
|
|
||||||
/* Returns number of available fragment slots (NOT BYTES) */
|
/* Returns number of available fragment slots (NOT BYTES) */
|
||||||
|
Loading…
Reference in New Issue
Block a user