2017-05-20 11:37:15 +08:00
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
class WebsocketServlet_impl : public acl::WebSocketServlet
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
WebsocketServlet_impl(acl::redis_client_cluster& cluster, size_t max_conns);
|
2018-10-20 00:30:02 +08:00
|
|
|
|
~WebsocketServlet_impl(void);
|
2017-05-20 11:37:15 +08:00
|
|
|
|
|
2018-10-20 00:30:02 +08:00
|
|
|
|
acl::session& get_session(void) const
|
2017-05-20 11:37:15 +08:00
|
|
|
|
{
|
|
|
|
|
return *session_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
2018-10-20 00:30:02 +08:00
|
|
|
|
// @override
|
|
|
|
|
bool doUnknown(acl::HttpServletRequest&, acl::HttpServletResponse&);
|
|
|
|
|
// @override
|
|
|
|
|
bool doGet(acl::HttpServletRequest&, acl::HttpServletResponse&);
|
|
|
|
|
// @override
|
|
|
|
|
bool doPost(acl::HttpServletRequest&, acl::HttpServletResponse&);
|
2017-05-20 11:37:15 +08:00
|
|
|
|
|
|
|
|
|
//for websocket
|
|
|
|
|
/**
|
2018-10-20 00:30:02 +08:00
|
|
|
|
* @override
|
|
|
|
|
* websocket <EFBFBD>ر<EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD>ص<EFBFBD>
|
|
|
|
|
* @return {void}
|
|
|
|
|
*/
|
|
|
|
|
void onClose(void) {}
|
2017-05-20 11:37:15 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2018-10-20 00:30:02 +08:00
|
|
|
|
* @override
|
|
|
|
|
* websocket ping <EFBFBD><EFBFBD>Ϣ<EFBFBD>ص<EFBFBD>.
|
|
|
|
|
* @param {const char *} buf <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param {int} len <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} false <EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
bool onPing(const char *buf, unsigned long long len);
|
|
|
|
|
|
2017-05-20 11:37:15 +08:00
|
|
|
|
/**
|
2018-10-20 00:30:02 +08:00
|
|
|
|
* @override
|
|
|
|
|
* websocket pong <EFBFBD><EFBFBD>Ϣ<EFBFBD>ص<EFBFBD>.
|
|
|
|
|
* @param {const char *} buf <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param {int} len <EFBFBD><EFBFBD>Ϣ<EFBFBD><EFBFBD><EFBFBD>ݳ<EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @return {bool} false <EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
bool onPong(const char *buf, unsigned long long len);
|
2017-05-20 11:37:15 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2018-10-20 00:30:02 +08:00
|
|
|
|
* @override
|
|
|
|
|
* websocket ping <EFBFBD><EFBFBD>Ϣ<EFBFBD>ص<EFBFBD>.
|
|
|
|
|
* @param data{char *} <EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
* @param len{unsigned long long}<EFBFBD>ص<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݻ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD>
|
|
|
|
|
* @param text{bool } true Ϊ<EFBFBD>ı<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݡ<EFBFBD>
|
|
|
|
|
* @return {bool} false <EFBFBD>Ͽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ӡ<EFBFBD>
|
|
|
|
|
*/
|
|
|
|
|
bool onMessage(char *data, unsigned long long len, bool text);
|
2017-05-20 11:37:15 +08:00
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
acl::session* session_;
|
|
|
|
|
int step_;
|
|
|
|
|
acl::string filename_;
|
|
|
|
|
acl::ofstream *file_;
|
|
|
|
|
int filesize_;
|
|
|
|
|
int current_filesize_;
|
|
|
|
|
};
|