Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
NetWork
Simple WebSocket Server
提交
6eef6805
S
Simple WebSocket Server
项目概览
NetWork
/
Simple WebSocket Server
通知
4
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
Simple WebSocket Server
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
6eef6805
编写于
1月 07, 2016
作者:
E
eidheim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Improved fix to #26, connection object is now kept alive for sure till send_from_queue is finished.
上级
c5d11030
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
12 addition
and
16 deletion
+12
-16
server_ws.hpp
server_ws.hpp
+12
-16
未找到文件。
server_ws.hpp
浏览文件 @
6eef6805
...
...
@@ -54,10 +54,9 @@ namespace SimpleWeb {
class
SendData
{
public:
SendData
(
std
::
shared_ptr
<
Connection
>
connection
,
std
::
shared_ptr
<
SendStream
>
header_stream
,
std
::
shared_ptr
<
SendStream
>
message_stream
,
SendData
(
std
::
shared_ptr
<
SendStream
>
header_stream
,
std
::
shared_ptr
<
SendStream
>
message_stream
,
const
std
::
function
<
void
(
const
boost
::
system
::
error_code
)
>
&
callback
)
:
connection
(
connection
),
header_stream
(
header_stream
),
message_stream
(
message_stream
),
callback
(
callback
)
{}
std
::
shared_ptr
<
Connection
>
connection
;
//Added to keep the connection object alive
header_stream
(
header_stream
),
message_stream
(
message_stream
),
callback
(
callback
)
{}
std
::
shared_ptr
<
SendStream
>
header_stream
;
std
::
shared_ptr
<
SendStream
>
message_stream
;
std
::
function
<
void
(
const
boost
::
system
::
error_code
)
>
callback
;
...
...
@@ -70,13 +69,13 @@ namespace SimpleWeb {
std
::
list
<
SendData
>
send_queue
;
void
send_from_queue
()
{
strand
.
post
([
this
]()
{
void
send_from_queue
(
std
::
shared_ptr
<
Connection
>
connection
)
{
strand
.
post
([
this
,
connection
]()
{
boost
::
asio
::
async_write
(
*
socket
,
send_queue
.
begin
()
->
header_stream
->
streambuf
,
strand
.
wrap
([
this
](
const
boost
::
system
::
error_code
&
ec
,
size_t
/*bytes_transferred*/
)
{
strand
.
wrap
([
this
,
connection
](
const
boost
::
system
::
error_code
&
ec
,
size_t
/*bytes_transferred*/
)
{
if
(
!
ec
)
{
boost
::
asio
::
async_write
(
*
socket
,
send_queue
.
begin
()
->
message_stream
->
streambuf
,
strand
.
wrap
([
this
]
strand
.
wrap
([
this
,
connection
]
(
const
boost
::
system
::
error_code
&
ec
,
size_t
/*bytes_transferred*/
)
{
auto
send_queued
=
send_queue
.
begin
();
if
(
send_queued
->
callback
)
...
...
@@ -84,20 +83,17 @@ namespace SimpleWeb {
if
(
!
ec
)
{
send_queue
.
erase
(
send_queued
);
if
(
send_queue
.
size
()
>
0
)
send_from_queue
();
}
else
{
for
(
auto
it
=
send_queue
.
begin
();
it
!=
send_queue
.
end
();)
it
=
send_queue
.
erase
(
it
);
send_from_queue
(
connection
);
}
else
send_queue
.
clear
();
}));
}
else
{
auto
send_queued
=
send_queue
.
begin
();
if
(
send_queued
->
callback
)
send_queued
->
callback
(
ec
);
for
(
auto
it
=
send_queue
.
begin
();
it
!=
send_queue
.
end
();)
it
=
send_queue
.
erase
(
it
);
send_queue
.
clear
();
}
}));
});
...
...
@@ -258,9 +254,9 @@ namespace SimpleWeb {
header_stream
->
put
(
static_cast
<
unsigned
char
>
(
length
));
connection
->
strand
.
post
([
this
,
connection
,
header_stream
,
message_stream
,
callback
]()
{
connection
->
send_queue
.
emplace_back
(
connection
,
header_stream
,
message_stream
,
callback
);
connection
->
send_queue
.
emplace_back
(
header_stream
,
message_stream
,
callback
);
if
(
connection
->
send_queue
.
size
()
==
1
)
connection
->
send_from_queue
();
connection
->
send_from_queue
(
connection
);
});
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录