acl/lib_acl_cpp/include/acl_cpp/http/websocket.hpp

391 lines
8.6 KiB
C++
Raw Normal View History

/**
2018-12-12 11:16:12 +08:00
* Copyright (C) 2015-2018
* All rights reserved.
*
* AUTHOR(S)
* niukey@qq.com
* shuxin.zheng@qq.com
*
* VERSION
* Sun 18 Sep 2016 05:15:52 PM CST
*/
#pragma once
#include "../acl_cpp_define.hpp"
#include "../stdlib/noncopyable.hpp"
2018-12-12 11:16:12 +08:00
namespace acl
{
class socket_stream;
2019-06-10 13:00:25 +08:00
class aio_socket_stream;
2018-12-12 11:16:12 +08:00
enum
{
FRAME_CONTINUATION = 0x00,
FRAME_TEXT = 0x01,
FRAME_BINARY = 0x02,
FRAME_RSV3 = 0x03,
FRAME_RSV4 = 0x04,
FRAME_RSV5 = 0x05,
FRAME_RSV6 = 0x06,
FRAME_RSV7 = 0x07,
FRAME_CLOSE = 0x08,
FRAME_PING = 0x09,
FRAME_PONG = 0x0A,
FRAME_CTL_RSVB = 0x0B,
FRAME_CTL_RSVC = 0x0C,
FRAME_CTL_RSVD = 0x0D,
FRAME_CTL_RSVE = 0x0E,
FRAME_CTL_RSVF = 0x0F,
};
struct frame_header
{
bool fin;
bool rsv1;
bool rsv2;
bool rsv3;
unsigned char opcode:4;
bool mask;
unsigned long long payload_len;
unsigned int masking_key;
2019-12-10 13:31:07 +08:00
frame_header(void) {
fin = false;
rsv1 = false;
rsv2 = false;
rsv3 = false;
opcode = FRAME_TEXT;
mask = false;
payload_len = 0;
masking_key = 0;
}
2018-12-12 11:16:12 +08:00
};
2019-06-06 23:43:04 +08:00
class string;
2018-12-12 11:16:12 +08:00
/**
* websocket <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
*/
class ACL_CPP_API websocket : public noncopyable
2018-12-12 11:16:12 +08:00
{
public:
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
* @param client {socket_stream&}
*/
websocket(socket_stream& client);
~websocket(void);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ظ<EFBFBD>ʹ<EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
*/
websocket& reset(void);
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>󶨵<EFBFBD> socket_stream <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
* @return {socket_stream&}
*/
socket_stream& get_stream(void) const
{
return client_;
}
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>־λ
2018-12-12 11:16:12 +08:00
* @param yes {bool}
* @return {websocket&}
*/
websocket& set_frame_fin(bool yes);
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
2018-12-12 11:16:12 +08:00
* @param yes {bool}
* @return {websocket&}
*/
websocket& set_frame_rsv1(bool yes);
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
2018-12-12 11:16:12 +08:00
* @param yes {bool}
* @return {websocket&}
*/
websocket& set_frame_rsv2(bool yes);
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
2018-12-12 11:16:12 +08:00
* @param yes {bool}
* @return {websocket&}
*/
websocket& set_frame_rsv3(bool yes);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD><EFBFBD>μ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>FRAME_XXX
2018-12-12 11:16:12 +08:00
* @param type {unsigned char}
* @return {websocket&}
*/
websocket& set_frame_opcode(unsigned char type);
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ܳ<EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
* @param len {unsigned long long}
* @return {websocket&}
*/
websocket& set_frame_payload_len(unsigned long long len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD>ģʽ<EFBFBD>±<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ô<EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
* @param mask {unsigned int}
* @return {websocket&}
*/
websocket& set_frame_masking_key(unsigned int mask);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>е<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͱ<EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>ܳ<EFBFBD><EFBFBD><EFBFBD>(<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ε<EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>֮<EFBFBD><EFBFBD>)Ӧ<EFBFBD><EFBFBD> set_frame_payload_len
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD>ֵ<EFBFBD><EFBFBD>ͬ
2018-12-12 11:16:12 +08:00
* @param data {const void*}
* @param len {size_t}
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2018-12-12 11:16:12 +08:00
*/
bool send_frame_data(const void* data, size_t len);
bool send_frame_data(void* data, size_t len);
bool send_frame_data(const char* str);
bool send_frame_data(char* str);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> PONG <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
* @param data {const void*} PONG <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ NULL
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD> data Ϊ NULL <EFBFBD><EFBFBD> len Ϊ 0 ʱ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>ʾû<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2018-12-12 11:16:12 +08:00
*/
bool send_frame_pong(const void* data, size_t len);
bool send_frame_pong(void* data, size_t len);
bool send_frame_pong(const char* str);
bool send_frame_pong(char* str);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> PING <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
* @param data {const void*} PING <EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ NULL
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD> data Ϊ NULL <EFBFBD><EFBFBD> len Ϊ 0 ʱ<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>ʾû<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>غ<EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD>
2018-12-12 11:16:12 +08:00
*/
bool send_frame_ping(const void* data, size_t len);
bool send_frame_ping(void* data, size_t len);
bool send_frame_ping(const char* str);
bool send_frame_ping(char* str);
2019-06-10 13:00:25 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͽӿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݺ<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD>Ӧ<EFBFBD>õ<EFBFBD><EFBFBD><EFBFBD>
* reset() <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD>ǰ<EFBFBD><EFBFBD>Ӧ<EFBFBD>ò<EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ϵ<EFBFBD>
* set_frame_xxx <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ÿһ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݰ<EFBFBD><EFBFBD><EFBFBD>֡ͷ<EFBFBD><EFBFBD>Ϣ
2019-06-10 13:00:25 +08:00
* @param conn {aio_socket_stream&}
* @param data {void*} Ҫ<EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD>޸<EFBFBD>
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2019-06-10 13:00:25 +08:00
*/
bool send_frame_data(aio_socket_stream& conn, void* data, size_t len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_TEXT <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
2019-06-10 13:00:25 +08:00
* @param conn {aio_socket_stream&}
* @param data {char*}
* @param len {size_t}
* @return {bool}
*/
bool send_frame_text(aio_socket_stream& conn, char* data, size_t len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_BINARY <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
2019-06-10 13:00:25 +08:00
* @param conn {aio_socket_stream&}
* @param data {char*}
* @param len {size_t}
* @return {bool}
*/
bool send_frame_binary(aio_socket_stream& conn, void* data, size_t len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_PING <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
2019-06-10 13:00:25 +08:00
* @param conn {aio_socket_stream&}
* @param data {char*}
* @param len {size_t}
* @return {bool}
*/
bool send_frame_ping(aio_socket_stream& conn, void* data, size_t len);
/**
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_PONG <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
2019-06-10 13:00:25 +08:00
* @param conn {aio_socket_stream&}
* @param data {char*}
* @param len {size_t}
* @return {bool}
*/
bool send_frame_pong(aio_socket_stream& conn, void* data, size_t len);
2018-12-12 11:16:12 +08:00
/**
* <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡֡ͷ
2018-12-12 11:16:12 +08:00
* @return {bool}
*/
bool read_frame_head(void);
/**
* <EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param buf {void*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵĻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} buf <EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>С
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ > 0 <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ٴζ<EFBFBD><EFBFBD><EFBFBD>== 0 <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* < 0 <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
*/
int read_frame_data(void* buf, size_t size);
2019-06-06 23:43:04 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ȡ websocket <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* <EFBFBD>ߵ<EFBFBD><EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> websocket ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD> eof() <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> eof() <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true<EFBFBD><EFBFBD>
* <EFBFBD><EFBFBD>Ӧ<EFBFBD>ͷű<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> true <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> websocket ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* read_frame_data() <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2019-06-06 23:43:04 +08:00
*/
bool peek_frame_head(void);
/**
* <EFBFBD><EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>ȡ websocket <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѭ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param buf {char*} <EFBFBD><EFBFBD><EFBFBD>Ŷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* @param size {size_t} buf <EFBFBD>Ŀռ<EFBFBD><EFBFBD><EFBFBD>С
* @return {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD>ȣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵΪ<EFBFBD><EFBFBD>
* 0: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
* -1: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> eof() <EFBFBD>ж<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>ر<EFBFBD>
* >0: <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD>ζ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
2019-06-06 23:43:04 +08:00
*/
int peek_frame_data(char* buf, size_t size);
int peek_frame_data(string& buf, size_t size);
2019-06-06 23:43:04 +08:00
/**
* <EFBFBD>жϵ<EFBFBD>ǰ<EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѷ<EFBFBD><EFBFBD><EFBFBD> websocket ֡ͷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2019-06-06 23:43:04 +08:00
* @return {bool}
*/
bool is_head_finish(void) const;
2019-06-06 23:43:04 +08:00
/**
* <EFBFBD>жϵ<EFBFBD>ǰ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Ѿ<EFBFBD><EFBFBD>Ͽ<EFBFBD>
2019-06-06 23:43:04 +08:00
* @return {bool}
*/
bool eof(void);
2018-12-12 11:16:12 +08:00
/**
* <EFBFBD><EFBFBD><EFBFBD>ö<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD>֡ͷ
2018-12-12 11:16:12 +08:00
* @return {const frame_header&}
*/
const frame_header& get_frame_header(void) const
{
return header_;
}
/**
* <EFBFBD>жϱ<EFBFBD>֡<EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
2018-12-12 11:16:12 +08:00
* @return {bool}
*/
bool frame_is_fin(void) const
{
return header_.fin;
}
/**
* <EFBFBD>жϱ<EFBFBD>֡<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
2018-12-12 11:16:12 +08:00
* @return {bool}
*/
bool frame_is_rsv1(void) const
{
return header_.rsv1;
}
/**
* <EFBFBD>жϱ<EFBFBD>֡<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
2018-12-12 11:16:12 +08:00
* @return {bool}
*/
bool frame_is_rsv2(void) const
{
return header_.rsv2;
}
/**
* <EFBFBD>жϱ<EFBFBD>֡<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˱<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>־λ
2018-12-12 11:16:12 +08:00
* @return {bool}
*/
bool frame_is_rsv3(void) const
{
return header_.rsv3;
}
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD>״̬<EFBFBD><EFBFBD>μ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>FRAME_XXX
2018-12-12 11:16:12 +08:00
* @return {unsigned char}
*/
unsigned char get_frame_opcode(void) const
{
return header_.opcode;
}
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
* @return {bool}
*/
bool frame_has_mask(void) const
{
return header_.mask;
}
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
* @return {unsigned long long}
*/
unsigned long long get_frame_payload_len(void) const
{
return header_.payload_len;
}
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ
2018-12-12 11:16:12 +08:00
* @return {unsigned int}
*/
unsigned int get_frame_masking_key(void) const
{
return header_.masking_key;
}
/**
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡<EFBFBD>Ѷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
2018-12-12 11:16:12 +08:00
* @return {unsigned long long}
*/
unsigned long long get_frame_payload_nread(void) const
{
return payload_nread_;
}
private:
socket_stream& client_;
struct frame_header header_;
char* header_buf_;
size_t header_size_;
size_t header_len_;
unsigned long long payload_nread_;
unsigned long long payload_nsent_;
bool header_sent_;
2019-06-06 23:43:04 +08:00
unsigned status_;
string* peek_buf_;
2019-06-06 23:43:04 +08:00
2018-12-12 11:16:12 +08:00
void make_frame_header(void);
2019-06-06 23:43:04 +08:00
void update_head_2bytes(unsigned char ch1, unsigned ch2);
bool peek_head_2bytes(void);
bool peek_head_len_2bytes(void);
bool peek_head_len_8bytes(void);
bool peek_head_masking_key(void);
2018-12-12 11:16:12 +08:00
};
} // namespace acl