tHandle non-blocking connect errors - vaccinewars - be a doctor and try to vacc… | |
git clone git://src.adamsgaard.dk/vaccinewars | |
Log | |
Files | |
Refs | |
README | |
LICENSE | |
--- | |
commit b7b017640b47d311c77eac2f0bd60e7f65286db1 | |
parent f6e1f6dab594b9695e0e220c8b20ad9184019283 | |
Author: Ben Webb <[email protected]> | |
Date: Wed, 11 Nov 2020 19:18:43 -0800 | |
Handle non-blocking connect errors | |
Have select() detect errors on the connecting | |
socket, and terminate the connection in this case. | |
Use a generic message if none is available. | |
Diffstat: | |
M src/curses_client/curses_client.c | 13 ++++++++----- | |
1 file changed, 8 insertions(+), 5 deletions(-) | |
--- | |
diff --git a/src/curses_client/curses_client.c b/src/curses_client/curses_clien… | |
t@@ -562,7 +562,7 @@ void SocksAuthFunc(NetworkBuffer *netbuf, gpointer data) | |
static gboolean DoConnect(Player *Play, GString *errstr) | |
{ | |
NetworkBuffer *netbuf; | |
- fd_set readfds, writefds; | |
+ fd_set readfds, writefds, errorfds; | |
int maxsock, c; | |
gboolean doneOK = TRUE; | |
NBStatus oldstatus; | |
t@@ -583,11 +583,12 @@ static gboolean DoConnect(Player *Play, GString *errstr) | |
oldsocks = netbuf->sockstat; | |
FD_ZERO(&readfds); | |
FD_ZERO(&writefds); | |
+ FD_ZERO(&errorfds); | |
FD_SET(0, &readfds); | |
maxsock = 1; | |
- SetSelectForNetworkBuffer(netbuf, &readfds, &writefds, NULL, | |
+ SetSelectForNetworkBuffer(netbuf, &readfds, &writefds, &errorfds, | |
&maxsock); | |
- if (bselect(maxsock, &readfds, &writefds, NULL, NULL) == -1) { | |
+ if (bselect(maxsock, &readfds, &writefds, &errorfds, NULL) == -1) { | |
if (errno == EINTR) { | |
CheckForResize(Play); | |
continue; | |
t@@ -603,7 +604,7 @@ static gboolean DoConnect(Player *Play, GString *errstr) | |
wrefresh(curscr); | |
#endif | |
} | |
- RespondToSelect(netbuf, &readfds, &writefds, NULL, &doneOK); | |
+ RespondToSelect(netbuf, &readfds, &writefds, &errorfds, &doneOK); | |
} | |
} | |
t@@ -665,7 +666,9 @@ static gboolean ConnectToServer(Player *Play) | |
server (the error message itself is displayed on the next | |
screen line) */ | |
mvaddstr(top, 1, _("Could not start multiplayer dopewars")); | |
- text = g_strdup_printf(" (%s)", errstr->str); | |
+ text = g_strdup_printf(" (%s)", | |
+ errstr->str[0] ? errstr->str | |
+ : _("connection to server failed")); | |
mvaddstr(top + 1, 1, text); | |
g_free(text); | |
} |