roubustness only return 0 from fd service if handled
Otherwise our app outer loop will think the world is ending
Signed-off-by: Andy Green <andy.green@linaro.org>
diff --git a/lib/client.c b/lib/client.c
index 1fa35b0..027fb77 100644
--- a/lib/client.c
+++ b/lib/client.c
@@ -63,7 +63,7 @@
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
- return 1;
+ return 0;
}
n = recv(wsi->sock, pkt, sizeof pkt, 0);
@@ -71,7 +71,7 @@
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
lwsl_err("ERROR reading from proxy socket\n");
- return 1;
+ return 0;
}
pkt[13] = '\0';
@@ -79,7 +79,7 @@
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
lwsl_err("ERROR from proxy: %s\n", pkt);
- return 1;
+ return 0;
}
/* clear his proxy connection timeout */
@@ -171,15 +171,19 @@
"look good %d\n", n);
libwebsocket_close_and_free_session(context,
wsi, LWS_CLOSE_STATUS_NOSTATUS);
- return 1;
+ return 0;
}
} else
wsi->ssl = NULL;
#endif
p = libwebsockets_generate_client_handshake(context, wsi, p);
- if (p == NULL)
- return 1;
+ if (p == NULL) {
+ lwsl_err("Failed to generate handshake for client, closing it\n");
+ libwebsocket_close_and_free_session(context, wsi,
+ LWS_CLOSE_STATUS_NOSTATUS);
+ return 0;
+ }
/* send our request to the server */
@@ -194,7 +198,7 @@
lwsl_debug("ERROR writing to client socket\n");
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
- return 1;
+ return 0;
}
wsi->parser_state = WSI_TOKEN_NAME_PART;
@@ -271,7 +275,7 @@
free(wsi->c_protocol);
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
- return 1;
+ return 0;
case LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT:
lwsl_ext("LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT\n");
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index ff152f1..df90289 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -868,7 +868,7 @@
if (errno != EINTR && errno != EAGAIN)
libwebsocket_close_and_free_session(context,
wsi, LWS_CLOSE_STATUS_NOSTATUS);
- return 1;
+ return 0;
}
if (!len) {
libwebsocket_close_and_free_session(context, wsi,
@@ -879,7 +879,7 @@
n = libwebsocket_read(context, wsi, buf, len);
if (n < 0)
/* we closed wsi */
- return 1;
+ return 0;
}
/* this handles POLLOUT for http serving fragments */
@@ -1035,7 +1035,7 @@
&clilen);
if (accept_fd < 0) {
lwsl_warn("ERROR on accept %d\n", accept_fd);
- return -1;
+ return 0;
}
if (context->fds_count >= MAX_CLIENTS) {
@@ -1089,7 +1089,7 @@
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NORMAL);
- return 1;
+ return 0;
}
/*
@@ -1102,7 +1102,7 @@
pollfd) < 0) {
libwebsocket_close_and_free_session(
context, wsi, LWS_CLOSE_STATUS_NORMAL);
- return 1;
+ return 0;
}
/* any incoming data ready? */
@@ -1172,7 +1172,7 @@
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
- return 1;
+ return 0;
}
/* the guy requested a callback when it was OK to write */
@@ -1183,7 +1183,7 @@
pollfd) < 0) {
libwebsocket_close_and_free_session(
context, wsi, LWS_CLOSE_STATUS_NORMAL);
- return 1;
+ return 0;
}
@@ -1207,7 +1207,7 @@
if (errno != EINTR && errno != EAGAIN)
libwebsocket_close_and_free_session(context,
wsi, LWS_CLOSE_STATUS_NOSTATUS);
- return 1;
+ return 0;
}
if (!eff_buf.token_len) {
libwebsocket_close_and_free_session(context, wsi,
@@ -1246,7 +1246,7 @@
libwebsocket_close_and_free_session(
context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
- return 1;
+ return 0;
}
if (m)
more = 1;
@@ -1260,7 +1260,7 @@
eff_buf.token_len);
if (n < 0)
/* we closed wsi */
- return 1;
+ return 0;
}
eff_buf.token = NULL;