2019-07-28 10:31:56 +08:00
|
|
|
|
#pragma once
|
2019-06-05 17:36:47 +08:00
|
|
|
|
#include "../acl_cpp_define.hpp"
|
|
|
|
|
#include "../stream/aio_socket_stream.hpp"
|
2019-08-13 18:29:40 +08:00
|
|
|
|
#if !defined(_WIN32) && !defined(_WIN64)
|
|
|
|
|
#include <netinet/in.h> // just for "struct sockaddr_storage"
|
|
|
|
|
#endif
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
|
|
|
|
struct HTTP_HDR;
|
|
|
|
|
struct HTTP_HDR_RES;
|
|
|
|
|
struct HTTP_RES;
|
|
|
|
|
struct HTTP_HDR_REQ;
|
|
|
|
|
struct HTTP_REQ;
|
|
|
|
|
|
2019-08-13 18:29:40 +08:00
|
|
|
|
struct ACL_ASTREAM_CTX;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
|
|
|
|
namespace acl {
|
|
|
|
|
|
2019-08-09 18:05:51 +08:00
|
|
|
|
class string;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
class aio_handle;
|
|
|
|
|
class aio_socket_stream;
|
2019-06-06 23:43:04 +08:00
|
|
|
|
class socket_stream;
|
2019-06-10 16:08:21 +08:00
|
|
|
|
class zlib_stream;
|
2019-06-06 23:43:04 +08:00
|
|
|
|
class websocket;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
class polarssl_conf;
|
|
|
|
|
class polarssl_io;
|
|
|
|
|
class http_header;
|
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* HTTP <EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>첽ͨ<EFBFBD><EFBFBD><EFBFBD>࣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD>ֱ<EFBFBD> HTTP ͨ<EFBFBD><EFBFBD>Э<EFBFBD>飬<EFBFBD><EFBFBD><EFBFBD><EFBFBD>֧<EFBFBD><EFBFBD> Websocket ͨ<EFBFBD>ţ<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP Э<EFBFBD>鼰 Websocket ͨ<EFBFBD>ž<EFBFBD>֧<EFBFBD><EFBFBD> SSL <EFBFBD><EFBFBD><EFBFBD>ܴ<EFBFBD><EFBFBD>䣻
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>⣬<EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP Э<EFBFBD>飬<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>ѹ GZIP <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڻص<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> on_http_res_body() <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD><EFBFBD>ı<EFBFBD><EFBFBD>ǽ<EFBFBD>ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-06-05 17:36:47 +08:00
|
|
|
|
class ACL_CPP_API http_aclient : public aio_open_callback
|
|
|
|
|
{
|
|
|
|
|
public:
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD>
|
|
|
|
|
* @param handle {aio_handle&} <EFBFBD>첽ͨ<EFBFBD><EFBFBD><EFBFBD>¼<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param ssl_conf {polarssl_conf*} <EFBFBD><EFBFBD> NULL ʱ<EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SSL ͨ<EFBFBD>ŷ<EFBFBD>ʽ
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-06-05 17:36:47 +08:00
|
|
|
|
http_aclient(aio_handle& handle, polarssl_conf* ssl_conf = NULL);
|
2019-06-06 13:46:23 +08:00
|
|
|
|
virtual ~http_aclient(void);
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +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>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual void destroy(void) = 0;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD><EFBFBD>Ա<EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD>е<EFBFBD><EFBFBD>ֶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
* @return {http_header&}
|
|
|
|
|
*/
|
|
|
|
|
http_header& request_header(void);
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
2019-06-10 16:08:21 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP Э<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>ѹ
|
2019-06-10 16:08:21 +08:00
|
|
|
|
* @param on {bool}
|
|
|
|
|
* @return {http_aclient&}
|
|
|
|
|
*/
|
|
|
|
|
http_aclient& unzip_body(bool on);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> GZIP ѹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>н<EFBFBD>ѹ
|
2019-06-10 16:08:21 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool is_unzip_body(void) const
|
|
|
|
|
{
|
|
|
|
|
return unzip_;
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-18 10:02:22 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SSL conf <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> ssl_conf Ϊ NULL<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD> ssl_enable_ <EFBFBD><EFBFBD>Ϊ
|
|
|
|
|
* false<EFBFBD><EFBFBD>ͨ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ssl_conf <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> enable_ssl()
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ssl <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param ssl_conf {polarssl_conf*} Ϊ NULL ʱ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD> SSL<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {http_aclient&}
|
|
|
|
|
*/
|
|
|
|
|
http_aclient& set_ssl_conf(polarssl_conf* ssl_conf);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD> SSL <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {polarssl_conf*} Ϊ NULL <EFBFBD><EFBFBD>ʾδ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
polarssl_conf* get_ssl_conf(void) const
|
|
|
|
|
{
|
|
|
|
|
return ssl_conf_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>캯<EFBFBD><EFBFBD><EFBFBD><EFBFBD> ssl_conf <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> SSL
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ssl_conf <EFBFBD>ǿգ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD> ssl_enable_ ȱʡֵΪ true<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨ
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>رջ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ssl <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param yes {bool}
|
|
|
|
|
* @return {http_aclient&}
|
|
|
|
|
*/
|
|
|
|
|
http_aclient& enable_ssl(bool yes);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>ж<EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>Ƿ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ssl <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool is_enable_ssl(void) const
|
|
|
|
|
{
|
2019-10-18 10:03:52 +08:00
|
|
|
|
return ssl_enable_ && ssl_conf_;
|
2019-10-18 10:02:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ʼ<EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param addr {const char*} Զ<EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʽΪ<EFBFBD><EFBFBD>
|
|
|
|
|
* domain:port <EFBFBD><EFBFBD> ip:port, <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> aio_handle::set_dns() <EFBFBD><EFBFBD><EFBFBD>ù<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַΪ IP <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 conn_timeout {int} <EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD>ʱʱ<EFBFBD>䣨<EFBFBD>룩
|
|
|
|
|
* @param rw_timeout {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> IO <EFBFBD><EFBFBD>д<EFBFBD><EFBFBD>ʱʱ<EFBFBD>䣨<EFBFBD>룩
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <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>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
|
|
|
|
bool open(const char* addr, int conn_timeout, int rw_timeout);
|
|
|
|
|
|
2019-08-08 16:13:05 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>첽<EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
void close(void);
|
|
|
|
|
|
2019-08-13 18:29:40 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>ñ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>۳ɹ<EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܣ<EFBFBD><EFBFBD><EFBFBD>ʹ<EFBFBD>õ<EFBFBD> DNS <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @param out {string&} <EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-08-21 17:42:07 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾû<EFBFBD>п<EFBFBD><EFBFBD>õ<EFBFBD> DNS <EFBFBD><EFBFBD>ַ
|
2019-08-13 18:29:40 +08:00
|
|
|
|
*/
|
|
|
|
|
bool get_ns_addr(string& out);
|
|
|
|
|
|
2019-08-21 17:42:07 +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><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
* @param out {string&} <EFBFBD>洢<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĵ<EFBFBD>ַ
|
|
|
|
|
*/
|
|
|
|
|
bool get_server_addr(string& out);
|
|
|
|
|
|
2019-08-13 18:29:40 +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>
|
|
|
|
|
* @return {aio_socket_stream*}
|
|
|
|
|
*/
|
|
|
|
|
aio_socket_stream* get_conn(void) const
|
|
|
|
|
{
|
|
|
|
|
return conn_;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 23:43:04 +08:00
|
|
|
|
protected:
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +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> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> send_request <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD>÷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-06-05 17:36:47 +08:00
|
|
|
|
virtual bool on_connect(void) = 0;
|
|
|
|
|
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-08-21 17:42:07 +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> this->destroy() <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_ns_failed(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> this->destroy() <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual void on_connect_timeout(void) {}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-08-21 17:42:07 +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> this->destroy() <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual void on_connect_failed(void) {}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-08-08 16:13:05 +08:00
|
|
|
|
* @return {bool} <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><EFBFBD><EFBFBD><EFBFBD>ݣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӽ<EFBFBD><EFBFBD>ᱻ<EFBFBD>رգ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Żص<EFBFBD> on_disconnect() <EFBFBD>鷽<EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-08-08 16:13:05 +08:00
|
|
|
|
virtual bool on_read_timeout(void) { return false; }
|
2019-06-06 13:46:23 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-08-08 16:13:05 +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>
|
|
|
|
|
* destroy() <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual void on_disconnect(void) {};
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>˵<EFBFBD><EFBFBD><EFBFBD>Ӧͷʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
* @param header {const http_header&}
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-06-06 23:43:04 +08:00
|
|
|
|
virtual bool on_http_res_hdr(const http_header& header)
|
|
|
|
|
{
|
|
|
|
|
(void) header;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-06-06 13:46:23 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> WEB <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>
|
|
|
|
|
* @param data {char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>IJ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param dlen {size_t} <EFBFBD><EFBFBD><EFBFBD>ζ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> data <EFBFBD><EFBFBD><EFBFBD>ݵij<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-06-06 23:43:04 +08:00
|
|
|
|
virtual bool on_http_res_body(char* data, size_t dlen)
|
|
|
|
|
{
|
|
|
|
|
(void) data;
|
|
|
|
|
(void) dlen;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-06-06 13:46:23 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param success {bool} <EFBFBD>Ƿ<EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-06-06 23:43:04 +08:00
|
|
|
|
virtual bool on_http_res_finish(bool success)
|
|
|
|
|
{
|
|
|
|
|
(void) success;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-10 13:00:25 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD> websocket <EFBFBD><EFBFBD><EFBFBD>ֳɹ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} <EFBFBD><EFBFBD><EFBFBD><EFBFBD> false <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
|
|
|
|
*/
|
|
|
|
|
virtual bool on_ws_handshake(void)
|
|
|
|
|
{
|
2019-07-28 10:31:56 +08:00
|
|
|
|
// <20><>ʼ<EFBFBD>첽<EFBFBD><ECB2BD> websocket <20><><EFBFBD><EFBFBD>
|
2019-06-10 13:00:25 +08:00
|
|
|
|
this->ws_read_wait(0);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD> websocket <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʧ<EFBFBD>ܺ<EFBFBD><EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param status {int} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ص<EFBFBD> HTTP <EFBFBD><EFBFBD>Ӧ״̬<EFBFBD><EFBFBD>
|
2019-06-10 13:00:25 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual void on_ws_handshake_failed(int status) { (void) status; }
|
|
|
|
|
|
2019-06-09 22:46:07 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> text <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><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-09 22:46:07 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual bool on_ws_frame_text(void) { return true; }
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> binary <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><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-09 22:46:07 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual bool on_ws_frame_binary(void) { return true; }
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD>֡<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-09 22:46:07 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual void on_ws_frame_closed(void) {}
|
|
|
|
|
|
2019-06-06 23:43:04 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <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>
|
|
|
|
|
* @param data {char*} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݵ<EFBFBD>ַ
|
|
|
|
|
* @param dlen {size_t} <EFBFBD><EFBFBD><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><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 23:43:04 +08:00
|
|
|
|
*/
|
2019-06-09 22:46:07 +08:00
|
|
|
|
virtual bool on_ws_frame_data(char* data, size_t dlen)
|
2019-06-06 23:43:04 +08:00
|
|
|
|
{
|
|
|
|
|
(void) data;
|
|
|
|
|
(void) dlen;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
2019-06-09 22:46:07 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ֡<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><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD><EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-09 22:46:07 +08:00
|
|
|
|
*/
|
|
|
|
|
virtual bool on_ws_frame_finish(void) { return true; }
|
|
|
|
|
|
2019-08-09 18:05:51 +08:00
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>յ<EFBFBD> ping <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>
|
|
|
|
|
* data <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD>д<EFBFBD><EFBFBD> pong <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD><EFBFBD><EFBFBD> data <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> pong <EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
* @param data {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_ws_frame_ping(string& data)
|
|
|
|
|
{
|
|
|
|
|
(void) data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD>յ<EFBFBD> pong <EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>Ļص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param data {string&} <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
virtual void on_ws_frame_pong(string& data)
|
|
|
|
|
{
|
|
|
|
|
(void) data;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-10 13:00:25 +08:00
|
|
|
|
public:
|
2019-06-06 13:46:23 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD> WEB <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD>ڷ<EFBFBD><EFBFBD>ͺ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>Զ<EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><EFBFBD> HTTP <EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param body {const void*} HTTP <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>壬<EFBFBD><EFBFBD>Ϊ NULL ʱ<EFBFBD><EFBFBD><EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP GET <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} body <EFBFBD><EFBFBD> NULL ʱ<EFBFBD><EFBFBD>ʾ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 13:46:23 +08:00
|
|
|
|
*/
|
2019-06-05 17:36:47 +08:00
|
|
|
|
void send_request(const void* body, size_t len);
|
|
|
|
|
|
2019-06-06 23:43:04 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> WEBSOCKET <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-10-18 10:02:22 +08:00
|
|
|
|
* @param key {const void*} <EFBFBD><EFBFBD><EFBFBD>õ<EFBFBD> key ֵ
|
|
|
|
|
* @param len {size_t} key ֵ<EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>
|
2019-06-06 23:43:04 +08:00
|
|
|
|
*/
|
2019-08-09 18:05:51 +08:00
|
|
|
|
void ws_handshake(const void* key, size_t len);
|
2019-08-09 22:22:55 +08:00
|
|
|
|
void ws_handshake(const char* key = "123456789xxx");
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ws_handshake() ʱ<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> websocket <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͷ<EFBFBD><EFBFBD>Ϣ
|
|
|
|
|
*/
|
|
|
|
|
virtual void ws_handshake_before(http_header& reqhdr)
|
|
|
|
|
{
|
|
|
|
|
(void) reqhdr;
|
|
|
|
|
}
|
2019-06-06 23:43:04 +08:00
|
|
|
|
|
2019-06-10 13:00:25 +08:00
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD><EFBFBD>ʼ<EFBFBD>첽<EFBFBD><EFBFBD> websocket <EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-08-08 16:13:05 +08:00
|
|
|
|
* @param timeout {int} <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><EFBFBD>ʱʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ᱻ<EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD>
|
|
|
|
|
* ע<EFBFBD>⣺
|
|
|
|
|
* <EFBFBD><EFBFBD>ֵ<EFBFBD><EFBFBD> open() <EFBFBD>е<EFBFBD> rw_timeout <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬ<EFBFBD><EFBFBD>open() <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>еĶ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD> HTTP IO <EFBFBD><EFBFBD><EFBFBD>̼<EFBFBD> SSL <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> websocket <EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD>ǿ<EFBFBD><EFBFBD>ǵ<EFBFBD> websocket Ӧ<EFBFBD>úܶ<EFBFBD>
|
|
|
|
|
* <EFBFBD><EFBFBD><EFBFBD>dz<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӳ<EFBFBD><EFBFBD><EFBFBD>
|
2019-06-10 13:00:25 +08:00
|
|
|
|
*/
|
|
|
|
|
void ws_read_wait(int timeout = 0);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_TEXT <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|
|
|
|
* @param data {char*} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
2019-06-10 13:00:25 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool ws_send_text(char* data, size_t len);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_BINARY <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|
|
|
|
* @param data {void*} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
2019-06-10 13:00:25 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool ws_send_binary(void* data, size_t len);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_PING <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|
|
|
|
* @param data {void*} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
2019-06-10 13:00:25 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool ws_send_ping(void* data, size_t len);
|
|
|
|
|
|
|
|
|
|
/**
|
2019-07-28 10:31:56 +08:00
|
|
|
|
* <EFBFBD>첽<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD> FRAME_PONG <EFBFBD><EFBFBD><EFBFBD>͵<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>֡
|
|
|
|
|
* @param data {void*} <EFBFBD>ڲ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ԭ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len {size_t} data <EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
2019-06-10 13:00:25 +08:00
|
|
|
|
* @return {bool}
|
|
|
|
|
*/
|
|
|
|
|
bool ws_send_pong(void* data, size_t len);
|
|
|
|
|
|
2019-06-05 17:36:47 +08:00
|
|
|
|
protected:
|
2019-06-06 13:46:23 +08:00
|
|
|
|
// @override dummy
|
|
|
|
|
bool open_callback(void) { return true; }
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
|
|
|
|
// @override
|
|
|
|
|
bool timeout_callback(void);
|
|
|
|
|
|
|
|
|
|
// @override
|
|
|
|
|
void close_callback(void);
|
|
|
|
|
|
|
|
|
|
// @override
|
|
|
|
|
bool read_wakeup(void);
|
|
|
|
|
|
|
|
|
|
// @override
|
|
|
|
|
bool read_callback(char* data, int len);
|
|
|
|
|
|
|
|
|
|
protected:
|
2019-06-10 13:00:25 +08:00
|
|
|
|
unsigned status_;
|
2019-08-21 17:54:35 +08:00
|
|
|
|
int rw_timeout_;
|
|
|
|
|
int gzip_header_left_; // gzip <20><><EFBFBD><EFBFBD>ʱѹ<CAB1><D1B9>ͷ<EFBFBD><CDB7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
bool keep_alive_;
|
|
|
|
|
bool unzip_; // <20>Ƿ<EFBFBD><C7B7>Զ<EFBFBD><D4B6><EFBFBD>ѹ<EFBFBD><D1B9>Ӧ<EFBFBD><D3A6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
2019-06-05 17:36:47 +08:00
|
|
|
|
aio_handle& handle_;
|
2019-10-18 10:02:22 +08:00
|
|
|
|
polarssl_conf* ssl_conf_; // <20>ǿ<EFBFBD>ʱ<EFBFBD><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> SSL <20><><EFBFBD><EFBFBD>
|
|
|
|
|
bool ssl_enable_; // <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD> SSL <20><><EFBFBD><EFBFBD>
|
2019-06-05 17:36:47 +08:00
|
|
|
|
aio_socket_stream* conn_;
|
2019-06-06 23:43:04 +08:00
|
|
|
|
socket_stream* stream_;
|
2019-06-05 17:36:47 +08:00
|
|
|
|
http_header* header_;
|
|
|
|
|
HTTP_HDR_RES* hdr_res_;
|
|
|
|
|
HTTP_RES* http_res_;
|
2019-06-06 23:43:04 +08:00
|
|
|
|
websocket* ws_in_;
|
|
|
|
|
websocket* ws_out_;
|
2019-06-09 22:46:07 +08:00
|
|
|
|
string* buff_;
|
2019-07-28 10:31:56 +08:00
|
|
|
|
zlib_stream* zstream_; // <20><>ѹ<EFBFBD><D1B9><EFBFBD><EFBFBD>
|
2019-08-21 17:42:07 +08:00
|
|
|
|
struct sockaddr_storage ns_addr_; // <20><>ʹ<EFBFBD>õ<EFBFBD> DNS <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
|
|
|
|
struct sockaddr_storage serv_addr_; // <20><><EFBFBD><EFBFBD><EFBFBD>ӵ<EFBFBD>Ӧ<EFBFBD>÷<EFBFBD><C3B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ
|
2019-06-06 23:43:04 +08:00
|
|
|
|
|
2019-08-13 18:29:40 +08:00
|
|
|
|
bool handle_connect(const ACL_ASTREAM_CTX* ctx);
|
2019-06-10 13:00:25 +08:00
|
|
|
|
bool handle_ssl_handshake(void);
|
|
|
|
|
|
2019-06-10 16:34:23 +08:00
|
|
|
|
bool handle_res_hdr(int status);
|
|
|
|
|
|
2019-06-10 16:08:21 +08:00
|
|
|
|
bool handle_res_body(char* data, int dlen);
|
|
|
|
|
bool res_plain(char* data, int dlen);
|
|
|
|
|
bool res_unzip(zlib_stream& zstream, char* data, int dlen);
|
|
|
|
|
|
|
|
|
|
bool handle_res_body_finish(char* data, int dlen);
|
|
|
|
|
bool res_plain_finish(char* data, int dlen);
|
|
|
|
|
bool res_unzip_finish(zlib_stream& zstream, char* data, int dlen);
|
|
|
|
|
|
2019-06-06 23:43:04 +08:00
|
|
|
|
bool handle_websocket(void);
|
2019-06-09 22:46:07 +08:00
|
|
|
|
bool handle_ws_data(void);
|
|
|
|
|
bool handle_ws_ping(void);
|
|
|
|
|
bool handle_ws_pong(void);
|
|
|
|
|
bool handle_ws_other(void);
|
2019-06-05 17:36:47 +08:00
|
|
|
|
|
|
|
|
|
private:
|
2019-08-13 18:29:40 +08:00
|
|
|
|
static int connect_callback(const ACL_ASTREAM_CTX* ctx);
|
2019-06-05 17:36:47 +08:00
|
|
|
|
static int http_res_hdr_cllback(int status, void* ctx);
|
|
|
|
|
static int http_res_callback(int status, char* data, int dlen, void* ctx);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace acl
|