diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-01-02 14:27:42 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-01-02 14:27:42 -0800 |
commit | 4485acfbd300ccecd86e37a3d8fdb9c9ade5e541 (patch) | |
tree | a1754dd11c9dfb3ee8244f871f1ced0ce5949f3a /tests/websockets.c | |
parent | faf6b1d3504a8e999d94469abf92938492bedb7b (diff) |
select()
Diffstat (limited to 'tests/websockets.c')
-rw-r--r-- | tests/websockets.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/tests/websockets.c b/tests/websockets.c index 8a8a0919..57549e94 100644 --- a/tests/websockets.c +++ b/tests/websockets.c @@ -8,6 +8,7 @@ #include <string.h> #include <unistd.h> #include <sys/ioctl.h> +#include <assert.h> #if EMSCRIPTEN #include <emscripten.h> #endif @@ -16,11 +17,25 @@ int SocketFD; +int not_always_data = 0; + unsigned int get_all_buf(int sock, char* output, unsigned int maxsize) { + // select check for IO + fd_set sett; + FD_ZERO(&sett); + assert(select(64, &sett, NULL, NULL, NULL) == 0); // empty set + FD_SET(sock, &sett); + assert(select(0, &sett, NULL, NULL, NULL) == 0); // max FD to check is 0 + int select_says_yes = select(64, &sett, NULL, NULL, NULL); + + // ioctl check for IO int bytes; - if (ioctl(sock, FIONREAD, &bytes)) return 0; - if (bytes == 0) return 0; + if (ioctl(sock, FIONREAD, &bytes) || bytes == 0) { + not_always_data = 1; + return 0; + } + assert(select_says_yes); // ioctl must agree with select char buffer[1024]; int n; @@ -67,6 +82,8 @@ void iter(void *arg) { printf("sum: %d\n", sum); #if EMSCRIPTEN + assert(not_always_data == 1); + int result = sum; REPORT_RESULT(); #endif |