[PACKET_IO] add function for operating packets

This commit is contained in:
liuwentan
2022-08-09 18:32:25 +08:00
parent c2d5b9cdb7
commit 873b25794b
10 changed files with 218 additions and 55 deletions

View File

@@ -1,6 +1,6 @@
/*
**********************************************************************************************
* File: packet_queue.cpp
* File: pio_packet_queue.cpp
* Description:
* Authors: Liu WenTan <liuwentan@geedgenetworks.com>
* Date: 2022-07-15
@@ -8,9 +8,23 @@
***********************************************************************************************
*/
#include <string.h>
#include "../../sdk/include/utils.h"
#include "pio_packet_queue.h"
static int packet_copy_data_offset(uint8_t *ptr, uint32_t offset, const uint8_t *data, uint32_t data_len)
{
memcpy(ptr + offset, data, data_len);
return 0;
}
int packet_copy_data(uint8_t *ptr, const uint8_t *pkt_data, uint32_t pkt_len)
{
return packet_copy_data_offset(ptr, 0, pkt_data, pkt_len);
}
void pio_packet_enqueue(struct pio_packet_queue *q, struct pio_packet *p)
{
if (nullptr == p)

View File

@@ -21,7 +21,7 @@
#define SIZE_OF_PIO_PACKET (DEFAULT_PACKET_SIZE + sizeof(struct pio_packet))
/*
/**
* @brief pcap_live/pcap_file mode packet structure
*
* |<-pkt_hdr |<-pkt_payload
@@ -37,13 +37,13 @@ struct pio_packet {
void *pkt_hdr;
/* pkt length */
uint64_t pkt_len;
uint32_t pkt_len;
/* pkt payload pointer */
void *pkt_payload;
/* reference counts */
uint64_t ref_cnt;
uint32_t ref_cnt;
struct pio_packet *prev;
@@ -57,6 +57,8 @@ struct pio_packet_queue {
pthread_mutex_t mutex_q;
};
int packet_copy_data(uint8_t *ptr, const uint8_t *pkt_data, uint32_t pkt_len);
void pio_packet_enqueue(struct pio_packet_queue *, struct pio_packet *);
struct pio_packet *pio_packet_dequeue(struct pio_packet_queue *);
void release_pio_packet_queue(struct pio_packet_queue *);