- generic Queue implemented - PacketRegistry allocation bug fixed - TCP implementation initials - ALIGN to type macros added
53 lines
1.5 KiB
C
53 lines
1.5 KiB
C
//
|
|
// Created by epagris on 2023.01.16..
|
|
//
|
|
|
|
#include <memory.h>
|
|
#include <stdbool.h>
|
|
#include "tcp_window.h"
|
|
#include "etherlib/dynmem.h"
|
|
|
|
TcpWindow *tcpw_create(uint32_t size) {
|
|
uint32_t allocSize = sizeof(TcpWindow) + size; // calculate full allocation size
|
|
TcpWindow * win = (TcpWindow *) dynmem_alloc(allocSize); // allocate data block at the end
|
|
mp_init(win->data, size); // initialize memory pool
|
|
|
|
return win;
|
|
}
|
|
|
|
#define TCP_WINDOW_MAX_WINSIZE_PADDING (16) // keep-out zone, this way allocated blocks will not block registry table growth TODO: not the best solution
|
|
|
|
uint32_t tcpw_get_max_window_size(TcpWindow * tcpw) {
|
|
return mp_largest_free_block_size(&tcpw->pool) - sizeof(TcpWindowSegment) - TCP_WINDOW_MAX_WINSIZE_PADDING;
|
|
}
|
|
|
|
TcpWindowSegment * tcpw_store_segment(TcpWindow * tcpw, const uint8_t * data, uint32_t size, uint32_t seqNum) {
|
|
TcpWindowSegment * seg = (TcpWindowSegment *) mp_alloc(&tcpw->pool, sizeof(TcpWindowSegment) + size);
|
|
if (seg == NULL) { // could not store...
|
|
return NULL;
|
|
}
|
|
|
|
// store segment descriptor
|
|
seg->size = size;
|
|
seg->seqNum = seqNum;
|
|
|
|
// store segment
|
|
memcpy(seg->data, data, size);
|
|
|
|
return seg;
|
|
}
|
|
|
|
static void tcpw_segment_search(MP *mp, const MPAllocRecord * rec, void * userData) {
|
|
TcpWindow * tcpw = (TcpWindow *) userData;
|
|
|
|
}
|
|
|
|
uint32_t tcpw_get_acknowledge(TcpWindow * tcpw) {
|
|
mp_foreach_block(&tcpw->pool, tcpw_segment_search, tcpw, false);
|
|
return 0;
|
|
}
|
|
|
|
void tcpw_set_sequence_number(TcpWindow * tcpw, uint32_t seqNum) {
|
|
tcpw->seqNum = seqNum;
|
|
}
|