-
Notifications
You must be signed in to change notification settings - Fork 1
/
sock_mod_structs.h
200 lines (168 loc) · 8.31 KB
/
sock_mod_structs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
#ifndef _sock_mod_structs
#define _sock_mod_structs
#include <iostream.h>
#include "sockint.h"
enum Status {FREE, UNBOUND, BOUND, LISTENING, ACCEPT_PENDING,
CONNECT_PENDING, CONNECTED, READ_PENDING,
WRITE_PENDING};
struct SockRecord {
Connection connection;
Buffer bin;
// Buffer bout;
Status status;
int toApp;
int fromApp;
int blocking;
int forward_read_notification;
int forward_write_notification;
int forward_exception_notification;
SockRecord();
SockRecord(const SockRecord &rhs);
SockRecord(const Connection &c,
const Buffer &bi,
// const Buffer &bo,
const Status &s,
const int &ta,
const int &fa,
const int &b,
const int &frn,
const int &fwn,
const int &fen);
virtual ~SockRecord() {}
SockRecord & operator=(const SockRecord &rhs);
ostream & Print(ostream &rhs) const;
};
struct SockStatus {
SockRecord sockArray[NUM_SOCKS];
int FindFreeSock(); // Return the first free socket,
// or -1 if no socket is
// available.
void CloseSocket(unsigned sock) { // Close the specified socket.
sockArray[sock] = SockRecord(); }
int FindConnection(const Connection & c); // Find a socket which matches
// this connection, return
// its fd or -1 if no socket
// matches.
int FindPendingConnection(const Connection & c);
// Find a socket which matches
// this connection and is
// waiting to complete its
// connection. Return its fd
// or -1 if no socket matches.
Connection *GetConnection (unsigned sock) { // Get the connection for the
return (&sockArray[sock].connection); } // specified socket.
Buffer *GetBin (unsigned sock) { // Get the input buffer for the
return (&sockArray[sock].bin); } // specified socket.
//Buffer *GetBout (unsigned sock) { // Get the output buffer for
// return (&sockArray[sock].bout); } // the specified socket.
Status GetStatus (unsigned sock) { // Get the status of the
return (sockArray[sock].status); } // specified socket.
int SetStatus (unsigned sock, Status stat); // Set the status of the
// specified socket.
int GetFifoToApp (unsigned sock) { // Get the fd of the fifo to the
return (sockArray[sock].toApp); } // application layer for the
// specified socket.
int SetFifoToApp (unsigned sock, int fd); // Set the fd of the fifo to the
// application layer for the
// specified socket.
int GetFifoFromApp (unsigned sock) { // Get the fd of the fifo from
return (sockArray[sock].fromApp); } // the application layer for
// the specified socket.
int SetFifoFromApp (unsigned sock, int fd); // Set the fd of the fifo from
// the application layer for
// the specified socket.
int GetBlockingStatus (unsigned sock) { // Return 0 if the socket is
return (sockArray[sock].blocking); } // set non-blocking, 1 if it
// is set to block.
int SetBlockingStatus (unsigned sock, int b);// Set the blocking status for
// the specified socket.
int GetReadNotificationStatus (unsigned sock) {
return (sockArray[sock].forward_read_notification); }
// Returns 1 if we have been
// asked to notify the
// application layer the next
// time this socket is
// available for reading, 0
// otherwise.
int SetReadNotificationStatus (unsigned sock,// Set the read notification
int s); // status.
int GetWriteNotificationStatus (unsigned sock) {
return (sockArray[sock].forward_write_notification); }
// Returns 1 if we have been
// asked to notify the
// application layer the next
// time this socket is
// available for writing, 0
// otherwise.
int SetWriteNotificationStatus (unsigned sock, int s);
// Set the write notification
// status.
int GetExceptionNotificationStatus (unsigned sock) {
return (sockArray[sock].forward_exception_notification); }
// Returns 1 if we have been
// asked to notify the
// application layer the next
// time this socket has an
// exception, 0 otherwise.
int SetExceptionNotificationStatus (unsigned sock, int s);
// Set the exception
// notification status
SockStatus() {}
SockStatus(const SockStatus &rhs);
virtual ~SockStatus() {}
SockStatus & operator=(const SockStatus &rhs);
};
struct PortStatus {
IPAddress portArrayIndex[NUM_IP_INTERFACES];
unsigned portArray[NUM_IP_INTERFACES][NUM_PORTS];
int FindFreePort(IPAddress ip, // Return the port number of an
unsigned sockfd); // available port for the
// specified ip. Assign the
// port to the specified
// socket. Return -1 on
// failure.
int Socket(IPAddress ip, unsigned port); // Return the socket to which
// a given port on the
// specified ip is assigned.
// Returns 0 if the port is
// unassigned. Return -1 on
// failure
int AssignPort(IPAddress ip, unsigned port, // Assign the specified port to
unsigned sockfd); // the specified ip. Return
// -1 on failure.
PortStatus();
PortStatus(const PortStatus &rhs);
virtual ~PortStatus() {}
PortStatus & operator=(const PortStatus & rhs);
};
struct RequestRecord {
SockRequestResponse *srr;
int sock;
RequestRecord() {}
RequestRecord(SockRequestResponse *s, int fd);
RequestRecord(const RequestRecord &rhs);
~RequestRecord() {
delete srr; }
RequestRecord & operator=(const RequestRecord & rhs);
};
struct QueueElt {
void *data;
QueueElt *front;
QueueElt *back;
QueueElt() {}
QueueElt(const QueueElt &rhs);
QueueElt(char *d, QueueElt *f, QueueElt *b);
virtual ~QueueElt() {}
QueueElt & operator=(const QueueElt & rhs);
};
struct Queue {
QueueElt *front;
QueueElt *back;
void Insert(void * d);
void * Remove();
Queue();
Queue(const Queue &rhs);
Queue & operator=(const Queue & rhs);
~Queue();
};
#endif