#include <post.h>
Public Methods | |
| PostOffice (NetworkAddress addr, double reliability, int nBoxes) | |
| ~PostOffice () | |
| void | Send (PacketHeader pktHdr, MailHeader mailHdr, char *data) |
| void | Receive (int box, PacketHeader *pktHdr, MailHeader *mailHdr, char *data) |
| void | PostalDelivery () |
| void | PacketSent () |
| void | IncomingPacket () |
Private Attributes | |
| Network * | network |
| NetworkAddress | netAddr |
| MailBox * | boxes |
| int | numBoxes |
| Semaphore * | messageAvailable |
| Semaphore * | messageSent |
| Lock * | sendLock |
|
||||||||||||||||
|
Definition at line 178 of file post.cc. References boxes, Thread::Fork, messageAvailable, messageSent, netAddr, network, NetworkAddress, numBoxes, PostalHelper, ReadAvail, sendLock, and WriteDone.
00179 {
00180 // First, initialize the synchronization with the interrupt handlers
00181 messageAvailable = new Semaphore("message available", 0);
00182 messageSent = new Semaphore("message sent", 0);
00183 sendLock = new Lock("message send lock");
00184
00185 // Second, initialize the mailboxes
00186 netAddr = addr;
00187 numBoxes = nBoxes;
00188 boxes = new MailBox[nBoxes];
00189
00190 // Third, initialize the network; tell it which interrupt handlers to call
00191 network = new Network(addr, reliability, ReadAvail, WriteDone, (int) this);
00192
00193
00194 // Finally, create a thread whose sole job is to wait for incoming messages,
00195 // and put them in the right mailbox.
00196 Thread *t = new Thread("postal worker");
00197
00198 t->Fork(PostalHelper, (int) this);
00199 }
|
|
|
Definition at line 206 of file post.cc. References boxes, messageAvailable, messageSent, network, and sendLock.
00207 {
00208 delete network;
00209 delete [] boxes;
00210 delete messageAvailable;
00211 delete messageSent;
00212 delete sendLock;
00213 }
|
|
|
Definition at line 328 of file post.cc. References messageAvailable, and Semaphore::V. Referenced by ReadAvail.
00329 {
00330 messageAvailable->V();
00331 }
|
|
|
Definition at line 344 of file post.cc. References messageSent, and Semaphore::V. Referenced by WriteDone.
00345 {
00346 messageSent->V();
00347 }
|
|
|
Definition at line 224 of file post.cc. References ASSERT, boxes, DebugIsEnabled, MailHeader::length, MaxMailSize, MaxPacketSize, messageAvailable, network, numBoxes, Semaphore::P, PrintHeader, Network::Receive, and MailHeader::to. Referenced by PostalHelper.
00225 {
00226 PacketHeader pktHdr;
00227 MailHeader mailHdr;
00228 char *buffer = new char[MaxPacketSize];
00229
00230 for (;;) {
00231 // first, wait for a message
00232 messageAvailable->P();
00233 pktHdr = network->Receive(buffer);
00234
00235 mailHdr = *(MailHeader *)buffer;
00236 if (DebugIsEnabled('n')) {
00237 printf("Putting mail into mailbox: ");
00238 PrintHeader(pktHdr, mailHdr);
00239 }
00240
00241 // check that arriving message is legal!
00242 ASSERT(0 <= mailHdr.to && mailHdr.to < numBoxes);
00243 ASSERT(mailHdr.length <= MaxMailSize);
00244
00245 // put into mailbox
00246 boxes[mailHdr.to].Put(pktHdr, mailHdr, buffer + sizeof(MailHeader));
00247 }
00248 }
|
|
||||||||||||||||||||
|
Definition at line 311 of file post.cc. References ASSERT, boxes, MailBox::Get, MailHeader::length, MaxMailSize, and numBoxes.
|
|
||||||||||||||||
|
Definition at line 264 of file post.cc. References Lock::Acquire, ASSERT, bcopy, DebugIsEnabled, PacketHeader::from, PacketHeader::length, MailHeader::length, MaxMailSize, MaxPacketSize, messageSent, netAddr, network, numBoxes, Semaphore::P, PrintHeader, Lock::Release, Network::Send, sendLock, and MailHeader::to.
00265 {
00266 char* buffer = new char[MaxPacketSize]; // space to hold concatenated
00267 // mailHdr + data
00268
00269 if (DebugIsEnabled('n')) {
00270 printf("Post send: ");
00271 PrintHeader(pktHdr, mailHdr);
00272 }
00273 ASSERT(mailHdr.length <= MaxMailSize);
00274 ASSERT(0 <= mailHdr.to && mailHdr.to < numBoxes);
00275
00276 // fill in pktHdr, for the Network layer
00277 pktHdr.from = netAddr;
00278 pktHdr.length = mailHdr.length + sizeof(MailHeader);
00279
00280 // concatenate MailHeader and data
00281 bcopy((char *) &mailHdr, buffer, sizeof(MailHeader));
00282 bcopy(data, buffer + sizeof(MailHeader), mailHdr.length);
00283
00284 sendLock->Acquire(); // only one message can be sent
00285 // to the network at any one time
00286 network->Send(pktHdr, buffer);
00287 messageSent->P(); // wait for interrupt to tell us
00288 // ok to send the next message
00289 sendLock->Release();
00290
00291 delete [] buffer; // we've sent the message, so
00292 // we can delete our buffer
00293 }
|
|
|
Definition at line 134 of file post.h. Referenced by PostalDelivery, PostOffice, Receive, and ~PostOffice. |
|
|
Definition at line 136 of file post.h. Referenced by IncomingPacket, PostalDelivery, PostOffice, and ~PostOffice. |
|
|
Definition at line 137 of file post.h. Referenced by PacketSent, PostOffice, Send, and ~PostOffice. |
|
|
Definition at line 133 of file post.h. Referenced by PostOffice, and Send. |
|
|
Definition at line 132 of file post.h. Referenced by PostalDelivery, PostOffice, Send, and ~PostOffice. |
|
|
Definition at line 135 of file post.h. Referenced by PostalDelivery, PostOffice, Receive, and Send. |
|
|
Definition at line 138 of file post.h. Referenced by PostOffice, Send, and ~PostOffice. |
1.2.14 written by Dimitri van Heesch,
© 1997-2002