summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2012-07-20 12:58:38 +0800
committerAndy Green <andy.green@linaro.org>2012-07-20 12:58:38 +0800
commit3928f6178a16583a7675f9bf1d7c9365876aa6e3 (patch)
treed239952156b565d39af7a0bffe159034419fa668
parent915316644cb47ec5a2d2ad3b5a233e5cd2b73db5 (diff)
restore accept error as closure signal
Signed-off-by: Andy Green <andy.green@linaro.org>
-rw-r--r--config.h.in3
-rwxr-xr-xconfigure2
-rw-r--r--lib/client-handshake.c3
-rw-r--r--lib/libwebsockets.c19
-rw-r--r--test-server/test-client.c3
-rw-r--r--test-server/test-server-extpoll.c5
-rw-r--r--test-server/test-server.c8
7 files changed, 27 insertions, 16 deletions
diff --git a/config.h.in b/config.h.in
index e7dd31b..7e3bec1 100644
--- a/config.h.in
+++ b/config.h.in
@@ -53,6 +53,9 @@
/* Define to 1 if you have the <string.h> header file. */
#undef HAVE_STRING_H
+/* Define to 1 if you have the <sys/prctl.h> header file. */
+#undef HAVE_SYS_PRCTL_H
+
/* Define to 1 if you have the <sys/socket.h> header file. */
#undef HAVE_SYS_SOCKET_H
diff --git a/configure b/configure
index eac5e1d..f6cdf0f 100755
--- a/configure
+++ b/configure
@@ -12438,7 +12438,7 @@ fi
# Checks for header files.
-for ac_header in zlib.h fcntl.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h
+for ac_header in zlib.h fcntl.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h sys/prctl.h
do :
as_ac_Header=`$as_echo "ac_cv_header_$ac_header" | $as_tr_sh`
ac_fn_c_check_header_mongrel "$LINENO" "$ac_header" "$as_ac_Header" "$ac_includes_default"
diff --git a/lib/client-handshake.c b/lib/client-handshake.c
index d3d3daa..ceb5f76 100644
--- a/lib/client-handshake.c
+++ b/lib/client-handshake.c
@@ -138,7 +138,8 @@ struct libwebsocket *__libwebsocket_client_connect_2(
wsi->mode = LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE;
pfd.fd = wsi->sock;
pfd.revents = POLLIN;
- libwebsocket_service_fd(context, &pfd);
+ if (libwebsocket_service_fd(context, &pfd) < 0)
+ goto oom4;
return wsi;
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index 7680817..03147e1 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -1529,8 +1529,8 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
accept_fd = accept(pollfd->fd, (struct sockaddr *)&cli_addr,
&clilen);
if (accept_fd < 0) {
- fprintf(stderr, "ERROR on accept");
- break;
+ debug("ERROR on accept\n");
+ return -1;
}
/* Disable Nagle */
@@ -1641,8 +1641,8 @@ libwebsocket_service_fd(struct libwebsocket_context *context,
accept_fd = accept(pollfd->fd, (struct sockaddr *)&cli_addr,
&clilen);
if (accept_fd < 0) {
- fprintf(stderr, "ERROR on accept");
- break;
+ debug("ERROR on accept\n");
+ return -1;
}
if (context->fds_count >= MAX_CLIENTS) {
@@ -2174,15 +2174,16 @@ libwebsocket_service(struct libwebsocket_context *context, int timeout_ms)
/*
fprintf(stderr, "Listen Socket dead\n");
*/
- return 1;
+ return -1;
}
/* handle accept on listening socket? */
for (n = 0; n < context->fds_count; n++)
if (context->fds[n].revents)
- libwebsocket_service_fd(context, &context->fds[n]);
-
+ if (libwebsocket_service_fd(context,
+ &context->fds[n]) < 0)
+ return -1;
return 0;
}
@@ -3030,7 +3031,7 @@ libwebsockets_fork_service_loop(struct libwebsocket_context *context)
while (1) {
if (libwebsocket_service(context, 1000))
- return -1;
+ break;
#ifndef HAVE_SYS_PRCTL_H
/*
* on systems without prctl() (i.e. anything but linux) we can notice that our
@@ -3044,7 +3045,7 @@ libwebsockets_fork_service_loop(struct libwebsocket_context *context)
}
- return 0;
+ return 1;
}
#endif
diff --git a/test-server/test-client.c b/test-server/test-client.c
index 9d1d9ef..ffd6365 100644
--- a/test-server/test-client.c
+++ b/test-server/test-client.c
@@ -287,6 +287,9 @@ int main(int argc, char **argv)
while (n >= 0 && !was_closed) {
n = libwebsocket_service(context, 1000);
+ if (n < 0)
+ continue;
+
if (wsi_mirror == NULL) {
/* create a client websocket using mirror protocol */
diff --git a/test-server/test-server-extpoll.c b/test-server/test-server-extpoll.c
index 0b44d8a..8131412 100644
--- a/test-server/test-server-extpoll.c
+++ b/test-server/test-server-extpoll.c
@@ -517,8 +517,9 @@ int main(int argc, char **argv)
* match anything under libwebsockets
* control
*/
- libwebsocket_service_fd(context,
- &pollfds[n]);
+ if (libwebsocket_service_fd(context,
+ &pollfds[n]))
+ goto done;
/* do our broadcast periodically */
diff --git a/test-server/test-server.c b/test-server/test-server.c
index dae0a8d..516deff 100644
--- a/test-server/test-server.c
+++ b/test-server/test-server.c
@@ -463,7 +463,8 @@ int main(int argc, char **argv)
fprintf(stderr, " Using no-fork service loop\n");
- while (1) {
+ n = 0;
+ while (n >= 0) {
struct timeval tv;
gettimeofday(&tv, NULL);
@@ -495,10 +496,11 @@ int main(int argc, char **argv)
* "manually".
*
* If no socket is needing service, the call below returns
- * immediately and quickly.
+ * immediately and quickly. Negative return means we are
+ * in process of closing
*/
- libwebsocket_service(context, 50);
+ n = libwebsocket_service(context, 50);
}
#else