Skip to content

Commit 4767e3a

Browse files
committed
Make API support connection byte size.
1 parent 7cc333f commit 4767e3a

File tree

11 files changed

+159
-48
lines changed

11 files changed

+159
-48
lines changed

apps/discard.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ static void discard_server (int sock)
1313
int host, connection, size;
1414
char buffer[1000];
1515

16-
if (ncp_listen (sock, &host, &connection) == -1) {
16+
size = 8;
17+
if (ncp_listen (sock, &size, &host, &connection) == -1) {
1718
fprintf (stderr, "NCP listen error.\n");
1819
exit (1);
1920
}

apps/echo.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,12 @@
1010

1111
static void echo_client (int host, int sock)
1212
{
13-
int connection, n;
13+
int connection, n, byte_size;
1414
char buffer[1000], *ptr;
1515
ssize_t size;
1616

17-
switch (ncp_open (host, sock, &connection)) {
17+
size = 8;
18+
switch (ncp_open (host, sock, &byte_size, &connection)) {
1819
case 0:
1920
break;
2021
case -1:
@@ -66,7 +67,8 @@ static void echo_server (int sock)
6667
int host, connection, size, n;
6768
char buffer[1000], *ptr;
6869

69-
if (ncp_listen (sock, &host, &connection) == -1) {
70+
size = 8;
71+
if (ncp_listen (sock, &size, &host, &connection) == -1) {
7072
fprintf (stderr, "NCP listen error.\n");
7173
exit (1);
7274
}

apps/finger.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ int main (int argc, char **argv)
2727

2828
printf ("Finger host %03o.\n", host);
2929

30-
switch (ncp_open (host, 0117, &connection)) {
30+
size = 8;
31+
switch (ncp_open (host, 0117, &size, &connection)) {
3132
case 0:
3233
break;
3334
case -1:

apps/finser.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ int main (int argc, char **argv)
2323
exit (1);
2424
}
2525

26-
if (ncp_listen (0117, &host, &connection) == -1) {
26+
size = 8;
27+
if (ncp_listen (0117, &size, &host, &connection) == -1) {
2728
fprintf (stderr, "NCP listen error.\n");
2829
exit (1);
2930
}

apps/gateway.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static void tcp_to_ncp (const char *port, const char *host, const char *sock)
138138
{
139139
char *foreign_host;
140140
int connection, foreign_port;
141-
int fd, s;
141+
int fd, s, size;
142142

143143
s = inet_server (port);
144144
fd = inet_accept (s, &foreign_host, &foreign_port);
@@ -148,7 +148,8 @@ static void tcp_to_ncp (const char *port, const char *host, const char *sock)
148148
int ncp_host = atoi (host);
149149
int ncp_sock = atoi (sock);
150150

151-
switch (ncp_open (ncp_host, ncp_sock, &connection)) {
151+
size = 8;
152+
switch (ncp_open (ncp_host, ncp_sock, &size, &connection)) {
152153
case 0:
153154
break;
154155
case -1:
@@ -170,9 +171,10 @@ static void tcp_to_ncp (const char *port, const char *host, const char *sock)
170171

171172
static void ncp_to_tcp (int sock, const char *host, const char *port)
172173
{
173-
int fd, ncp_host, connection;
174+
int fd, ncp_host, connection, size;
174175

175-
if (ncp_listen (sock, &ncp_host, &connection) == -1) {
176+
size = 8;
177+
if (ncp_listen (sock, &size, &ncp_host, &connection) == -1) {
176178
fprintf (stderr, "NCP listen error.\n");
177179
exit (1);
178180
}

apps/telnet.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -313,13 +313,14 @@ static void telnet_client (int host, int sock,
313313
void (*process) (unsigned char, int, int),
314314
const unsigned char *options)
315315
{
316-
int connection;
316+
int connection, byte_size;
317317
int reader_fd, writer_fd;
318318
size_t size;
319319

320320
printf ("TELNET to host %03o.\n", host);
321321

322-
switch (ncp_open (host, sock, &connection)) {
322+
byte_size = 8;
323+
switch (ncp_open (host, sock, &byte_size, &connection)) {
323324
case 0:
324325
break;
325326
case -1:
@@ -392,7 +393,9 @@ static void telnet_server (int sock, void (*process) (unsigned char, int, int),
392393
char *banner;
393394

394395
fprintf (stderr, "Listening to socket %d.\n", sock);
395-
if (ncp_listen (sock, &host, &connection) == -1) {
396+
397+
size = 8;
398+
if (ncp_listen (sock, &size, &host, &connection) == -1) {
396399
fprintf (stderr, "NCP listen error.\n");
397400
exit (1);
398401
}

src/ICP

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
2+
3+
Server
4+
5+
1. incoming RTS1
6+
2. reply STR1
7+
3. wait for ALL
8+
4. data S
9+
5. CLS
10+
6. be ready to accept new STR2+RTS2
11+
7. send new STR3+RTS3
12+
8. wait for reply STR2+RTS2
13+
14+
After RTS1, send STR1.
15+
After STR1, expect ALL.
16+
After ALL, send data S, send CLS.
17+
After send data S, expect CLS, RTS2, STR2.
18+
19+
Client
20+
21+
1. send RTS1
22+
2. wait for STR1
23+
3. be ready accept new STR2+RTS2
24+
4. send ALL
25+
5. wait for data
26+
6. send new STR3+RTS3
27+
7. wait for reply STR2+RTS2
28+
29+
Send RTS1, expect STR1, STR2, RTS2.
30+
After STR1, send ALL, expect data S, STR2, RTS2.
31+
After data S, send CLS, send STR2, send RTS2, expect STR2, expect RTS2.
32+
33+
RTS->STR->ALL->data->CLS
34+
35+
RTS->STR2+STR2
36+
37+
Server
38+
39+
Incoming RTS:
40+
- ICP initial (first message)
41+
- or ICP primary
42+
Incoming STR:
43+
- ICP primary
44+
Incoming ALL:
45+
- ICP
46+
- or not
47+
Incoming CLS:
48+
- ICP
49+
- remote closing
50+
- reply to CLS
51+
52+
Client
53+
54+
Incoming STR:
55+
- ICP initial (reply to first RTS)
56+
- or ICP primary
57+
Incoming RTS:
58+
- ICP primary
59+
Incoming data:
60+
- ICP
61+
- or not
62+
Incoming CLS:
63+
- ICP
64+
- remote closing
65+
- reply to CLS
66+
67+
Both
68+
69+
Incoming RTS:
70+
- If listening to L, start ICP.
71+
- Else new connection.
72+
Incoming STR:
73+
- Confirm start ICP.
74+
- Else new connection.
75+
Incoming ALL:
76+
- Allocation for ICP.
77+
- Else allocation for regular data.
78+
Incoming data:
79+
- S for ICP.
80+
- Else regular data.
81+
Incoming CLS:
82+
- Close ICP link.
83+
- Remote closing link.
84+
- Confirm closing link.

src/libncp.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,33 +109,36 @@ static int u32 (uint8_t *data)
109109
return (data[0] << 24) | (data[1] << 16) | (data[2] << 8) | data[3];
110110
}
111111

112-
int ncp_open (int host, unsigned socket, int *connection)
112+
int ncp_open (int host, unsigned socket, int *size, int *connection)
113113
{
114114
type (WIRE_OPEN);
115115
add (host);
116116
add (socket >> 24);
117117
add (socket >> 16);
118118
add (socket >> 8);
119119
add (socket);
120+
add (*size);
120121
if (transact () == -1)
121122
return -1;
122123
if (message[1] != host)
123124
return -1;
124125
if (u32 (message + 2) != socket)
125126
return -1;
126-
if (message[7] == 255)
127+
if (message[8] == 255)
127128
return -2;
128129
*connection = message[6];
130+
*size = message[7];
129131
return 0;
130132
}
131133

132-
int ncp_listen (unsigned socket, int *host, int *connection)
134+
int ncp_listen (unsigned socket, int *size, int *host, int *connection)
133135
{
134136
type (WIRE_LISTEN);
135137
add (socket >> 24);
136138
add (socket >> 16);
137139
add (socket >> 8);
138140
add (socket);
141+
add (*size);
139142
if (transact () == -1)
140143
return -1;
141144
if (message[1] == 0)
@@ -144,6 +147,7 @@ int ncp_listen (unsigned socket, int *host, int *connection)
144147
return -1;
145148
*host = message[1];
146149
*connection = message[6];
150+
*size = message[7];
147151
return 0;
148152
}
149153

0 commit comments

Comments
 (0)