| 2 | #include "websocket.h" |
| 3 | |
| 4 | static bool ws_ping(acl::websocket& in, acl::websocket& out) |
| 5 | { |
| 6 | unsigned long long len = in.get_frame_payload_len(); |
| 7 | if (len == 0) { |
| 8 | if (out.send_frame_pong((const void*) NULL, 0) == false) { |
| 9 | return false; |
| 10 | } else { |
| 11 | return true; |
| 12 | } |
| 13 | } |
| 14 | |
| 15 | out.reset().set_frame_fin(true) |
| 16 | .set_frame_opcode(acl::FRAME_PONG) |
| 17 | .set_frame_payload_len(len); |
| 18 | |
| 19 | char buf[4096]; |
| 20 | while (true) { |
| 21 | int ret = in.read_frame_data(buf, sizeof(buf) - 1); |
| 22 | if (ret == 0) { |
| 23 | break; |
| 24 | } |
| 25 | |
| 26 | if (ret < 0) { |
| 27 | printf("read_frame_data error\r\n"); |
| 28 | return false; |
| 29 | } |
| 30 | |
| 31 | buf[ret] = 0; |
| 32 | printf("read: [%s]\r\n", buf); |
| 33 | if (out.send_frame_data(buf, ret) == false) { |
| 34 | printf("send_frame_data error\r\n"); |
| 35 | return false; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | return true; |
| 40 | } |
| 41 | |
| 42 | static bool ws_pong(acl::websocket& in, acl::websocket&) |
| 43 | { |
no test coverage detected
searching dependent graphs…