tac0S
Template Affectional Command Operating System
|
Public Member Functions | |
PostOffice (NetworkAddress addr, double reliability, int nBoxes) | |
PostOffice::PostOffice Initialize a post office as a collection of mailboxes. Also initialize the network device, to allow post offices on different machines to deliver messages to one another. More... | |
~PostOffice () | |
PostOffice::~PostOffice De-allocate the post office data structures. | |
void | Send (PacketHeader pktHdr, MailHeader mailHdr, const char *data) |
PostOffice::Send Concatenate the MailHeader to the front of the data, and pass the result to the Network for delivery to the destination machine. More... | |
void | Receive (int box, PacketHeader *pktHdr, MailHeader *mailHdr, char *data) |
PostOffice::Send Retrieve a message from a specific box if one is available, otherwise wait for a message to arrive in the box. More... | |
void | PostalDelivery () |
PostOffice::PostalDelivery Wait for incoming messages, and put them in the right mailbox. More... | |
void | PacketSent () |
PostOffice::PacketSent Interrupt handler, called when the next packet can be put onto the network. More... | |
void | IncomingPacket () |
PostOffice::IncomingPacket Interrupt handler, called when a packet arrives from the network. More... | |
PostOffice::PostOffice | ( | NetworkAddress | addr, |
double | reliability, | ||
int | nBoxes | ||
) |
PostOffice::PostOffice Initialize a post office as a collection of mailboxes. Also initialize the network device, to allow post offices on different machines to deliver messages to one another.
We use a separate thread "the postal worker" to wait for messages to arrive, and deliver them to the correct mailbox. Note that delivering messages to the mailboxes can't be done directly by the interrupt handlers, because it requires a Lock.
addr | is this machine's network ID |
reliability | is the probability that a network packet will be delivered (e.g., reliability = 1 means the network never drops any packets; reliability = 0 means the network never delivers any packets) |
nBoxes | is the number of mail boxes in this Post Office |
void PostOffice::IncomingPacket | ( | ) |
PostOffice::IncomingPacket Interrupt handler, called when a packet arrives from the network.
Signal the PostalDelivery routine that it is time to get to work!
void PostOffice::PacketSent | ( | ) |
PostOffice::PacketSent Interrupt handler, called when the next packet can be put onto the network.
The name of this routine is a misnomer; if "reliability < 1", the packet could have been dropped by the network, so it won't get through.
void PostOffice::PostalDelivery | ( | ) |
PostOffice::PostalDelivery Wait for incoming messages, and put them in the right mailbox.
Incoming messages have had the PacketHeader stripped off, but the MailHeader is still tacked on the front of the data.
void PostOffice::Receive | ( | int | box, |
PacketHeader * | pktHdr, | ||
MailHeader * | mailHdr, | ||
char * | data | ||
) |
PostOffice::Send Retrieve a message from a specific box if one is available, otherwise wait for a message to arrive in the box.
Note that the MailHeader + data looks just like normal payload data to the Network.
box | – mailbox ID in which to look for message |
pktHdr | – address to put: source, destination machine ID's |
mailHdr | – address to put: source, destination mailbox ID's |
data | – address to put: payload message data |
void PostOffice::Send | ( | PacketHeader | pktHdr, |
MailHeader | mailHdr, | ||
const char * | data | ||
) |
PostOffice::Send Concatenate the MailHeader to the front of the data, and pass the result to the Network for delivery to the destination machine.
Note that the MailHeader + data looks just like normal payload data to the Network.
pktHdr | – source, destination machine ID's |
mailHdr | – source, destination mailbox ID's |
data | – payload message data |