J. Blustein

Network Computing

[Crs | Ann | Mats | Res]

Kurose & Ross's Network Simulation Code

[Assignment | Documentation | Source Code ]

Documentation: [ Overview | KRnet | stucode | message_t | packet_t | queue_t ]

[Include contents frame]

queue_t

You can use this generic queue implementation if you need a FIFO buffer in your code. To use it, you should #include "queue.h" in your .c file.

All data (message_t units) passed to functions in client.c and server.c is first buffered in a message queue (aka FIFO buffer). When the code that implements the transport layer protocols (ABP or GBN) is ready for more input then data can be extracted from the queue one unit at a time and passed to the routines that need it. You don't need to touch the message queue between the upper layers or your protocol layers.

Creating/Destroying

queue_t new_queue(void)

The new_queue() function must be called to create a empty queue for you to manipulate. It returns a pointer to the queue structure, or NULL if the queue could not be created.

void destory_queue (queue_t q)

The destory_queue() function clears the queue and all items in the queue. After destory_queue() function is called all memory taken by the objects stored in the queue will also be released. So those objects should not be used again.

Initializing

void queue_init(queue_t q)

The queue_init() function initializes a queue. It will be called automatically in the new_queue() function. So you need not to call it while creating a new queue.

It should be used to reset an existing queue.

void queue_clear(queue_t q)

The queue_clear() function clears the queue, however none of the items in the queue are destroyed.

Interrogating

void* queue_top(queue_t q )

The queue_top() function returns the object stored in the head (first) item. The returned void* pointer should be cast to a proper object type pointer for use.

int queue_size(queue_t q)

The queue_size() function returns the length of the queue.

int queue_empty(queue_t q)

The queue_empty() function returns 1 (true) for an empty queue, otherwise it returns 0 (false).

Manipulating

void queue_push(queue_t q, void * data)

The queue_push() function inserts a new item which contains the specified data object at the end of the queue q.

void queue_pop(queue_t q)

The queue_pop() function removes the head (first) item in the queue. The object stored in the head item is not released.

Documentation: [ Overview | KRnet | stucode | message_t | packet_t | queue_t ]


http://web.cs.dal.ca/~jamie/course/CS/3171/Materials/KR_1e/Code/Chapter3/doc/queue.shtml
Version:
Sunday, 27-Jul-2003 13:35:25 ADT
CS 3171 Prof.:
J. Blustein <jamie@cs.dal.ca>

This webpage uses valid XHTML 1.0

Based on
document at <URL:http://occawlonline.pearsoned.com/bookbind/pubbooks/kurose-ross1/chapter4/custom12/deluxe-content.html> (copied on 05 July 2002). That document is © 2000-2001 by Addison Wesley Longman A division of Pearson Education

[Include contents frame]