add WebSocketServlet by "fuwangqin" <niukey@qq.com>

This commit is contained in:
root 2017-05-31 14:43:18 +08:00
parent e5c39cb5c8
commit 0707afa35f
15 changed files with 354 additions and 285 deletions

View File

@ -1,6 +1,9 @@
修改历史列表:
-----------------------------------------------------------------------
479) 2017.5.31
479.1) featur: add WebSocketServlet by "fuwangqin" <niukey@qq.com>
478) 2017.5.27
478.1) bugfix: websocket::make_frame_header 中当 payload_len 为 126 时会遇到
内存跨界问题 --- found by "lindawei" <672496008@qq.com>

View File

@ -100,7 +100,7 @@ public:
* @return {bool} false
*
*/
bool doRun();
bool doRun(void);
/**
* HttpServlet HTTP doXXX

View File

@ -1,156 +1,165 @@
#pragma once
#include "stdlib/acl_mymalloc.h"
#include "HttpServlet.hpp"
#include "websocket.hpp"
#include "acl_cpp/acl_cpp_define.hpp"
#include "acl_cpp/http/HttpServlet.hpp"
namespace acl
{
class WebSocketServlet: public HttpServlet
class websocket;
class session;
class WebSocketServlet: public HttpServlet
{
public:
WebSocketServlet(void);
/**
*
* @param stream {socket_stream*} acl_master
* apache CGI
* NULL
* 便 acl_master
* @param session {session*} HttpServlet session
*/
WebSocketServlet(socket_stream* stream, session* session);
/**
*
* @param stream {socket_stream*} acl_master
* apache CGI
* NULL
* 便 acl_master
* @param memcache_addr {const char*}
*/
WebSocketServlet(socket_stream* stream,
const char* memcache_addr = "127.0.0.1:11211");
/**
* HttpServlet HTTP doXXX
* start start /
* .
* @return {bool} false
*
*/
virtual ~WebSocketServlet(void);
/**
* HttpServlet HTTP doXXX
* @param session {session&} session
* @param stream {socket_stream*} acl_master
* apache CGI
* NULL
* 便 acl_master
* @return {bool}
*/
virtual bool doRun(session& session, socket_stream* stream = NULL)
{
public:
WebSocketServlet();
/**
*
* @param stream {socket_stream*} acl_master
* apache CGI
* NULL
* 便 acl_master
* @param session {session*} HttpServlet session
*/
WebSocketServlet(socket_stream* stream, session* session);
return HttpServlet::doRun(session, stream);
}
/**
*
* @param stream {socket_stream*} acl_master
* apache CGI
* NULL
* 便 acl_master
* @param memcache_addr {const char*}
*/
WebSocketServlet(socket_stream* stream, const char* memcache_addr = "127.0.0.1:11211");
/**
* HttpServlet HTTP doXXX
* memcached session
* @param memcached_addr {const char*} memcached IP:PORT
* @param stream {socket_stream*}
* @return {bool}
*/
virtual bool doRun(const char* memcached_addr, socket_stream* stream)
{
return HttpServlet::doRun(memcached_addr, stream);
}
/**
* HttpServlet HTTP doXXX
* start start /
* .
* @return {bool} false
*
*/
virtual ~WebSocketServlet();
virtual bool doRun(void);
/**
* HttpServlet HTTP doXXX
* @param session {session&} session
* @param stream {socket_stream*} acl_master
* apache CGI
* NULL
* 便 acl_master
* @return {bool}
*/
virtual bool doRun(session& session, socket_stream* stream = NULL)
{
return HttpServlet::doRun(session, stream);
}
/**
* .
* @param rw_timeout {const char *}
* @return {bool} false. true
*/
/**
* HttpServlet HTTP doXXX
* memcached session
* @param memcached_addr {const char*} memcached IP:PORT
* @param stream {socket_stream*}
* @return {bool}
*/
virtual bool doRun(const char* memcached_addr, socket_stream* stream)
{
return HttpServlet::doRun(memcached_addr, stream);
}
bool send_binary(const char *buf, int len);
virtual bool doRun();
/**
* .
* @param rw_timeout {const char *}
* @return {bool} false. true
*/
/**
* .
* @param rw_timeout {const char *}
* @return {bool} false. true
*/
bool send_binary(const char *buf, int len);
bool send_text(const char *text);
/**
* pong .
* @param rw_timeout {const char *}
* @return {bool} false. true
*/
bool send_pong(const char *buffer = NULL);
/**
* .
* @param rw_timeout {const char *}
* @return {bool} false. true
*/
/**
* pong .
* @param rw_timeout {const char *}
* @return {bool} false. true
*/
bool send_ping(const char *buffer = NULL);
bool send_text(const char *text);
unsigned long long get_max_msg_len(void) const
{
return max_msg_len_;
}
/**
* websocket websocket连接.
* @param unsigned long long{len}
*/
void set_max_msg_len(unsigned long long len)
{
max_msg_len_ = len;
}
/**
* pong .
* @param rw_timeout {const char *}
* @return {bool} false. true
*/
bool send_pong(const char *buffer = NULL);
protected:
/**
* websocket
* @return {void}
*/
virtual void on_close(void);
/**
* pong .
* @param rw_timeout {const char *}
* @return {bool} false. true
*/
bool send_ping(const char *buffer = NULL);
/**
* websocket ping .
* @param {const char *} buf
* @param {int} len
* @return {bool} false
*/
virtual bool on_ping(const char *buf, unsigned long long len) = 0;
unsigned long long get_max_msg_len()
{
return max_msg_len_;
}
/**
* websocket pong .
* @param {const char *} buf
* @param {int} len
* @return {bool} false
*/
virtual bool on_pong(const char *buf, unsigned long long len) = 0;
/**
* websocket websocket连接.
* @param unsigned long long{len}
*/
void set_max_msg_len(unsigned long long len)
{
max_msg_len_ = len;
}
protected:
/**
* websocket ping .
* @param data{char *}
* @param len{unsigned long long}
* @param text{bool } true
* @return {bool} false
*/
virtual bool on_message(char *data, unsigned long long len, bool text) = 0;
/**
* websocket
* @return {void}
*/
virtual void on_close();
/**
* websocket ping .
* @param {const char *} buf
* @param {int} len
* @return {bool} false
*/
virtual bool on_ping(const char *buf, unsigned long long len) = 0;
/**
* websocket pong .
* @param {const char *} buf
* @param {int} len
* @return {bool} false
*/
virtual bool on_pong(const char *buf, unsigned long long len) = 0;
private:
// @override
bool doWebsocket(HttpServletRequest&, HttpServletResponse&);
/**
* websocket ping .
* @param data{char *}
* @param len{unsigned long long}
* @param text{bool } true
* @return {bool} false
*/
virtual bool on_message(char *data, unsigned long long len, bool text) = 0;
private:
private:
bool doWebsocket(HttpServletRequest&, HttpServletResponse&);
private:
unsigned long long max_msg_len_;
websocket *ws_;
unsigned long long max_msg_len_;
websocket *ws_;
char *recv_buffer_;
int write_pos_;
int opcode_;
};
char *recv_buffer_;
int write_pos_;
int opcode_;
};
}
} // namespace acl

View File

@ -89,6 +89,7 @@
#include "acl_cpp/http/http_request_pool.hpp"
#include "acl_cpp/http/http_request_manager.hpp"
#include "acl_cpp/http/websocket.hpp"
#include "acl_cpp/http/WebSocketServlet.hpp"
#include "acl_cpp/db/query.hpp"
#include "acl_cpp/db/mysql_conf.hpp"

View File

@ -672,6 +672,9 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
<File
RelativePath=".\src\http\websocket.cpp">
</File>
<File
RelativePath=".\src\http\WebSocketServlet.cpp">
</File>
</Filter>
<Filter
Name="hsocket"
@ -1265,6 +1268,9 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
<File
RelativePath=".\include\acl_cpp\http\websocket.hpp">
</File>
<File
RelativePath=".\include\acl_cpp\http\WebSocketServlet.hpp">
</File>
</Filter>
<Filter
Name="hsocket"

View File

@ -585,6 +585,10 @@
RelativePath=".\src\http\websocket.cpp"
>
</File>
<File
RelativePath=".\src\http\WebSocketServlet.cpp"
>
</File>
</Filter>
<Filter
Name="ipc"
@ -1431,6 +1435,10 @@
RelativePath=".\include\acl_cpp\http\websocket.hpp"
>
</File>
<File
RelativePath=".\include\acl_cpp\http\WebSocketServlet.hpp"
>
</File>
</Filter>
<Filter
Name="ipc"

View File

@ -255,6 +255,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
<ClCompile Include="src\http\http_service.cpp" />
<ClCompile Include="src\http\http_utils.cpp" />
<ClCompile Include="src\http\websocket.cpp" />
<ClCompile Include="src\http\WebSocketServlet.cpp" />
<ClCompile Include="src\ipc\ipc_client.cpp" />
<ClCompile Include="src\ipc\ipc_server.cpp" />
<ClCompile Include="src\ipc\ipc_service.cpp" />
@ -434,6 +435,7 @@ copy $(TargetName).pdb ..\dist\lib\win32\$(TargetName).pdb /Y
<ClInclude Include="include\acl_cpp\http\http_type.hpp" />
<ClInclude Include="include\acl_cpp\http\http_utils.hpp" />
<ClInclude Include="include\acl_cpp\http\websocket.hpp" />
<ClInclude Include="include\acl_cpp\http\WebSocketServlet.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_client.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_server.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_service.hpp" />

View File

@ -286,6 +286,9 @@
<ClCompile Include="src\http\websocket.cpp">
<Filter>src\http</Filter>
</ClCompile>
<ClCompile Include="src\http\WebSocketServlet.cpp">
<Filter>src\http</Filter>
</ClCompile>
<ClCompile Include="src\stdlib\sha1.cpp">
<Filter>src\stdlib</Filter>
</ClCompile>
@ -651,6 +654,9 @@
<ClInclude Include="include\acl_cpp\http\websocket.hpp">
<Filter>include\http</Filter>
</ClInclude>
<ClInclude Include="include\acl_cpp\http\WebSocketServlet.hpp">
<Filter>include\http</Filter>
</ClInclude>
<ClInclude Include="include\acl_cpp\http\HttpServlet.hpp">
<Filter>include\http</Filter>
</ClInclude>

View File

@ -449,6 +449,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
<ClCompile Include="src\http\http_service.cpp" />
<ClCompile Include="src\http\http_utils.cpp" />
<ClCompile Include="src\http\websocket.cpp" />
<ClCompile Include="src\http\WebSocketServlet.cpp" />
<ClCompile Include="src\ipc\ipc_client.cpp" />
<ClCompile Include="src\ipc\ipc_server.cpp" />
<ClCompile Include="src\ipc\ipc_service.cpp" />
@ -628,6 +629,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
<ClInclude Include="include\acl_cpp\http\http_type.hpp" />
<ClInclude Include="include\acl_cpp\http\http_utils.hpp" />
<ClInclude Include="include\acl_cpp\http\websocket.hpp" />
<ClInclude Include="include\acl_cpp\http\WebSocketServlet.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_client.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_server.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_service.hpp" />

View File

@ -283,6 +283,9 @@
<ClCompile Include="src\http\websocket.cpp">
<Filter>Source Files\http</Filter>
</ClCompile>
<ClCompile Include="src\http\WebSocketServlet.cpp">
<Filter>Source Files\http</Filter>
</ClCompile>
<ClCompile Include="src\stdlib\sha1.cpp">
<Filter>Source Files\stdlib</Filter>
</ClCompile>
@ -648,6 +651,9 @@
<ClInclude Include="include\acl_cpp\http\websocket.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>
<ClInclude Include="include\acl_cpp\http\WebSocketServlet.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>
<ClInclude Include="include\acl_cpp\http\HttpServlet.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>

View File

@ -449,6 +449,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
<ClCompile Include="src\http\http_service.cpp" />
<ClCompile Include="src\http\http_utils.cpp" />
<ClCompile Include="src\http\websocket.cpp" />
<ClCompile Include="src\http\WebSocketServlet.cpp" />
<ClCompile Include="src\ipc\ipc_client.cpp" />
<ClCompile Include="src\ipc\ipc_server.cpp" />
<ClCompile Include="src\ipc\ipc_service.cpp" />
@ -628,6 +629,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
<ClInclude Include="include\acl_cpp\http\http_type.hpp" />
<ClInclude Include="include\acl_cpp\http\http_utils.hpp" />
<ClInclude Include="include\acl_cpp\http\websocket.hpp" />
<ClInclude Include="include\acl_cpp\http\WebSocketServlet.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_client.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_server.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_service.hpp" />

View File

@ -283,6 +283,9 @@
<ClCompile Include="src\http\websocket.cpp">
<Filter>Source Files\http</Filter>
</ClCompile>
<ClCompile Include="src\http\WebSocketServlet.cpp">
<Filter>Source Files\http</Filter>
</ClCompile>
<ClCompile Include="src\stdlib\sha1.cpp">
<Filter>Source Files\stdlib</Filter>
</ClCompile>
@ -648,6 +651,9 @@
<ClInclude Include="include\acl_cpp\http\websocket.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>
<ClInclude Include="include\acl_cpp\http\WebSocketServlet.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>
<ClInclude Include="include\acl_cpp\http\HttpServlet.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>

View File

@ -449,6 +449,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
<ClCompile Include="src\http\http_service.cpp" />
<ClCompile Include="src\http\http_utils.cpp" />
<ClCompile Include="src\http\websocket.cpp" />
<ClCompile Include="src\http\WebSocketServlet.cpp" />
<ClCompile Include="src\ipc\ipc_client.cpp" />
<ClCompile Include="src\ipc\ipc_server.cpp" />
<ClCompile Include="src\ipc\ipc_service.cpp" />
@ -628,6 +629,7 @@ copy $(TargetName).pdb ..\dist\lib\win64\$(TargetName).pdb /Y
<ClInclude Include="include\acl_cpp\http\http_type.hpp" />
<ClInclude Include="include\acl_cpp\http\http_utils.hpp" />
<ClInclude Include="include\acl_cpp\http\websocket.hpp" />
<ClInclude Include="include\acl_cpp\http\WebSocketServlet.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_client.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_server.hpp" />
<ClInclude Include="include\acl_cpp\ipc\ipc_service.hpp" />

View File

@ -283,6 +283,9 @@
<ClCompile Include="src\http\websocket.cpp">
<Filter>Source Files\http</Filter>
</ClCompile>
<ClCompile Include="src\http\WebSocketServlet.cpp">
<Filter>Source Files\http</Filter>
</ClCompile>
<ClCompile Include="src\stdlib\sha1.cpp">
<Filter>Source Files\stdlib</Filter>
</ClCompile>
@ -648,6 +651,9 @@
<ClInclude Include="include\acl_cpp\http\websocket.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>
<ClInclude Include="include\acl_cpp\http\WebSocketServlet.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>
<ClInclude Include="include\acl_cpp\http\HttpServlet.hpp">
<Filter>Header Files\http</Filter>
</ClInclude>

View File

@ -1,181 +1,191 @@
/**
* Copyright (C) 2015-2018
* All rights reserved.
*
* AUTHOR(S)
* Fu wangqin
* E-mail: "fuwangqin" <niukey@qq.com>
*
* VERSION
* Wed 31 May 2017 02:37:14 PM CST
*/
#include "acl_stdafx.hpp"
#ifndef ACL_PREPARE_COMPILE
#include "acl_cpp/stdlib/log.hpp"
#include "acl_cpp/stream/socket_stream.hpp"
#include "acl_cpp/session/session.hpp"
#include "acl_cpp/http/websocket.hpp"
#include "acl_cpp/http/WebSocketServlet.hpp"
#endif
namespace acl
{
WebSocketServlet::WebSocketServlet(socket_stream* stream, session* session)
:HttpServlet(stream, session),
max_msg_len_(100 * 1024*1024),
ws_(NULL)
{
}
WebSocketServlet::WebSocketServlet(
socket_stream* stream,
const char* memcache_addr )
:HttpServlet(stream, memcache_addr),
max_msg_len_(100 * 1024 * 1024),
ws_(NULL)
{
}
WebSocketServlet::WebSocketServlet()
:max_msg_len_(100 * 1024 * 1024),
ws_(NULL)
{
}
WebSocketServlet::~WebSocketServlet()
WebSocketServlet::WebSocketServlet(socket_stream* stream, session* session)
: HttpServlet(stream, session)
, max_msg_len_(100 * 1024*1024)
, ws_(NULL)
{
}
WebSocketServlet::WebSocketServlet(socket_stream* stream,
const char* memcache_addr)
:HttpServlet(stream, memcache_addr)
, max_msg_len_(100 * 1024 * 1024)
, ws_(NULL)
{
}
WebSocketServlet::WebSocketServlet(void)
:max_msg_len_(100 * 1024 * 1024),
ws_(NULL)
{
}
WebSocketServlet::~WebSocketServlet(void)
{
if (ws_)
delete ws_;
ws_ = NULL;
}
bool WebSocketServlet::doRun(void)
{
if (!ws_)
{
bool ret = HttpServlet::doRun();
//websocket upgrade ok.
//maybe http without keepalive ,
//return false,framework will close this connection.
if (ws_)
delete ws_;
ws_ = NULL;
}
bool WebSocketServlet::doRun()
{
if (!ws_)
{
bool ret = HttpServlet::doRun();
//websocket upgrade ok.
//maybe http without keepalive ,
//return false,framework will close this connection.
if (ws_)
return true;
return ret;
}
if (ws_->read_frame_head() == false)
return false;
unsigned long long len = ws_->get_frame_payload_len();
if (len > max_msg_len_)
{
logger_error("payload too large error: %llu", len);
return false;
}
if (len > 0)
{
if (!recv_buffer_)
{
recv_buffer_ = (char*)acl_mymalloc((size_t)len + 1);
}
else
{
//frame not finish.
recv_buffer_ = (char*)acl_myrealloc(recv_buffer_, write_pos_ + (size_t)len + 1);
}
if (ws_->read_frame_data(recv_buffer_+ write_pos_, len) < 0)
{
write_pos_ = 0;
acl_myfree(recv_buffer_);
recv_buffer_ = NULL;
return false;
}
write_pos_ += len;
recv_buffer_[write_pos_] = '\0';
}
int opcode = ws_->get_frame_opcode();
bool ret = false;
if (ws_->get_frame_fin() == false)
{
//safe opcode.
if(opcode != FRAME_CONTINUATION)
opcode_ = opcode;
return true;
}
//frame is finish callback frame.
if (opcode == FRAME_CONTINUATION)
{
opcode = opcode_;
}
switch (opcode)
{
case FRAME_PING:
ret = on_ping(recv_buffer_, write_pos_);
break;
case FRAME_PONG:
ret = on_pong(recv_buffer_, write_pos_);
break;
case FRAME_CLOSE:
on_close();
break;
case FRAME_TEXT:
case FRAME_BINARY:
{
ret = on_message(recv_buffer_, write_pos_,
ws_->get_frame_opcode() == FRAME_TEXT);
break;
}
default:
logger_error("unknown websocket Frame opcode error: %d",
ws_->get_frame_opcode());
}
if (recv_buffer_)
{
acl_myfree(recv_buffer_);
recv_buffer_ = NULL;
write_pos_ = 0;
}
return ret;
}
if (ws_->read_frame_head() == false)
return false;
bool WebSocketServlet::send_binary(const char *recv_buffer_, int len)
unsigned long long len = ws_->get_frame_payload_len();
if (len > max_msg_len_)
{
ws_->set_frame_opcode(FRAME_BINARY);
ws_->set_frame_fin(true);
ws_->set_frame_payload_len(len);
return ws_->send_frame_data(recv_buffer_, len);
logger_error("payload too large error: %llu", len);
return false;
}
bool WebSocketServlet::send_text(const char *recv_buffer_fer)
if (len > 0)
{
ws_->set_frame_opcode(FRAME_TEXT);
ws_->set_frame_fin(true);
ws_->set_frame_payload_len(strlen(recv_buffer_fer));
return ws_->send_frame_data(recv_buffer_fer, strlen(recv_buffer_fer));
if (!recv_buffer_)
recv_buffer_ = (char*) acl_mymalloc((size_t)len + 1);
else
//frame not finish.
recv_buffer_ = (char*) acl_myrealloc(recv_buffer_,
write_pos_ + (size_t)len + 1);
if (ws_->read_frame_data(recv_buffer_+ write_pos_, len) < 0)
{
write_pos_ = 0;
acl_myfree(recv_buffer_);
recv_buffer_ = NULL;
return false;
}
write_pos_ += len;
recv_buffer_[write_pos_] = '\0';
}
bool WebSocketServlet::send_pong(const char *text)
{
size_t len = !text ? 0 : strlen(text);
ws_->set_frame_opcode(FRAME_PONG);
ws_->set_frame_fin(true);
ws_->set_frame_payload_len(len);
return ws_->send_frame_data(text, len);
}
int opcode = ws_->get_frame_opcode();
bool ret = false;
bool WebSocketServlet::send_ping(const char *text)
if (ws_->get_frame_fin() == false)
{
size_t len = !text ? 0 : strlen(text);
ws_->set_frame_opcode(FRAME_PING);
ws_->set_frame_fin(true);
ws_->set_frame_payload_len(len);
return ws_->send_frame_data(text, len);
}
bool WebSocketServlet::doWebsocket(HttpServletRequest&, HttpServletResponse&)
{
acl_assert(!ws_);
ws_ = new websocket(*getStream());
//safe opcode.
if(opcode != FRAME_CONTINUATION)
opcode_ = opcode;
return true;
}
void WebSocketServlet::on_close()
//frame is finish callback frame.
if (opcode == FRAME_CONTINUATION)
opcode = opcode_;
switch (opcode)
{
case FRAME_PING:
ret = on_ping(recv_buffer_, write_pos_);
break;
case FRAME_PONG:
ret = on_pong(recv_buffer_, write_pos_);
break;
case FRAME_CLOSE:
on_close();
break;
case FRAME_TEXT:
case FRAME_BINARY:
ret = on_message(recv_buffer_, write_pos_,
ws_->get_frame_opcode() == FRAME_TEXT);
break;
default:
logger_error("unknown websocket Frame opcode error: %d",
ws_->get_frame_opcode());
break;
}
}
if (recv_buffer_)
{
acl_myfree(recv_buffer_);
recv_buffer_ = NULL;
write_pos_ = 0;
}
return ret;
}
bool WebSocketServlet::send_binary(const char *buffer, int len)
{
ws_->set_frame_opcode(FRAME_BINARY);
ws_->set_frame_fin(true);
ws_->set_frame_payload_len(len);
return ws_->send_frame_data(buffer, len);
}
bool WebSocketServlet::send_text(const char *buffer)
{
ws_->set_frame_opcode(FRAME_TEXT);
ws_->set_frame_fin(true);
ws_->set_frame_payload_len(strlen(buffer));
return ws_->send_frame_data(buffer, strlen(buffer));
}
bool WebSocketServlet::send_pong(const char *text)
{
size_t len = !text ? 0 : strlen(text);
ws_->set_frame_opcode(FRAME_PONG);
ws_->set_frame_fin(true);
ws_->set_frame_payload_len(len);
return ws_->send_frame_data(text, len);
}
bool WebSocketServlet::send_ping(const char *text)
{
size_t len = !text ? 0 : strlen(text);
ws_->set_frame_opcode(FRAME_PING);
ws_->set_frame_fin(true);
ws_->set_frame_payload_len(len);
return ws_->send_frame_data(text, len);
}
bool WebSocketServlet::doWebsocket(HttpServletRequest&, HttpServletResponse&)
{
acl_assert(!ws_);
ws_ = new websocket(*getStream());
return true;
}
void WebSocketServlet::on_close(void)
{
}
} // namespace acl