diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-09-28 15:37:02 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-09-28 15:37:02 -0700 |
commit | 32e88a57eb101df7a25f885699a05bcac1f791f7 (patch) | |
tree | aa3ff673ecb9cb9ade75e46385f029ff77d8a234 /tests/websockets.c | |
parent | 46b3356e4812b8eb5e8986abee4626d9bac140b9 (diff) |
support ioctl-FIONREAD
Diffstat (limited to 'tests/websockets.c')
-rw-r--r-- | tests/websockets.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/tests/websockets.c b/tests/websockets.c index c74b145d..6e81eb47 100644 --- a/tests/websockets.c +++ b/tests/websockets.c @@ -7,6 +7,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <sys/ioctl.h> #if EMSCRIPTEN #include <emscripten.h> #endif @@ -17,8 +18,11 @@ int SocketFD; unsigned int get_all_buf(int sock, char* output, unsigned int maxsize) { - char buffer[1024]; + int bytes; + if (ioctl(sock, FIONREAD, &bytes)) return 0; + if (bytes == 0) return 0; + char buffer[1024]; int n; unsigned int offset = 0; while((errno = 0, (n = recv(sock, buffer, sizeof(buffer), 0))>0) || |