From 55da5d46a5f8dda0e1a9a3cf10b05ea3f48dd923 Mon Sep 17 00:00:00 2001 From: Andy Green Date: Fri, 26 Feb 2016 09:22:12 +0800 Subject: [PATCH] adopt test Signed-off-by: Andy Green --- lib/server.c | 32 +++++++++++++++++++++++++++++--- lib/service.c | 1 + 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/lib/server.c b/lib/server.c index 79ad5829..1a974762 100644 --- a/lib/server.c +++ b/lib/server.c @@ -1130,9 +1130,35 @@ try_pollout: break; } - if (!lws_adopt_socket(context, accept_fd)) - /* already closed cleanly as necessary */ - return 1; + { + static const char *taken = "GET /default HTTP/1.1\r\n" + "Host: server.example.com\r\n" + "Upgrade: websocket\r\n" + "Connection: Upgrade\r\n" + "Sec-WebSocket-Key: x3JJHMbDL1EzLkh9GBhXDw==\r\n" + "Sec-WebSocket-Protocol: default\r\n" + "Sec-WebSocket-Version: 13\r\n" + "Origin: http://example.com\r\n\r\n"; + + struct lws *w; + char discard[2000]; + + lwsl_err("adopt test *********\n"); + + /* drain the real headers that may be there or + * will shortly come on the socket + */ + + n = 0; + while (!n) + n = read(accept_fd, discard, sizeof(discard)); + + lwsl_err("discarded %d from real socket\n", n); + + w = lws_adopt_socket_readbuf(context, + accept_fd, taken, strlen(taken)); + lwsl_err("adopt test: returns %p", w); + } #if LWS_POSIX } while (pt->fds_count < context->fd_limit_per_thread - 1 && diff --git a/lib/service.c b/lib/service.c index e1faeba4..f38bd12f 100644 --- a/lib/service.c +++ b/lib/service.c @@ -460,6 +460,7 @@ lws_service_flag_pending(struct lws_context *context, int tsi) for (n = 0; n < context->max_http_header_pool; n++) if (pt->ah_pool[n].rxpos != pt->ah_pool[n].rxlen && !pt->ah_pool[n].wsi->hdr_parsing_completed) { +lwsl_err("forcing POLLIN\n"); pt->fds[pt->ah_pool[n].wsi->position_in_fds_table].revents |= pt->fds[pt->ah_pool[n].wsi->position_in_fds_table].events & LWS_POLLIN;