tac0S
Template Affectional Command Operating System
Main Page
Classes
Files
File List
File Members
code
network
post.h
Go to the documentation of this file.
1
28
#include "copyright.h"
29
30
#ifndef POST_H
31
#define POST_H
32
33
#include "
network.h
"
34
#include "
synchlist.h
"
35
38
typedef
int
MailBoxAddress
;
39
43
44
class
MailHeader
{
45
public
:
46
MailBoxAddress
to;
// Destination mail box
47
MailBoxAddress
from;
// Mail box to reply to
48
unsigned
length;
// Bytes of message data (excluding the
49
// mail header)
50
};
51
52
// Maximum "payload" -- real data -- that can included in a single message
53
// Excluding the MailHeader and the PacketHeader
54
55
#define MaxMailSize (MaxPacketSize - sizeof(MailHeader))
56
57
58
// The following class defines the format of an incoming/outgoing
59
// "Mail" message. The message format is layered:
60
// network header (PacketHeader)
61
// post office header (MailHeader)
62
// data
63
64
class
Mail
{
65
public
:
66
Mail
(
PacketHeader
pktH,
MailHeader
mailH,
char
*msgData);
67
// Initialize a mail message by
68
// concatenating the headers to the data
69
70
PacketHeader
pktHdr;
// Header appended by Network
71
MailHeader
mailHdr;
// Header appended by PostOffice
72
char
data
[MaxMailSize];
// Payload -- message data
73
};
74
75
// The following class defines a single mailbox, or temporary storage
76
// for messages. Incoming messages are put by the PostOffice into the
77
// appropriate mailbox, and these messages can then be retrieved by
78
// threads on this machine.
79
80
class
MailBox
{
81
public
:
82
MailBox
();
// Allocate and initialize mail box
83
~
MailBox
();
// De-allocate mail box
84
85
void
Put(
PacketHeader
pktHdr,
MailHeader
mailHdr,
char
*
data
);
86
// Atomically put a message into the mailbox
87
void
Get(
PacketHeader
*pktHdr,
MailHeader
*mailHdr,
char
*data);
88
// Atomically get a message out of the
89
// mailbox (and wait if there is no message
90
// to get!)
91
private
:
92
SynchList
*messages;
// A mailbox is just a list of arrived messages
93
};
94
95
// The following class defines a "Post Office", or a collection of
96
// mailboxes. The Post Office is a synchronization object that provides
97
// two main operations: Send -- send a message to a mailbox on a remote
98
// machine, and Receive -- wait until a message is in the mailbox,
99
// then remove and return it.
100
//
101
// Incoming messages are put by the PostOffice into the
102
// appropriate mailbox, waking up any threads waiting on Receive.
103
104
class
PostOffice
{
105
public
:
106
PostOffice
(
NetworkAddress
addr,
double
reliability,
int
nBoxes);
107
// Allocate and initialize Post Office
108
// "reliability" is how many packets
109
// get dropped by the underlying network
110
~
PostOffice
();
// De-allocate Post Office data
111
112
void
Send(
PacketHeader
pktHdr,
MailHeader
mailHdr,
const
char
*
data
);
113
// Send a message to a mailbox on a remote
114
// machine. The fromBox in the MailHeader is
115
// the return box for ack's.
116
117
void
Receive(
int
box,
PacketHeader
*pktHdr,
118
MailHeader
*mailHdr,
char
*data);
119
// Retrieve a message from "box". Wait if
120
// there is no message in the box.
121
122
void
PostalDelivery();
// Wait for incoming messages,
123
// and then put them in the correct mailbox
124
125
void
PacketSent();
// Interrupt handler, called when outgoing
126
// packet has been put on network; next
127
// packet can now be sent
128
void
IncomingPacket();
// Interrupt handler, called when incoming
129
// packet has arrived and can be pulled
130
// off of network (i.e., time to call
131
// PostalDelivery)
132
133
private
:
134
Network
*network;
// Physical network connection
135
NetworkAddress
netAddr;
// Network address of this machine
136
MailBox
*boxes;
// Table of mail boxes to hold incoming mail
137
int
numBoxes;
// Number of mail boxes
138
Semaphore
*messageAvailable;
// V'ed when message has arrived from network
139
Semaphore
*messageSent;
// V'ed when next message can be sent to network
140
Lock
*sendLock;
// Only one outgoing message at a time
141
};
142
143
#endif
NetworkAddress
int NetworkAddress
Network address – uniquely identifies a machine. This machine's ID is given on the command line...
Definition:
network.h:26
MailHeader
The following class defines part of the message header. This is prepended to the message by the PostO...
Definition:
post.h:44
PostOffice
Definition:
post.h:104
MailBoxAddress
int MailBoxAddress
Mailbox address – uniquely identifies a mailbox on a given machine. A mailbox is just a place for te...
Definition:
post.h:38
PacketHeader
The following class defines the network packet header. The packet header is prepended to the data pay...
Definition:
network.h:34
network.h
structures to emulate a physical network connection.
Semaphore
The following class defines a "semaphore" whose value is a non-negative integer. The semaphore has on...
Definition:
synch.h:42
synchlist.h
Data structures for synchronized access to a list.
MailBox
Definition:
post.h:80
SynchList
The following class defines a "synchronized list" – a list for which: these constraints hold: ...
Definition:
synchlist.h:27
Lock
Definition:
synch.h:73
Network
Definition:
network.h:58
data
Definition:
out.c:36
Mail
Definition:
post.h:64
Generated by
1.8.11