From 10ee4cff7e498a7c31a2cbfc1916f7d795c7aca2 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 24 May 2022 22:43:15 +0200 Subject: Remove external status variable from connection code. Use return code to signal dead connection --- vchat-client.c | 4 ++-- vchat-connection.c | 13 ++++--------- vchat-connection.h | 2 +- 3 files changed, 7 insertions(+), 12 deletions(-) diff --git a/vchat-client.c b/vchat-client.c index c094376..d1afaa2 100755 --- a/vchat-client.c +++ b/vchat-client.c @@ -397,8 +397,8 @@ void eventloop(void) { userinput(); /* something to read from server? */ - if (poll_result & 2) - vc_receive(); + if ((poll_result & 2) && vc_receive()) + status = 0; break; } } diff --git a/vchat-connection.c b/vchat-connection.c index 9770115..7c204fd 100644 --- a/vchat-connection.c +++ b/vchat-connection.c @@ -35,10 +35,6 @@ static int serverfd = -1; unsigned int want_tcp_keepalive = 0; -/* TODO: NEEDS TO GO. status-variable from vchat-client.c - * eventloop is done as long as this is true */ -extern int status; - /* Generic tcp connector, blocking */ static int connect_tcp_socket(const char *server, const char *port) { struct addrinfo hints, *res, *res0; @@ -215,15 +211,14 @@ void vc_receive(void) { /* Our tls functions may require retries with handshakes etc, this is * signalled by -2 */ if (bytes == -2) - return; + return 0; /* Error on the socket read? raise error message, bail out */ if (bytes == -1) { snprintf(tmpstr, TMPSTRSIZE, "Receive fails, %s.", strerror(errno)); snprintf(errstr, ERRSTRSIZE, "Receive fails, %s.\n", strerror(errno)); writecf(FS_ERR, tmpstr); - status = 0; - return; + return -1; } /* end of file from server? */ @@ -231,8 +226,7 @@ void vc_receive(void) { /* inform user, bail out */ writecf(FS_SERV, "* EOF from server."); snprintf(errstr, ERRSTRSIZE, "* EOF from server.\n"); - status = 0; - return; + return -1; } buf_fill += bytes; @@ -257,4 +251,5 @@ void vc_receive(void) { buf_fill -= 1 + endmsg - buf; memmove(buf, endmsg + 1, buf_fill); } + return 0; } diff --git a/vchat-connection.h b/vchat-connection.h index 9b3ccaa..2889c82 100644 --- a/vchat-connection.h +++ b/vchat-connection.h @@ -4,6 +4,6 @@ int vc_connect(const char *host, const char *port); void vc_sendmessage(const char *message); -void vc_receive(); +int vc_receive(); int vc_poll(); void vc_disconnect(); -- cgit v1.2.3