HelenOS sources
This source file includes following definitions.
- tcp_iqueue_init
- tcp_iqueue_insert_seg
- tcp_iqueue_remove_seg
- tcp_iqueue_get_ready_seg
#include <adt/list.h>
#include <errno.h>
#include <io/log.h>
#include <stdlib.h>
#include "iqueue.h"
#include "segment.h"
#include "seq_no.h"
#include "tcp_type.h"
void tcp_iqueue_init(tcp_iqueue_t *iqueue, tcp_conn_t *conn)
{
list_initialize(&iqueue->list);
iqueue->conn = conn;
}
void tcp_iqueue_insert_seg(tcp_iqueue_t *iqueue, tcp_segment_t *seg)
{
tcp_iqueue_entry_t *iqe;
tcp_iqueue_entry_t *qe;
link_t *link;
log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_iqueue_insert_seg()");
iqe = calloc(1, sizeof(tcp_iqueue_entry_t));
if (iqe == NULL) {
log_msg(LOG_DEFAULT, LVL_ERROR, "Failed allocating IQE.");
return;
}
iqe->seg = seg;
link = list_first(&iqueue->list);
while (link != NULL) {
qe = list_get_instance(link,
tcp_iqueue_entry_t, link);
if (seq_no_seg_cmp(iqueue->conn, iqe->seg, qe->seg) < 0)
break;
link = list_next(link, &iqueue->list);
}
if (link != NULL)
list_insert_before(&iqe->link, &qe->link);
else
list_append(&iqe->link, &iqueue->list);
}
void tcp_iqueue_remove_seg(tcp_iqueue_t *iqueue, tcp_segment_t *seg)
{
tcp_iqueue_entry_t *qe;
link_t *link;
log_msg(LOG_DEFAULT, LVL_NOTE, "tcp_iqueue_remove_seg()");
link = list_first(&iqueue->list);
while (link != NULL) {
log_msg(LOG_DEFAULT, LVL_NOTE, "tcp_iqueue_remove_seg() - next");
qe = list_get_instance(link,
tcp_iqueue_entry_t, link);
if (qe->seg == seg) {
log_msg(LOG_DEFAULT, LVL_NOTE, "tcp_iqueue_remove_seg() - found, DONE");
list_remove(&qe->link);
free(qe);
return;
}
link = list_next(link, &iqueue->list);
}
log_msg(LOG_DEFAULT, LVL_NOTE, "tcp_iqueue_remove_seg() - not found");
assert(false);
}
errno_t tcp_iqueue_get_ready_seg(tcp_iqueue_t *iqueue, tcp_segment_t **seg)
{
tcp_iqueue_entry_t *iqe;
link_t *link;
log_msg(LOG_DEFAULT, LVL_DEBUG, "tcp_get_ready_seg()");
link = list_first(&iqueue->list);
if (link == NULL) {
log_msg(LOG_DEFAULT, LVL_DEBUG, "iqueue is empty");
return ENOENT;
}
iqe = list_get_instance(link, tcp_iqueue_entry_t, link);
while (!seq_no_segment_acceptable(iqueue->conn, iqe->seg)) {
log_msg(LOG_DEFAULT, LVL_DEBUG, "Skipping unacceptable segment (RCV.NXT=%"
PRIu32 ", RCV.NXT+RCV.WND=%" PRIu32 ", SEG.SEQ=%" PRIu32
", SEG.LEN=%" PRIu32 ")", iqueue->conn->rcv_nxt,
iqueue->conn->rcv_nxt + iqueue->conn->rcv_wnd,
iqe->seg->seq, iqe->seg->len);
list_remove(&iqe->link);
tcp_segment_delete(iqe->seg);
link = list_first(&iqueue->list);
if (link == NULL) {
log_msg(LOG_DEFAULT, LVL_DEBUG, "iqueue is empty");
return ENOENT;
}
iqe = list_get_instance(link, tcp_iqueue_entry_t, link);
}
if (!seq_no_segment_ready(iqueue->conn, iqe->seg)) {
log_msg(LOG_DEFAULT, LVL_DEBUG, "Next segment not ready: SEG.SEQ=%u, "
"RCV.NXT=%u, SEG.LEN=%u", iqe->seg->seq,
iqueue->conn->rcv_nxt, iqe->seg->len);
return ENOENT;
}
log_msg(LOG_DEFAULT, LVL_DEBUG, "Returning ready segment %p", iqe->seg);
list_remove(&iqe->link);
*seg = iqe->seg;
free(iqe);
return EOK;
}
HelenOS homepage, sources at GitHub