mirror of
https://github.com/yarrick/iodine.git
synced 2024-11-25 11:05:15 +00:00
Fixed window_sending + made debug output nicer
This commit is contained in:
parent
4403e950a9
commit
2be624c9a6
19
src/window.c
19
src/window.c
@ -232,18 +232,18 @@ window_reassemble_data(struct frag_buffer *w, uint8_t *data, size_t maxlen, int
|
|||||||
|
|
||||||
/* Returns number of fragments that can be sent immediately; effectively
|
/* Returns number of fragments that can be sent immediately; effectively
|
||||||
* the same as window_get_next_sending_fragment but without changing anything. */
|
* the same as window_get_next_sending_fragment but without changing anything. */
|
||||||
int
|
size_t
|
||||||
window_sending(struct frag_buffer *w)
|
window_sending(struct frag_buffer *w)
|
||||||
{
|
{
|
||||||
fragment *f;
|
fragment *f;
|
||||||
int tosend = 0;
|
size_t tosend = 0;
|
||||||
if (w->numitems == 0)
|
if (w->numitems == 0)
|
||||||
return 0;
|
return 0;
|
||||||
for (size_t i = 0; i < w->windowsize; i++) {
|
for (size_t i = 0; i < w->windowsize; i++) {
|
||||||
f = &w->frags[WRAP(w->window_start + i)];
|
f = &w->frags[WRAP(w->window_start + i)];
|
||||||
if (f->len == 0 || f->acks >= 1) continue;
|
if (f->len == 0 || f->acks >= 1) continue;
|
||||||
if ((f->retries == 0) != (difftime(time(NULL), f->lastsent) > ACK_TIMEOUT)) {
|
if (f->retries < 1 || difftime(time(NULL), f->lastsent) >= ACK_TIMEOUT) {
|
||||||
/* Fragment not sent xor timed out (to be re-sent) */
|
/* Fragment not sent or timed out (to be re-sent) */
|
||||||
tosend++;
|
tosend++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -262,7 +262,7 @@ window_get_next_sending_fragment(struct frag_buffer *w, int *other_ack)
|
|||||||
f = &w->frags[WRAP(w->window_start + i)];
|
f = &w->frags[WRAP(w->window_start + i)];
|
||||||
if (f->acks >= 1) continue;
|
if (f->acks >= 1) continue;
|
||||||
/* TODO: use timeval for more precise timeouts */
|
/* TODO: use timeval for more precise timeouts */
|
||||||
if (f->retries >= 1 && difftime(time(NULL), f->lastsent) > ACK_TIMEOUT) {
|
if (f->retries >= 1 && difftime(time(NULL), f->lastsent) >= ACK_TIMEOUT) {
|
||||||
/* Fragment sent before, not ACK'd */
|
/* Fragment sent before, not ACK'd */
|
||||||
DEBUG("Sending fragment %u again, %u retries so far, %u resent overall\n", f->seqID, f->retries, w->resends);
|
DEBUG("Sending fragment %u again, %u retries so far, %u resent overall\n", f->seqID, f->retries, w->resends);
|
||||||
w->resends ++;
|
w->resends ++;
|
||||||
@ -328,17 +328,20 @@ window_ack(struct frag_buffer *w, int seqid)
|
|||||||
void
|
void
|
||||||
window_tick(struct frag_buffer *w)
|
window_tick(struct frag_buffer *w)
|
||||||
{
|
{
|
||||||
|
unsigned old_start_id;
|
||||||
for (size_t i = 0; i < w->windowsize; i++) {
|
for (size_t i = 0; i < w->windowsize; i++) {
|
||||||
if (w->frags[w->window_start].acks >= 1) {
|
if (w->frags[w->window_start].acks >= 1) {
|
||||||
DEBUG("moving window forwards 1; start = %lu-%lu, end = %lu-%lu, len = %lu",
|
old_start_id = w->start_seq_id;
|
||||||
w->window_start, AFTER(w, 1), w->window_end, AFTER(w, w->windowsize + 1), w->length);
|
w->start_seq_id = (w->start_seq_id + 1) % MAX_SEQ_ID;
|
||||||
|
DEBUG("moving window forwards; %lu-%lu (%u) to %lu-%lu (%u) len=%lu",
|
||||||
|
w->window_start, w->window_end, old_start_id, AFTER(w, 1),
|
||||||
|
AFTER(w, w->windowsize + 1), w->start_seq_id, w->length);
|
||||||
if (w->direction == WINDOW_SENDING) {
|
if (w->direction == WINDOW_SENDING) {
|
||||||
DEBUG("Clearing old fragments in SENDING window.");
|
DEBUG("Clearing old fragments in SENDING window.");
|
||||||
w->numitems --; /* Clear old fragments */
|
w->numitems --; /* Clear old fragments */
|
||||||
memset(&w->frags[w->window_start], 0, sizeof(fragment));
|
memset(&w->frags[w->window_start], 0, sizeof(fragment));
|
||||||
}
|
}
|
||||||
w->window_start = AFTER(w, 1);
|
w->window_start = AFTER(w, 1);
|
||||||
w->start_seq_id = (w->start_seq_id + 1) % MAX_SEQ_ID;
|
|
||||||
|
|
||||||
w->window_end = AFTER(w, w->windowsize);
|
w->window_end = AFTER(w, w->windowsize);
|
||||||
} else break;
|
} else break;
|
||||||
|
@ -62,7 +62,7 @@ extern int window_debug;
|
|||||||
|
|
||||||
#ifdef DEBUG_BUILD
|
#ifdef DEBUG_BUILD
|
||||||
#define DEBUG(...) if (window_debug) {\
|
#define DEBUG(...) if (window_debug) {\
|
||||||
fprintf(stderr, "[WINDOW-DEBUG] (%s:%d)", __FILE__, __LINE__);\
|
fprintf(stderr, "[WINDOW-DEBUG] (%s:%d) ", __FILE__, __LINE__);\
|
||||||
fprintf(stderr, __VA_ARGS__);\
|
fprintf(stderr, __VA_ARGS__);\
|
||||||
fprintf(stderr, "\n");\
|
fprintf(stderr, "\n");\
|
||||||
}
|
}
|
||||||
@ -120,7 +120,7 @@ int window_process_incoming_fragment(struct frag_buffer *w, fragment *f);
|
|||||||
size_t window_reassemble_data(struct frag_buffer *w, uint8_t *data, size_t maxlen, int *compression);
|
size_t window_reassemble_data(struct frag_buffer *w, uint8_t *data, size_t maxlen, int *compression);
|
||||||
|
|
||||||
/* Returns number of fragments to be sent */
|
/* Returns number of fragments to be sent */
|
||||||
int window_sending(struct frag_buffer *w);
|
size_t window_sending(struct frag_buffer *w);
|
||||||
|
|
||||||
/* Returns next fragment to be sent or NULL if nothing (SEND) */
|
/* Returns next fragment to be sent or NULL if nothing (SEND) */
|
||||||
fragment *window_get_next_sending_fragment(struct frag_buffer *w, int *other_ack);
|
fragment *window_get_next_sending_fragment(struct frag_buffer *w, int *other_ack);
|
||||||
|
Loading…
Reference in New Issue
Block a user