Setup server client to have two threads.
This commit is contained in:
@ -18,7 +18,7 @@ void packetQueuePushIn(packetqueue_t *queue, const packet_t *packet) {
|
||||
assertNotNull(queue, "Packet queue is NULL");
|
||||
assertNotNull(packet, "Packet is NULL");
|
||||
assertTrue(
|
||||
queue->packetsInCount < PACKET_QUEUE_MAX_SIZE, "Packet queue is full"
|
||||
queue->packetsInCount < PACKET_QUEUE_MAX_SIZE, "Inbound packet queue is full"
|
||||
);
|
||||
|
||||
queue->packetsIn[queue->packetsInCount++] = *packet;
|
||||
@ -28,8 +28,36 @@ void packetQueuePushOut(packetqueue_t *queue, const packet_t *packet) {
|
||||
assertNotNull(queue, "Packet queue is NULL");
|
||||
assertNotNull(packet, "Packet is NULL");
|
||||
assertTrue(
|
||||
queue->packetsOutCount < PACKET_QUEUE_MAX_SIZE, "Packet queue is full"
|
||||
queue->packetsOutCount < PACKET_QUEUE_MAX_SIZE, "Outbound packet queue is full"
|
||||
);
|
||||
|
||||
queue->packetsOut[queue->packetsOutCount++] = *packet;
|
||||
}
|
||||
|
||||
int packetQueuePopIn(packetqueue_t *queue, packet_t *packet) {
|
||||
assertNotNull(queue, "Packet queue is NULL");
|
||||
assertNotNull(packet, "Packet is NULL");
|
||||
|
||||
if(queue->packetsInCount == 0) return 0;
|
||||
|
||||
*packet = queue->packetsIn[0];
|
||||
for(uint32_t i = 1; i < queue->packetsInCount; i++) {
|
||||
queue->packetsIn[i - 1] = queue->packetsIn[i];
|
||||
}
|
||||
queue->packetsInCount--;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int packetQueuePopOut(packetqueue_t *queue, packet_t *packet) {
|
||||
assertNotNull(queue, "Packet queue is NULL");
|
||||
assertNotNull(packet, "Packet is NULL");
|
||||
|
||||
if(queue->packetsOutCount == 0) return 0;
|
||||
|
||||
*packet = queue->packetsOut[0];
|
||||
for(uint32_t i = 1; i < queue->packetsOutCount; i++) {
|
||||
queue->packetsOut[i - 1] = queue->packetsOut[i];
|
||||
}
|
||||
queue->packetsOutCount--;
|
||||
return 1;
|
||||
}
|
@ -15,14 +15,6 @@ typedef struct {
|
||||
uint32_t packetsInCount;
|
||||
packet_t packetsOut[PACKET_QUEUE_MAX_SIZE];
|
||||
uint32_t packetsOutCount;
|
||||
|
||||
// Mutex for thread safety
|
||||
pthread_mutex_t mutex;
|
||||
// Condition variables for signaling
|
||||
pthread_cond_t condIn;
|
||||
pthread_cond_t condOut;
|
||||
// Thread ID of the thread that owns the queue
|
||||
|
||||
} packetqueue_t;
|
||||
|
||||
/**
|
||||
@ -41,9 +33,27 @@ void packetQueueInit(packetqueue_t *queue);
|
||||
void packetQueuePushIn(packetqueue_t *queue, const packet_t *packet);
|
||||
|
||||
/**
|
||||
* Pushes a packet from the outbound packet queue.
|
||||
* Pushes a packet into the outbound packet queue.
|
||||
*
|
||||
* @param queue Pointer to the packet queue structure.
|
||||
* @param packet Pointer to the packet to be pushed.
|
||||
*/
|
||||
void packetQueuePushOut(packetqueue_t *queue, const packet_t *packet);
|
||||
void packetQueuePushOut(packetqueue_t *queue, const packet_t *packet);
|
||||
|
||||
/**
|
||||
* Pops a packet from the inbound packet queue.
|
||||
*
|
||||
* @param queue Pointer to the packet queue structure.
|
||||
* @param packet Pointer to the packet to store the popped packet.
|
||||
* @return 1 if a packet was popped, 0 otherwise.
|
||||
*/
|
||||
int packetQueuePopIn(packetqueue_t *queue, packet_t *packet);
|
||||
|
||||
/**
|
||||
* Pops a packet from the outbound packet queue.
|
||||
*
|
||||
* @param queue Pointer to the packet queue structure.
|
||||
* @param packet Pointer to the packet to store the popped packet.
|
||||
* @return 1 if a packet was popped, 0 otherwise.
|
||||
*/
|
||||
int packetQueuePopOut(packetqueue_t *queue, packet_t *packet);
|
Reference in New Issue
Block a user