removed unnecessary code

This commit is contained in:
cozis
2023-11-01 21:39:33 +01:00
parent c3f4a52b6d
commit e76bd74c6f
2 changed files with 6 additions and 59 deletions
+3 -53
View File
@@ -143,7 +143,6 @@ const char *microtcp_strerror(microtcp_errcode_t errcode)
case MICROTCP_ERRCODE_CANTBLOCK: return "Can't execute a blocking call for this function"; case MICROTCP_ERRCODE_CANTBLOCK: return "Can't execute a blocking call for this function";
case MICROTCP_ERRCODE_WOULDBLOCK: return "Can't executa e non-blocking call for this function"; case MICROTCP_ERRCODE_WOULDBLOCK: return "Can't executa e non-blocking call for this function";
case MICROTCP_ERRCODE_NOTCONNECTION: return "Invalid operation on a non-connection socket"; case MICROTCP_ERRCODE_NOTCONNECTION: return "Invalid operation on a non-connection socket";
case MICROTCP_ERRCODE_PEERCLOSED: return "Peer closed the connection";
} }
return "???"; return "???";
} }
@@ -159,27 +158,11 @@ typedef struct {
uint16_t proto; uint16_t proto;
} __attribute__((packed)) ethernet_frame_t; } __attribute__((packed)) ethernet_frame_t;
static_assert(sizeof(ethernet_frame_t) == 14);
#ifdef MICROTCP_DEBUG
static bool is_valid_buffer_pointer(microtcp_t *mtcp, buffer_t *buffer)
{
for (size_t i = 0; i < MICROTCP_MAX_BUFFERS; i++)
if (buffer == mtcp->buffer_pool + i)
return true;
return false;
}
#endif
static void send_arp_packet(void *data, mac_address_t dst) static void send_arp_packet(void *data, mac_address_t dst)
{ {
microtcp_t *mtcp = data; microtcp_t *mtcp = data;
buffer_t *buffer = mtcp->used_buffer; buffer_t *buffer = mtcp->used_buffer;
#ifdef MICROTCP_DEBUG
assert(is_valid_buffer_pointer(mtcp, buffer));
#endif
buffer->used = sizeof(ethernet_frame_t) + sizeof(arp_packet_t); buffer->used = sizeof(ethernet_frame_t) + sizeof(arp_packet_t);
ethernet_frame_t *frame = (ethernet_frame_t*) buffer->data; ethernet_frame_t *frame = (ethernet_frame_t*) buffer->data;
@@ -187,8 +170,6 @@ static void send_arp_packet(void *data, mac_address_t dst)
frame->src = mtcp->mac; frame->src = mtcp->mac;
frame->proto = cpu_to_net_u16(ETHERNET_PROTOCOL_ARP); frame->proto = cpu_to_net_u16(ETHERNET_PROTOCOL_ARP);
// TODO: What about the CRC?
int n = mtcp->callbacks.send(mtcp->callbacks.data, buffer->data, buffer->used); int n = mtcp->callbacks.send(mtcp->callbacks.data, buffer->data, buffer->used);
if (n < 0) if (n < 0)
MICROTCP_DEBUG_LOG("Couldn't send (%s)", strerror(errno)); MICROTCP_DEBUG_LOG("Couldn't send (%s)", strerror(errno));
@@ -209,12 +190,6 @@ static void move_wait_buffer_to_free_list(buffer_t *buffer)
{ {
microtcp_t *mtcp = buffer->mtcp; microtcp_t *mtcp = buffer->mtcp;
#ifdef MICROTCP_DEBUG
assert(is_valid_buffer_pointer(mtcp, buffer));
assert(buffer->prev == NULL || is_valid_buffer_pointer(mtcp, buffer->prev));
assert(buffer->next == NULL || is_valid_buffer_pointer(mtcp, buffer->next));
#endif
if (buffer->prev) if (buffer->prev)
buffer->prev->next = buffer->next; buffer->prev->next = buffer->next;
else else
@@ -223,12 +198,6 @@ static void move_wait_buffer_to_free_list(buffer_t *buffer)
if (buffer->next) if (buffer->next)
buffer->next->prev = buffer->prev; buffer->next->prev = buffer->prev;
#ifdef MICROTCP_DEBUG
assert(mtcp->free_buffer_list == NULL || is_valid_buffer_pointer(mtcp, mtcp->free_buffer_list));
assert(mtcp->free_buffer_list == NULL || mtcp->free_buffer_list->prev == NULL);
assert(mtcp->free_buffer_list == NULL || mtcp->free_buffer_list->next == NULL || is_valid_buffer_pointer(mtcp, mtcp->free_buffer_list->next));
#endif
buffer->prev = NULL; buffer->prev = NULL;
buffer->next = mtcp->free_buffer_list; buffer->next = mtcp->free_buffer_list;
mtcp->free_buffer_list = buffer; mtcp->free_buffer_list = buffer;
@@ -239,11 +208,8 @@ static void mac_resolved(void *data, arp_resolution_status_t status, mac_address
buffer_t *buffer = data; buffer_t *buffer = data;
microtcp_t *mtcp = buffer->mtcp; microtcp_t *mtcp = buffer->mtcp;
#ifdef MICROTCP_DEBUG
assert(is_valid_buffer_pointer(mtcp, buffer));
#endif
switch (status) { switch (status) {
case ARP_RESOLUTION_OK: case ARP_RESOLUTION_OK:
{ {
ethernet_frame_t *frame = (ethernet_frame_t*) buffer->data; ethernet_frame_t *frame = (ethernet_frame_t*) buffer->data;
@@ -255,13 +221,8 @@ static void mac_resolved(void *data, arp_resolution_status_t status, mac_address
} }
break; break;
case ARP_RESOLUTION_FAILED: case ARP_RESOLUTION_FAILED: MICROTCP_DEBUG_LOG("MAC resolution failed"); break;
MICROTCP_DEBUG_LOG("MAC resolution failed"); case ARP_RESOLUTION_TIMEOUT: MICROTCP_DEBUG_LOG("MAC resolution timeout"); break;
break;
case ARP_RESOLUTION_TIMEOUT:
MICROTCP_DEBUG_LOG("MAC resolution timeout");
break;
} }
move_wait_buffer_to_free_list(buffer); move_wait_buffer_to_free_list(buffer);
@@ -272,10 +233,6 @@ static void move_used_buffer_to_wait_list(microtcp_t *mtcp)
buffer_t *buffer = mtcp->used_buffer; buffer_t *buffer = mtcp->used_buffer;
mtcp->used_buffer = NULL; mtcp->used_buffer = NULL;
#ifdef MICROTCP_DEBUG
assert(is_valid_buffer_pointer(mtcp, buffer));
#endif
buffer->next = mtcp->wait_buffer_list; buffer->next = mtcp->wait_buffer_list;
if (mtcp->wait_buffer_list) if (mtcp->wait_buffer_list)
mtcp->wait_buffer_list->prev = buffer; mtcp->wait_buffer_list->prev = buffer;
@@ -287,13 +244,6 @@ static void move_used_buffer_to_wait_list(microtcp_t *mtcp)
static void use_a_buffer(microtcp_t *mtcp) static void use_a_buffer(microtcp_t *mtcp)
{ {
#ifdef MIRCOTCP_DEBUG
assert(mtcp->free_buffer_list == NULL || is_valid_buffer_pointer(mtcp, mtcp->free_buffer_list));
assert(mtcp->free_buffer_list == NULL || mtcp->free_buffer_list->prev == NULL);
assert(mtcp->free_buffer_list == NULL || mtcp->free_buffer_list->next == NULL || is_valid_buffer_pointer(mtcp, mtcp->free_buffer_list->next));
#endif
// At this moment the network stack has no allocated // At this moment the network stack has no allocated
// output buffer but wants to allocate one (by calling // output buffer but wants to allocate one (by calling
// this function). // this function).
-3
View File
@@ -36,9 +36,6 @@ typedef enum {
// Returned by microtcp_accept, microtcp_recv and microtcp_send // Returned by microtcp_accept, microtcp_recv and microtcp_send
MICROTCP_ERRCODE_WOULDBLOCK, MICROTCP_ERRCODE_WOULDBLOCK,
// Returned by microtcp_recv, microtcp_send
MICROTCP_ERRCODE_PEERCLOSED,
} microtcp_errcode_t; } microtcp_errcode_t;
typedef struct { typedef struct {