📄 mem.c
字号:
bytes_to_copy = len;
}
}
else
{
/* Set the bytes to copy and the data_len */
d->data_len = len;
bytes_to_copy = d->data_len;
}
}
else
{
/* Check to see if there is data already in the buffer */
if(d->data_len > 0)
{
/* Set the offset past the data in the buffer */
data_off = d->data_len;
/* Set the max buffer size */
if(first_buffer == 0)
max_buf_size = NET_PARENT_BUFFER_SIZE;
else
max_buf_size = NET_MAX_BUFFER_SIZE;
/* Ensure that the data being copied in does not exceed */
/* the max buffer size */
if((d->data_len + s->data_len) > (UINT32)max_buf_size)
{
/* Set the bytes to copy and the data_len */
bytes_to_copy = max_buf_size - d->data_len;
if((s->data_len - off) < (UINT32)bytes_to_copy)
{
bytes_to_copy = s->data_len - off;
}
d->data_len = d->data_len + bytes_to_copy;
}
else
{
/* Set the bytes to copy and the data_len */
bytes_to_copy = s->data_len;
if((s->data_len - off) < (UINT32)bytes_to_copy)
{
bytes_to_copy = s->data_len - off;
}
d->data_len = d->data_len + bytes_to_copy;
}
}
else
{
/* Set the bytes to copy and the data_len */
d->data_len = (s->data_len - off);
bytes_to_copy = d->data_len;
}
}
/* Decrement the total data left to copy in */
len -= bytes_to_copy;
/* Copy the data to the destination */
NU_BLOCK_COPY(d->data_ptr + data_off, s->data_ptr + off, (unsigned int)bytes_to_copy);
/* Set the max buffer size */
if(first_buffer == 0)
max_buf_size = NET_PARENT_BUFFER_SIZE;
else
max_buf_size = NET_MAX_BUFFER_SIZE;
/* Done copying data for this fragment */
if(len == 0)
{
d->next_buffer = NU_NULL;
}
else if(d->data_len >= (UINT32)max_buf_size)
{
/* Advance to next dest buffer */
d = d->next_buffer;
d->data_ptr = d->mem_packet;
d->data_len = 0;
first_buffer = 1;
}
/* Advance to next source buffer */
if((UINT32)(off + bytes_to_copy) >= s->data_len)
{
s = s->next_buffer;
off = 0;
}
else
{
off = off + bytes_to_copy;
}
data_off = 0;
}
} /* MEM_Chain_Copy */
/*************************************************************************
*
* FUNCTION
*
* MEM_Buffer_Remove
*
* DESCRIPTION
*
* Removes a node from a buffer list.
*
* INPUTS
*
* *hdr
* *item
*
* OUTPUTS
*
* None
*
*************************************************************************/
VOID MEM_Buffer_Remove (NET_BUFFER_HEADER *hdr, NET_BUFFER *item)
{
NET_BUFFER *ent, *pre_ent = NU_NULL;
INT old_level;
if ( (!hdr) || (!item) )
return;
/* Temporarily lockout interrupts to protect the global buffer variables. */
old_level = NU_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);
/* Search the linked list until item is found or the end of the list
* is reached.
*/
for (ent = hdr->head;((ent) && (ent != item)); pre_ent = ent, ent = ent->next)
;
/* Make sure the item we are looking for was found. */
if (ent)
{
/* If we're deleting the list head, this is just a dequeue operation */
if (hdr->head == item)
MEM_Buffer_Dequeue(hdr);
else
/* If we are deleting the list tail, we need to reset the tail pointer
* and make the new tail point forward to 0.
*/
if (hdr->tail == item)
{
hdr->tail = pre_ent;
hdr->tail->next = NU_NULL;
}
else /* We're removing this entry from the middle of the list */
pre_ent->next = item->next;
/* Now clear the next pointer since this buffer is no
longer on the list. */
item->next = NU_NULL;
}
/* Restore the previous interrupt lockout level. */
NU_Local_Control_Interrupts(old_level);
}
/*************************************************************************
*
* FUNCTION
*
* MEM_Buffer_Cleanup
*
* DESCRIPTION
*
* This function takes a list header and moves all of the buffers off
* of the list and onto the MEM_Buffer_Freelist. Mainly used to
* deallocate any unprocessed buffers when ever a TCP connection is
* closed.
*
* INPUTS
*
* *hdr Pointer to the head of a linked list.
*
* OUTPUTS
*
* None
*
*************************************************************************/
VOID MEM_Buffer_Cleanup (NET_BUFFER_HEADER *hdr)
{
while(hdr->head)
MEM_Buffer_Chain_Free (hdr, &MEM_Buffer_Freelist);
}
/*************************************************************************
*
* FUNCTION
*
* MEM_Buffer_Insert
*
* DESCRIPTION
*
* Insert an item into a linked list just before lpos and just after
* fpos.
*
* INPUTS
*
* *hdr
* *item
* *lpos
* *fpos
*
* OUTPUTS
*
* *NET_BUFFER
*
*************************************************************************/
NET_BUFFER *MEM_Buffer_Insert(NET_BUFFER_HEADER *hdr, NET_BUFFER *item,
NET_BUFFER *lpos, NET_BUFFER *fpos)
{
INT old_level;
/* Temporarily lockout interrupts to protect the global buffer variables. */
old_level = NU_Local_Control_Interrupts(NU_DISABLE_INTERRUPTS);
/* Make item's next point to lpos */
item->next = lpos;
/* If lpos was the first node in the linked list. We need to make
* hdr's head point to item, which is the new first node.
*/
if (lpos == hdr->head)
hdr->head = item;
else
/* Make fpos point to item. */
fpos->next = item;
/* If fpos is the tail of the list then we neec to update the
headers tail pointer to point at item. */
if (fpos == hdr->tail)
hdr->tail = item;
/* Restore the previous interrupt lockout level. */
NU_Local_Control_Interrupts(old_level);
return(item);
}
/*************************************************************************
*
* FUNCTION
*
* MEM_Buffer_Suspension_HISR
*
* DESCRIPTION
*
* This function resumes the first task on the buffer suspension list
* It then removes that tasks entry from the list.
*
* INPUTS
*
* None
*
* OUTPUTS
*
* None
*
*************************************************************************/
VOID MEM_Buffer_Suspension_HISR (VOID)
{
/* Make sure there is really a task to wake up. */
if (MEM_Buffer_Suspension_List.head)
{
/* Resume the task. */
NU_Resume_Task (MEM_Buffer_Suspension_List.head->waiting_task);
/* Remove this element from the suspension list. */
DLL_Dequeue (&MEM_Buffer_Suspension_List);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -