Main Page   Compound List   File List   Compound Members   File Members  

nettest.cc File Reference

#include "copyright.h"
#include "system.h"
#include "network.h"
#include "post.h"
#include "interrupt.h"

Go to the source code of this file.

Functions

void MailTest (int farAddr)


Function Documentation

void MailTest int    farAddr
 

Definition at line 34 of file nettest.cc.

References PacketHeader::from, MailHeader::from, MailHeader::length, MaxMailSize, MailHeader::to, and PacketHeader::to.

00035 {
00036     PacketHeader outPktHdr, inPktHdr;
00037     MailHeader outMailHdr, inMailHdr;
00038     char *data = "Hello there!";
00039     char *ack = "Got it!";
00040     char buffer[MaxMailSize];
00041 
00042     // construct packet, mail header for original message
00043     // To: destination machine, mailbox 0
00044     // From: our machine, reply to: mailbox 1
00045     outPktHdr.to = farAddr;             
00046     outMailHdr.to = 0;
00047     outMailHdr.from = 1;
00048     outMailHdr.length = strlen(data) + 1;
00049 
00050     // Send the first message
00051     postOffice->Send(outPktHdr, outMailHdr, data); 
00052 
00053     // Wait for the first message from the other machine
00054     postOffice->Receive(0, &inPktHdr, &inMailHdr, buffer);
00055     printf("Got \"%s\" from %d, box %d\n",buffer,inPktHdr.from,inMailHdr.from);
00056     fflush(stdout);
00057 
00058     // Send acknowledgement to the other machine (using "reply to" mailbox
00059     // in the message that just arrived
00060     outPktHdr.to = inPktHdr.from;
00061     outMailHdr.to = inMailHdr.from;
00062     outMailHdr.length = strlen(ack) + 1;
00063     postOffice->Send(outPktHdr, outMailHdr, ack); 
00064 
00065     // Wait for the ack from the other machine to the first message we sent.
00066     postOffice->Receive(1, &inPktHdr, &inMailHdr, buffer);
00067     printf("Got \"%s\" from %d, box %d\n",buffer,inPktHdr.from,inMailHdr.from);
00068     fflush(stdout);
00069 
00070     // Then we're done!
00071     interrupt->Halt();
00072 }


Generated on Mon Feb 10 09:54:50 2003 for nachos by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002
The University of Southern California does not screen or control the content on this website and thus does not guarantee the accuracy, integrity, or quality of such content. All content on this website is provided by and is the sole responsibility of the person from which such content originated, and such content does not necessarily reflect the opinions of the University administration or the Board of Trustees