Beispiel #1
0
gboolean asyncpriorityqueue_isEmpty(AsyncPriorityQueue *q) {
	g_assert(q);
	g_mutex_lock(&(q->lock));
	gboolean returnVal = priorityqueue_isEmpty(q->pq);
	g_mutex_unlock(&(q->lock));
	return returnVal;
}
/* first-in-first-out queuing discipline ($ man tc)*/
static Packet* _networkinterface_selectFirstInFirstOut(NetworkInterface* interface, gint* socketHandle) {
	/* use packet priority field to select based on application ordering.
	 * this is really a simplification of prioritizing on timestamps. */
	Packet* packet = NULL;

	while(!packet && !priorityqueue_isEmpty(interface->fifoQueue)) {
		/* do fifo to get the next packet from the next socket */
		Socket* socket = priorityqueue_pop(interface->fifoQueue);
		packet = socket_pullOutPacket(socket);
		*socketHandle = *descriptor_getHandleReference((Descriptor*)socket);

		if(socket_peekNextPacket(socket)) {
			/* socket has more packets, and is still reffed from before */
			priorityqueue_push(interface->fifoQueue, socket);
		} else {
			/* socket has no more packets, unref it from the sendable queue */
			descriptor_unref((Descriptor*) socket);
		}
	}

	return packet;
}