diff options
Diffstat (limited to 'src/examples/websocket_threaded_example.c')
-rw-r--r-- | src/examples/websocket_threaded_example.c | 86 |
1 files changed, 43 insertions, 43 deletions
diff --git a/src/examples/websocket_threaded_example.c b/src/examples/websocket_threaded_example.c index ea12e14b..2c1f31b3 100644 --- a/src/examples/websocket_threaded_example.c +++ b/src/examples/websocket_threaded_example.c | |||
@@ -36,40 +36,40 @@ | |||
36 | "<title>WebSocket chat</title>\n" \ | 36 | "<title>WebSocket chat</title>\n" \ |
37 | "<script>\n" \ | 37 | "<script>\n" \ |
38 | "document.addEventListener('DOMContentLoaded', function() {\n" \ | 38 | "document.addEventListener('DOMContentLoaded', function() {\n" \ |
39 | " const ws = new WebSocket('ws:// ' + window.location.host);\n" \ | 39 | " const ws = new WebSocket('ws:// ' + window.location.host);\n" /* \ |
40 | // " const btn = document.getElementById('send');\n" \ | 40 | " const btn = document.getElementById('send');\n" \ |
41 | // " const msg = document.getElementById('msg');\n" \ | 41 | " const msg = document.getElementById('msg');\n" \ |
42 | // " const log = document.getElementById('log');\n" \ | 42 | " const log = document.getElementById('log');\n" \ |
43 | // " ws.onopen = function() {\n" \ | 43 | " ws.onopen = function() {\n" \ |
44 | // " log.value += 'Connected\\n';\n" \ | 44 | " log.value += 'Connected\\n';\n" \ |
45 | // " };\n" \ | 45 | " };\n" \ |
46 | // " ws.onclose = function() {\n" \ | 46 | " ws.onclose = function() {\n" \ |
47 | // " log.value += 'Disconnected\\n';\n" \ | 47 | " log.value += 'Disconnected\\n';\n" \ |
48 | // " };\n" \ | 48 | " };\n" \ |
49 | // " ws.onmessage = function(ev) {\n" \ | 49 | " ws.onmessage = function(ev) {\n" \ |
50 | // " log.value += ev.data + '\\n';\n" \ | 50 | " log.value += ev.data + '\\n';\n" \ |
51 | // " };\n" \ | 51 | " };\n" \ |
52 | // " btn.onclick = function() {\n" \ | 52 | " btn.onclick = function() {\n" \ |
53 | // " log.value += '<You>: ' + msg.value + '\\n';\n" \ | 53 | " log.value += '<You>: ' + msg.value + '\\n';\n" \ |
54 | // " ws.send(msg.value);\n" \ | 54 | " ws.send(msg.value);\n" \ |
55 | // " };\n" \ | 55 | " };\n" \ |
56 | // " msg.onkeyup = function(ev) {\n" \ | 56 | " msg.onkeyup = function(ev) {\n" \ |
57 | // " if (ev.keyCode === 13) {\n" \ | 57 | " if (ev.keyCode === 13) {\n" \ |
58 | // " ev.preventDefault();\n" \ | 58 | " ev.preventDefault();\n" \ |
59 | // " ev.stopPropagation();\n" \ | 59 | " ev.stopPropagation();\n" \ |
60 | // " btn.click();\n" \ | 60 | " btn.click();\n" \ |
61 | // " msg.value = '';\n" \ | 61 | " msg.value = '';\n" \ |
62 | // " }\n" \ | 62 | " }\n" \ |
63 | // " };\n" \ | 63 | " };\n" \ |
64 | // "});\n" \ | 64 | "});\n" \ |
65 | // "</script>\n" \ | 65 | "</script>\n" \ |
66 | // "</head>\n" \ | 66 | "</head>\n" \ |
67 | // "<body>\n" \ | 67 | "<body>\n" \ |
68 | // "<input type='text' id='msg' autofocus/>\n" \ | 68 | "<input type='text' id='msg' autofocus/>\n" \ |
69 | // "<input type='button' id='send' value='Send' /><br /><br />\n" \ | 69 | "<input type='button' id='send' value='Send' /><br /><br />\n" \ |
70 | // "<textarea id='log' rows='20' cols='28'></textarea>\n" \ | 70 | "<textarea id='log' rows='20' cols='28'></textarea>\n" \ |
71 | // "</body>\n" \ | 71 | "</body>\n" \ |
72 | // "</html>" | 72 | "</html>" */ |
73 | #define BAD_REQUEST_PAGE \ | 73 | #define BAD_REQUEST_PAGE \ |
74 | "<html>\n" \ | 74 | "<html>\n" \ |
75 | "<head>\n" \ | 75 | "<head>\n" \ |
@@ -101,7 +101,7 @@ | |||
101 | 101 | ||
102 | #define MAX_CLIENTS 10 | 102 | #define MAX_CLIENTS 10 |
103 | 103 | ||
104 | static int CLIENT_SOCKS[MAX_CLIENTS]; | 104 | static MHD_socket CLIENT_SOCKS[MAX_CLIENTS]; |
105 | 105 | ||
106 | static pthread_mutex_t MUTEX = PTHREAD_MUTEX_INITIALIZER; | 106 | static pthread_mutex_t MUTEX = PTHREAD_MUTEX_INITIALIZER; |
107 | 107 | ||
@@ -535,7 +535,7 @@ send_all (MHD_socket sock, const unsigned char *buf, size_t len) | |||
535 | 535 | ||
536 | for (off = 0; off < len; off += ret) | 536 | for (off = 0; off < len; off += ret) |
537 | { | 537 | { |
538 | ret = send (sock, &buf[off], len - off, 0); | 538 | ret = send (sock, (const void*)&buf[off], len - off, 0); |
539 | if (0 > ret) | 539 | if (0 > ret) |
540 | { | 540 | { |
541 | if (EAGAIN == errno) | 541 | if (EAGAIN == errno) |
@@ -555,14 +555,14 @@ send_all (MHD_socket sock, const unsigned char *buf, size_t len) | |||
555 | 555 | ||
556 | 556 | ||
557 | static int | 557 | static int |
558 | ws_send_frame (int sock, const char *msg, size_t length) | 558 | ws_send_frame (MHD_socket sock, const char *msg, size_t length) |
559 | { | 559 | { |
560 | unsigned char *response; | 560 | unsigned char *response; |
561 | unsigned char frame[10]; | 561 | unsigned char frame[10]; |
562 | unsigned char idx_first_rdata; | 562 | unsigned char idx_first_rdata; |
563 | int idx_response; | 563 | int idx_response; |
564 | int output; | 564 | int output; |
565 | int isock; | 565 | MHD_socket isock; |
566 | size_t i; | 566 | size_t i; |
567 | 567 | ||
568 | frame[0] = (WS_FIN | WS_OPCODE_TEXT_FRAME); | 568 | frame[0] = (WS_FIN | WS_OPCODE_TEXT_FRAME); |
@@ -613,7 +613,7 @@ ws_send_frame (int sock, const char *msg, size_t length) | |||
613 | for (i = 0; i < MAX_CLIENTS; i++) | 613 | for (i = 0; i < MAX_CLIENTS; i++) |
614 | { | 614 | { |
615 | isock = CLIENT_SOCKS[i]; | 615 | isock = CLIENT_SOCKS[i]; |
616 | if ((isock > -1) && (isock != sock)) | 616 | if ((isock != MHD_INVALID_SOCKET) && (isock != sock)) |
617 | { | 617 | { |
618 | output += send_all (isock, response, idx_response); | 618 | output += send_all (isock, response, idx_response); |
619 | } | 619 | } |
@@ -699,7 +699,7 @@ run_usock (void *cls) | |||
699 | make_blocking (ws->sock); | 699 | make_blocking (ws->sock); |
700 | while (1) | 700 | while (1) |
701 | { | 701 | { |
702 | got = recv (ws->sock, buf, sizeof (buf), 0); | 702 | got = recv (ws->sock, (void*) buf, sizeof (buf), 0); |
703 | if (0 >= got) | 703 | if (0 >= got) |
704 | { | 704 | { |
705 | break; | 705 | break; |
@@ -711,7 +711,7 @@ run_usock (void *cls) | |||
711 | } | 711 | } |
712 | if (type == WS_OPCODE_TEXT_FRAME) | 712 | if (type == WS_OPCODE_TEXT_FRAME) |
713 | { | 713 | { |
714 | size = sprintf (client, "User#%d: ", ws->sock); | 714 | size = sprintf (client, "User#%d: ", (int)ws->sock); |
715 | size += got; | 715 | size += got; |
716 | text = malloc (size); | 716 | text = malloc (size); |
717 | if (NULL != buf) | 717 | if (NULL != buf) |
@@ -744,7 +744,7 @@ run_usock (void *cls) | |||
744 | { | 744 | { |
745 | if (CLIENT_SOCKS[i] == ws->sock) | 745 | if (CLIENT_SOCKS[i] == ws->sock) |
746 | { | 746 | { |
747 | CLIENT_SOCKS[i] = -1; | 747 | CLIENT_SOCKS[i] = MHD_INVALID_SOCKET; |
748 | break; | 748 | break; |
749 | } | 749 | } |
750 | } | 750 | } |
@@ -781,7 +781,7 @@ uh_cb (void *cls, struct MHD_Connection *con, void *con_cls, | |||
781 | pthread_mutex_lock (&MUTEX); | 781 | pthread_mutex_lock (&MUTEX); |
782 | for (i = 0; i < MAX_CLIENTS; i++) | 782 | for (i = 0; i < MAX_CLIENTS; i++) |
783 | { | 783 | { |
784 | if (-1 == CLIENT_SOCKS[i]) | 784 | if (MHD_INVALID_SOCKET == CLIENT_SOCKS[i]) |
785 | { | 785 | { |
786 | CLIENT_SOCKS[i] = ws->sock; | 786 | CLIENT_SOCKS[i] = ws->sock; |
787 | sock_overflow = MHD_NO; | 787 | sock_overflow = MHD_NO; |