mirror of
https://github.com/Zeal-Operating-System/ZealOS.git
synced 2024-12-29 00:36:32 +00:00
Clean up UDP queue find a bit
This commit is contained in:
parent
5ef1d5ef57
commit
1be8f456f0
2 changed files with 53 additions and 46 deletions
Binary file not shown.
|
@ -23,7 +23,7 @@ class CUDPSocket
|
||||||
U8 *receive_buffer;
|
U8 *receive_buffer;
|
||||||
I64 receive_len;
|
I64 receive_len;
|
||||||
|
|
||||||
CSocketAddressStorage receive_address; // based on ->family, cast or assign pointer as IPV4/IPV6 CSocketAddress
|
CSocketAddressStorage receive_address; // based on ->family, cast or assign to a var as IPV4/IPV6 CSocketAddress
|
||||||
|
|
||||||
U16 bound_to; // represents the currently bound port
|
U16 bound_to; // represents the currently bound port
|
||||||
};
|
};
|
||||||
|
@ -243,24 +243,30 @@ CUDPTreeQueue *UDPTreeNodeQueueSocketFind(CUDPSocket *socket, CUDPTreeNode *node
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
CUDPTreeQueue *UDPTreeNodeQueueFind(U32 address, CUDPTreeNode *node)
|
CUDPTreeQueue *UDPTreeNodeQueueIPV4Find(U32 address, CUDPTreeNode *node)
|
||||||
{ // address should be pulled from an instance of CIPV4Address (TODO... double check what bit order we're in ?)
|
{ // address should be pulled from an instance of CIPV4Address (TODO... double check what bit order we're in ?)
|
||||||
|
|
||||||
CUDPTreeQueue *temp_queue;
|
CUDPTreeQueue *temp_queue;
|
||||||
|
CSocketAddressIPV4 *temp_ip;
|
||||||
|
|
||||||
if (node->queue)
|
if (node->queue)
|
||||||
{
|
{
|
||||||
if (node->queue->socket->receive_address.family != AF_INET)
|
if (node->queue->socket->receive_address.family == AF_INET)
|
||||||
Debug("This method was made for IPV4, UDP can be IPV4 or IPV6. excessive casting bad, TODO: revise method.");
|
{
|
||||||
|
temp_ip = &node->queue->socket->receive_address;
|
||||||
if (node->queue->socket->receive_address(CSocketAddressIPV4).address == address)
|
if (temp_ip->address == address)
|
||||||
return node->queue;
|
return node->queue;
|
||||||
|
}
|
||||||
|
|
||||||
temp_queue = node->queue->next;
|
temp_queue = node->queue->next;
|
||||||
while (temp_queue != node->queue)
|
while (temp_queue != node->queue)
|
||||||
{
|
{
|
||||||
if (temp_queue->socket->receive_address(CSocketAddressIPV4).address == address)
|
if (temp_queue->socket->receive_address.family == AF_INET)
|
||||||
|
{
|
||||||
|
temp_ip = &temp_queue->socket->receive_address;
|
||||||
|
if (temp_ip->address == address)
|
||||||
return temp_queue;
|
return temp_queue;
|
||||||
|
}
|
||||||
|
|
||||||
temp_queue = temp_queue->next;
|
temp_queue = temp_queue->next;
|
||||||
}
|
}
|
||||||
|
@ -286,6 +292,7 @@ CUDPTreeQueue *UDPTreeNodeQueueSocketSinglePop(CUDPSocket *socket, CUDPTreeNode
|
||||||
temp_next->last = temp_last;
|
temp_next->last = temp_last;
|
||||||
temp_queue->next = temp_queue;
|
temp_queue->next = temp_queue;
|
||||||
temp_queue->last = temp_queue;
|
temp_queue->last = temp_queue;
|
||||||
|
|
||||||
if (temp_queue == node->queue) // if entry to pop is node queue head, change head to next
|
if (temp_queue == node->queue) // if entry to pop is node queue head, change head to next
|
||||||
node->queue = temp_next;
|
node->queue = temp_next;
|
||||||
}
|
}
|
||||||
|
@ -457,7 +464,7 @@ I64 UDPSocketBind(CUDPSocket *udp_socket, CSocketAddressStorage *address_in) //
|
||||||
|
|
||||||
if (temp_node)
|
if (temp_node)
|
||||||
{ // if we find we have bound sockets at port, check address before adding to queue
|
{ // if we find we have bound sockets at port, check address before adding to queue
|
||||||
if (UDPTreeNodeQueueFind(udp_socket->receive_address(CSocketAddressIPV4).address.address, temp_node))
|
if (UDPTreeNodeQueueIPV4Find(udp_socket->receive_address(CSocketAddressIPV4).address.address, temp_node))
|
||||||
{
|
{
|
||||||
ZenithErr("Attempted UDP Socket Bind at an address already in Bound Socket Tree !\n");
|
ZenithErr("Attempted UDP Socket Bind at an address already in Bound Socket Tree !\n");
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue