Skip to content

Commit 153a3e5

Browse files
committed
Make all server unlisten when then they finish.
1 parent 63a7127 commit 153a3e5

File tree

5 files changed

+36
-7
lines changed

5 files changed

+36
-7
lines changed

apps/discard.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,17 @@ static void discard_server (int sock)
2525
if (ncp_read (connection, buffer, &size) == -1)
2626
fprintf (stderr, "NCP read error.\n");
2727
if (size <= 0)
28-
return;
28+
break;
2929
fprintf (stderr, "Read %d octets.\n", size);
3030
}
31+
32+
if (size == 0 && ncp_close (connection) == -1)
33+
fprintf (stderr, "NCP close error.\n");
34+
35+
if (ncp_unlisten (sock) == -1) {
36+
fprintf (stderr, "NCP unlisten error.\n");
37+
exit (1);
38+
}
3139
}
3240

3341
static void usage (const char *argv0)

apps/echo.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,24 @@ static void echo_server (int sock)
7979
if (ncp_read (connection, buffer, &size) == -1)
8080
fprintf (stderr, "NCP read error.\n");
8181
if (size <= 0)
82-
return;
82+
goto end;
8383
for (ptr = buffer; size > 0; ptr += n, size -= n) {
8484
n = size;
8585
if (ncp_write (connection, ptr, &n) == -1)
8686
fprintf (stderr, "NCP read error.\n");
8787
if (n <= 0)
88-
return;
88+
goto end;
8989
}
9090
}
91+
92+
end:
93+
if (n == 0 && ncp_close (connection) == -1)
94+
fprintf (stderr, "NCP close error.\n");
95+
96+
if (ncp_unlisten (sock) == -1) {
97+
fprintf (stderr, "NCP unlisten error.\n");
98+
exit (1);
99+
}
91100
}
92101

93102
static void usage (const char *argv0)

apps/finser.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <string.h>
66
#include "ncp.h"
77

8+
#define SOCKET 0117
9+
810
int main (int argc, char **argv)
911
{
1012
char command[1000];
@@ -26,7 +28,7 @@ int main (int argc, char **argv)
2628
}
2729

2830
size = 8;
29-
if (ncp_listen (0117, &size, &host, &connection) == -1) {
31+
if (ncp_listen (SOCKET, &size, &host, &connection) == -1) {
3032
fprintf (stderr, "NCP listen error.\n");
3133
exit (1);
3234
}
@@ -47,9 +49,13 @@ int main (int argc, char **argv)
4749
exit (1);
4850
}
4951

50-
if (ncp_close (connection) == -1) {
52+
if (ncp_close (connection) == -1)
5153
fprintf (stderr, "NCP close error.\n");
54+
55+
if (ncp_unlisten (SOCKET) == -1) {
56+
fprintf (stderr, "NCP unlisten error.\n");
5257
exit (1);
5358
}
5459

60+
return 0;
5561
}

apps/gateway.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,8 +183,11 @@ static void ncp_to_tcp (int sock, const char *host, const char *port)
183183
fd = inet_connect (host, port);
184184
transport (fd, connection);
185185

186-
if (ncp_close (connection) == -1) {
186+
if (ncp_close (connection) == -1)
187187
fprintf (stderr, "NCP close error.\n");
188+
189+
if (ncp_unlisten (sock) == -1) {
190+
fprintf (stderr, "NCP unlisten error.\n");
188191
exit (1);
189192
}
190193
}

apps/telnet.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,11 @@ static void telnet_server (int host, int sock,
456456
kill (reader_pid, SIGTERM);
457457
kill (writer_pid, SIGTERM);
458458

459-
if (ncp_close (connection) == -1) {
459+
if (ncp_close (connection) == -1)
460460
fprintf (stderr, "NCP close error.\n");
461+
462+
if (ncp_unlisten (sock) == -1) {
463+
fprintf (stderr, "NCP unlisten error.\n");
461464
exit (1);
462465
}
463466
}

0 commit comments

Comments
 (0)