trac 40 client connection properly nonblocking

As spotted by JM on Trac#40

http://libwebsockets.org/trac/libwebsockets/ticket/40

client connect didn't do anything about being truly nonblocking.  This patch
should hopefully solve that.

Signed-off-by: Andy Green <andy.green@linaro.org>
diff --git a/lib/libwebsockets.c b/lib/libwebsockets.c
index e2254e0..ea8a8ff 100644
--- a/lib/libwebsockets.c
+++ b/lib/libwebsockets.c
@@ -206,6 +206,17 @@
 
 	wsi->u.ws.close_reason = reason;
 
+	if (wsi->mode == LWS_CONNMODE_WS_CLIENT_WAITING_CONNECT ||
+			wsi->mode == LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE) {
+
+		context->protocols[0].callback(context, wsi,
+			LWS_CALLBACK_CLIENT_CONNECTION_ERROR, NULL, NULL, 0);
+
+		free(wsi->u.hdr.ah);
+		goto just_kill_connection;
+	}
+
+
 	if (wsi->mode == LWS_CONNMODE_HTTP_SERVING_ACCEPTED && wsi->u.http.fd) {
 		lwsl_debug("closing http fd %d\n", wsi->u.http.fd);
 		close(wsi->u.http.fd);
@@ -904,12 +915,10 @@
 		return 0;
 
 	/* just here for timeout management? */
-
 	if (pollfd == NULL)
 		return 0;
 
 	/* no, here to service a socket descriptor */
-
 	wsi = context->lws_lookup[pollfd->fd];
 	if (wsi == NULL)
 		/* not lws connection ... leave revents alone and return */
@@ -1286,8 +1295,10 @@
 	/* wait for something to need service */
 
 	n = poll(context->fds, context->fds_count, timeout_ms);
-	if (n == 0) /* poll timeout */
+	if (n == 0) /* poll timeout */ {
+		libwebsocket_service_fd(context, NULL);
 		return 0;
+	}
 
 	if (n < 0)
 		return -1;