Skip to content

Commit afa6e48

Browse files
committed
Make all server unlisten when then they finish.
1 parent 67e2c1a commit afa6e48

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

apps/discard.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,14 @@ 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 (ncp_unlisten (sock) == -1) {
33+
fprintf (stderr, "NCP unlisten error.\n");
34+
exit (1);
35+
}
3136
}
3237

3338
static void usage (const char *argv0)

apps/echo.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,21 @@ 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 (ncp_unlisten (sock) == -1) {
94+
fprintf (stderr, "NCP unlisten error.\n");
95+
exit (1);
96+
}
9197
}
9298

9399
static void usage (const char *argv0)

apps/finser.c

Lines changed: 9 additions & 1 deletion
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
}
@@ -52,4 +54,10 @@ int main (int argc, char **argv)
5254
exit (1);
5355
}
5456

57+
if (ncp_unlisten (SOCKET) == -1) {
58+
fprintf (stderr, "NCP unlisten error.\n");
59+
exit (1);
60+
}
61+
62+
return 0;
5563
}

apps/gateway.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,11 @@ static void ncp_to_tcp (int sock, const char *host, const char *port)
187187
fprintf (stderr, "NCP close error.\n");
188188
exit (1);
189189
}
190+
191+
if (ncp_unlisten (sock) == -1) {
192+
fprintf (stderr, "NCP unlisten error.\n");
193+
exit (1);
194+
}
190195
}
191196

192197
static void usage (const char *argv0)

apps/telnet.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,11 @@ static void telnet_server (int host, int sock,
460460
fprintf (stderr, "NCP close error.\n");
461461
exit (1);
462462
}
463+
464+
if (ncp_unlisten (sock) == -1) {
465+
fprintf (stderr, "NCP unlisten error.\n");
466+
exit (1);
467+
}
463468
}
464469

465470
static void usage (const char *argv0, int code)

0 commit comments

Comments
 (0)