diff options
author | Andy Green <andy.green@linaro.org> | 2011-02-12 13:15:04 +0000 |
---|---|---|
committer | Andy Green <andy.green@linaro.org> | 2011-02-12 13:15:04 +0000 |
commit | 2a5aa6537d144de6f09ed852a90b545c09788a0e (patch) | |
tree | 84e5056c93bdd2e3b5c21766ad63e1f29bfd0ddd /test-server | |
parent | 3221f92b1e7cac445150d97ce2f13e49b6a7ffeb (diff) |
add-ext-poll-callbacks-in-extpoll-test.patch
Signed-off-by: Andy Green <andy.green@linaro.org>
Diffstat (limited to 'test-server')
-rw-r--r-- | test-server/test-server-extpoll.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/test-server/test-server-extpoll.c b/test-server/test-server-extpoll.c index cccb50e..d7ea10d 100644 --- a/test-server/test-server-extpoll.c +++ b/test-server/test-server-extpoll.c @@ -76,6 +76,8 @@ static int callback_http(struct libwebsocket *wsi, enum libwebsocket_callback_reasons reason, void *user, void *in, size_t len) { + int n; + switch (reason) { case LWS_CALLBACK_HTTP: fprintf(stderr, "serving HTTP URI %s\n", (char *)in); @@ -94,6 +96,39 @@ static int callback_http(struct libwebsocket *wsi, fprintf(stderr, "Failed to send HTTP file\n"); break; + /* + * callbacks for managing the external poll() array appear in + * protocl 0 callback + */ + + case LWS_CALLBACK_ADD_POLL_FD: + pollfds[count_pollfds].fd = (int)(long)user; + pollfds[count_pollfds].events = (int)len; + pollfds[count_pollfds++].revents = 0; + break; + + case LWS_CALLBACK_DEL_POLL_FD: + for (n = 0; n < count_pollfds; n++) + if (pollfds[n].fd == (int)(long)user) + while (n < count_pollfds) { + pollfds[n] = pollfds[n + 1]; + n++; + } + count_pollfds--; + break; + + case LWS_CALLBACK_SET_MODE_POLL_FD: + for (n = 0; n < count_pollfds; n++) + if (pollfds[n].fd == (int)(long)user) + pollfds[n].events |= (int)(long)len; + break; + + case LWS_CALLBACK_CLEAR_MODE_POLL_FD: + for (n = 0; n < count_pollfds; n++) + if (pollfds[n].fd == (int)(long)user) + pollfds[n].events &= ~(int)(long)len; + break; + default: break; } @@ -194,9 +229,11 @@ callback_lws_mirror(struct libwebsocket *wsi, case LWS_CALLBACK_ESTABLISHED: pss->ringbuffer_tail = ringbuffer_head; pss->wsi = wsi; + libwebsocket_callback_on_writable(wsi); break; case LWS_CALLBACK_CLIENT_WRITEABLE: + if (pss->ringbuffer_tail != ringbuffer_head) { n = libwebsocket_write(wsi, (unsigned char *) @@ -204,6 +241,7 @@ callback_lws_mirror(struct libwebsocket *wsi, LWS_SEND_BUFFER_PRE_PADDING, ringbuffer[pss->ringbuffer_tail].len, LWS_WRITE_TEXT); + if (n < 0) { fprintf(stderr, "ERROR writing to socket"); exit(1); |