Skip to content

Commit

Permalink
Make all server unlisten when then they finish.
Browse files Browse the repository at this point in the history
  • Loading branch information
larsbrinkhoff committed Jan 29, 2025
1 parent 67e2c1a commit afa6e48
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 4 deletions.
7 changes: 6 additions & 1 deletion apps/discard.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,14 @@ static void discard_server (int sock)
if (ncp_read (connection, buffer, &size) == -1)
fprintf (stderr, "NCP read error.\n");
if (size <= 0)
return;
break;
fprintf (stderr, "Read %d octets.\n", size);
}

if (ncp_unlisten (sock) == -1) {
fprintf (stderr, "NCP unlisten error.\n");
exit (1);
}
}

static void usage (const char *argv0)
Expand Down
10 changes: 8 additions & 2 deletions apps/echo.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,21 @@ static void echo_server (int sock)
if (ncp_read (connection, buffer, &size) == -1)
fprintf (stderr, "NCP read error.\n");
if (size <= 0)
return;
goto end;
for (ptr = buffer; size > 0; ptr += n, size -= n) {
n = size;
if (ncp_write (connection, ptr, &n) == -1)
fprintf (stderr, "NCP read error.\n");
if (n <= 0)
return;
goto end;
}
}

end:
if (ncp_unlisten (sock) == -1) {
fprintf (stderr, "NCP unlisten error.\n");
exit (1);
}
}

static void usage (const char *argv0)
Expand Down
10 changes: 9 additions & 1 deletion apps/finser.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <string.h>
#include "ncp.h"

#define SOCKET 0117

int main (int argc, char **argv)
{
char command[1000];
Expand All @@ -26,7 +28,7 @@ int main (int argc, char **argv)
}

size = 8;
if (ncp_listen (0117, &size, &host, &connection) == -1) {
if (ncp_listen (SOCKET, &size, &host, &connection) == -1) {
fprintf (stderr, "NCP listen error.\n");
exit (1);
}
Expand All @@ -52,4 +54,10 @@ int main (int argc, char **argv)
exit (1);
}

if (ncp_unlisten (SOCKET) == -1) {
fprintf (stderr, "NCP unlisten error.\n");
exit (1);
}

return 0;
}
5 changes: 5 additions & 0 deletions apps/gateway.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,11 @@ static void ncp_to_tcp (int sock, const char *host, const char *port)
fprintf (stderr, "NCP close error.\n");
exit (1);
}

if (ncp_unlisten (sock) == -1) {
fprintf (stderr, "NCP unlisten error.\n");
exit (1);
}
}

static void usage (const char *argv0)
Expand Down
5 changes: 5 additions & 0 deletions apps/telnet.c
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,11 @@ static void telnet_server (int host, int sock,
fprintf (stderr, "NCP close error.\n");
exit (1);
}

if (ncp_unlisten (sock) == -1) {
fprintf (stderr, "NCP unlisten error.\n");
exit (1);
}
}

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

0 comments on commit afa6e48

Please sign in to comment.