summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2022-05-24 22:43:15 +0200
committerDirk Engling <erdgeist@erdgeist.org>2022-05-24 22:43:15 +0200
commit10ee4cff7e498a7c31a2cbfc1916f7d795c7aca2 (patch)
treee4282fd66ad38ca6f0ea3929c89829dcbb6dca55
parentef780ee52da0845fa679c664e106d93d1142c9ef (diff)
Remove external status variable from connection code. Use return code to signal dead connection
-rwxr-xr-xvchat-client.c4
-rw-r--r--vchat-connection.c13
-rw-r--r--vchat-connection.h2
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) {
397 userinput(); 397 userinput();
398 398
399 /* something to read from server? */ 399 /* something to read from server? */
400 if (poll_result & 2) 400 if ((poll_result & 2) && vc_receive())
401 vc_receive(); 401 status = 0;
402 break; 402 break;
403 } 403 }
404} 404}
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 @@
35static int serverfd = -1; 35static int serverfd = -1;
36unsigned int want_tcp_keepalive = 0; 36unsigned int want_tcp_keepalive = 0;
37 37
38/* TODO: NEEDS TO GO. status-variable from vchat-client.c
39 * eventloop is done as long as this is true */
40extern int status;
41
42/* Generic tcp connector, blocking */ 38/* Generic tcp connector, blocking */
43static int connect_tcp_socket(const char *server, const char *port) { 39static int connect_tcp_socket(const char *server, const char *port) {
44 struct addrinfo hints, *res, *res0; 40 struct addrinfo hints, *res, *res0;
@@ -215,15 +211,14 @@ void vc_receive(void) {
215 /* Our tls functions may require retries with handshakes etc, this is 211 /* Our tls functions may require retries with handshakes etc, this is
216 * signalled by -2 */ 212 * signalled by -2 */
217 if (bytes == -2) 213 if (bytes == -2)
218 return; 214 return 0;
219 215
220 /* Error on the socket read? raise error message, bail out */ 216 /* Error on the socket read? raise error message, bail out */
221 if (bytes == -1) { 217 if (bytes == -1) {
222 snprintf(tmpstr, TMPSTRSIZE, "Receive fails, %s.", strerror(errno)); 218 snprintf(tmpstr, TMPSTRSIZE, "Receive fails, %s.", strerror(errno));
223 snprintf(errstr, ERRSTRSIZE, "Receive fails, %s.\n", strerror(errno)); 219 snprintf(errstr, ERRSTRSIZE, "Receive fails, %s.\n", strerror(errno));
224 writecf(FS_ERR, tmpstr); 220 writecf(FS_ERR, tmpstr);
225 status = 0; 221 return -1;
226 return;
227 } 222 }
228 223
229 /* end of file from server? */ 224 /* end of file from server? */
@@ -231,8 +226,7 @@ void vc_receive(void) {
231 /* inform user, bail out */ 226 /* inform user, bail out */
232 writecf(FS_SERV, "* EOF from server."); 227 writecf(FS_SERV, "* EOF from server.");
233 snprintf(errstr, ERRSTRSIZE, "* EOF from server.\n"); 228 snprintf(errstr, ERRSTRSIZE, "* EOF from server.\n");
234 status = 0; 229 return -1;
235 return;
236 } 230 }
237 231
238 buf_fill += bytes; 232 buf_fill += bytes;
@@ -257,4 +251,5 @@ void vc_receive(void) {
257 buf_fill -= 1 + endmsg - buf; 251 buf_fill -= 1 + endmsg - buf;
258 memmove(buf, endmsg + 1, buf_fill); 252 memmove(buf, endmsg + 1, buf_fill);
259 } 253 }
254 return 0;
260} 255}
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 @@
4 4
5int vc_connect(const char *host, const char *port); 5int vc_connect(const char *host, const char *port);
6void vc_sendmessage(const char *message); 6void vc_sendmessage(const char *message);
7void vc_receive(); 7int vc_receive();
8int vc_poll(); 8int vc_poll();
9void vc_disconnect(); 9void vc_disconnect();