nserver

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | LICENSE

commit 17eadd99e175386fe2f9a77825f3964855543366
parent 68474b1bed5657b4d8fab417d06abd47de70767d
Author: rsiddharth <s@ricketyspace.net>
Date:   Mon, 16 Sep 2019 20:37:23 -0400

nserver/bin/statserve.c: Use echoserve.

* nserver/bin/statserve.c (echo, serve): Remove function.
(main): Use echoserve from necho.h for echoing back to client.

Diffstat:
nserver/bin/statserve.c | 52++--------------------------------------------------
1 file changed, 2 insertions(+), 50 deletions(-)

diff --git a/nserver/bin/statserve.c b/nserver/bin/statserve.c @@ -1,56 +1,8 @@ -#include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netdb.h> - -#include <dbg.h> +#include <necho.h> #include <nsocket.h> #define BACKLOG 10 -int echo(int sock, char *buf, int len) -{ - int bytes = 0; - - bytes = send(sock, buf, len, 0); - check(bytes >= 0, "statserv: send failed"); - - return bytes; - error: - return -1; -} - -void serve(int sock) -{ - int rc = 0; - int buf_len = 1000; - char buf[buf_len]; - ssize_t bytes; - - do { - bytes = recv(sock, buf, buf_len, 0); - check(bytes >= 0, "statserv: recv failed"); - - if (bytes < 1) { - break; - } - - rc = echo(sock, buf, bytes); - check(rc != -1, "statserv: echo failed"); - } while(1); - - rc = close(sock); - check(rc == 0, "statserv: close failed"); - - exit(0); - error: - rc = close(sock); - check(rc == 0, "statserv: close failed"); - exit(1); -} - int main(void) { int rc = 0; @@ -73,7 +25,7 @@ int main(void) check(pidc != -1, "statserve: fork failed"); if (pidc == 0) { - serve(sockfd_c); + echoserve(sockfd_c); } rc = close(sockfd_c);