Next: send And recieve
Creating Channels
New communication channels are created with the get_channel() function as follows:
get_channel (int number)
{
struct channel *ptr;
/* 1 *1
for (ptr = channel_list; ptr; ptr = ptr->link)
if (ptr->number==number)
return( (int)ptr);
/* 2 */
if (!(ptr = (struct channel *)malloc(sizeof(struct channel))))
return 0;
/* 3 */
ptr->number = number;
ptr->message_list = 0;
ptr->message_tail = 0;
ptr->sr_flag = 0;
ptr->link = channel~list;
channel_list = ptr;
return((int)ptr);
}
Remember that the get_channel() function returns a channel descriptor given a channel number as a parameter. If the channel does not already exist, then it will be created. The numbered comment are:
- Starting at channel_list, search down the linked list of existing channels looking to see if the specified channel number already exists. If the specified number is found in the list then the address of the associated struct channel is cast to an int value and returned as the channel descriptor.
- If the channel number does not already exist, then a new struct channel is allocated, or a zero is returned on error.
- After the new struct channel has been successfully created its fields are initialized and the structure is added to the head of the channel list. Finally, the address of the new structure is cast to mt and returned as the channel descriptor.
Next: send And recieve