Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
actor-incubator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
actor-incubator
Commits
ebebef9f
Commit
ebebef9f
authored
Dec 23, 2021
by
chenhuaqing
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement close for mixed_message_oriented_layer
parent
e41eaa05
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
4 deletions
+37
-4
examples/net/web-socket-feed.cpp
examples/net/web-socket-feed.cpp
+9
-4
libcaf_net/caf/net/mixed_message_oriented_layer_ptr.hpp
libcaf_net/caf/net/mixed_message_oriented_layer_ptr.hpp
+5
-0
libcaf_net/caf/net/web_socket/framing.hpp
libcaf_net/caf/net/web_socket/framing.hpp
+23
-0
No files found.
examples/net/web-socket-feed.cpp
View file @
ebebef9f
...
@@ -236,18 +236,23 @@ public:
...
@@ -236,18 +236,23 @@ public:
}
}
template
<
class
LowerLayerPtr
>
template
<
class
LowerLayerPtr
>
void
abort
(
LowerLayerPtr
,
const
caf
::
error
&
)
{
void
abort
(
LowerLayerPtr
down
,
const
caf
::
error
&
)
{
// nop
std
::
cout
<<
"app abort "
<<
"
\n
"
;
}
}
template
<
class
LowerLayerPtr
>
template
<
class
LowerLayerPtr
>
ptrdiff_t
consume_text
(
LowerLayerPtr
,
caf
::
string_view
text
)
{
ptrdiff_t
consume_text
(
LowerLayerPtr
down
,
caf
::
string_view
text
)
{
// Discard any input.
// Discard any input.
std
::
cout
<<
down
->
handle
().
id
<<
" receive text: "
<<
text
<<
"
\n
"
;
if
(
"close"
==
text
)
{
down
->
close
(
1000
,
"Bye"
);
}
return
static_cast
<
ptrdiff_t
>
(
text
.
size
());
return
static_cast
<
ptrdiff_t
>
(
text
.
size
());
}
}
template
<
class
LowerLayerPtr
>
template
<
class
LowerLayerPtr
>
ptrdiff_t
consume_binary
(
LowerLayerPtr
,
caf
::
byte_span
bytes
)
{
ptrdiff_t
consume_binary
(
LowerLayerPtr
down
,
caf
::
byte_span
bytes
)
{
// Discard any input.
// Discard any input.
return
static_cast
<
ptrdiff_t
>
(
bytes
.
size
());
return
static_cast
<
ptrdiff_t
>
(
bytes
.
size
());
}
}
...
...
libcaf_net/caf/net/mixed_message_oriented_layer_ptr.hpp
View file @
ebebef9f
...
@@ -54,6 +54,11 @@ public:
...
@@ -54,6 +54,11 @@ public:
lptr_
->
end_text_message
(
llptr_
);
lptr_
->
end_text_message
(
llptr_
);
}
}
void
close
(
uint16_t
code
,
string_view
reason
)
{
lptr_
->
close
(
llptr_
,
code
,
reason
);
abort_reason
();
}
void
abort_reason
(
error
reason
)
{
void
abort_reason
(
error
reason
)
{
return
lptr_
->
abort_reason
(
llptr_
,
std
::
move
(
reason
));
return
lptr_
->
abort_reason
(
llptr_
,
std
::
move
(
reason
));
}
}
...
...
libcaf_net/caf/net/web_socket/framing.hpp
View file @
ebebef9f
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include "caf/byte.hpp"
#include "caf/byte.hpp"
#include "caf/byte_span.hpp"
#include "caf/byte_span.hpp"
#include "caf/detail/network_order.hpp"
#include "caf/detail/rfc6455.hpp"
#include "caf/detail/rfc6455.hpp"
#include "caf/net/mixed_message_oriented_layer_ptr.hpp"
#include "caf/net/mixed_message_oriented_layer_ptr.hpp"
#include "caf/sec.hpp"
#include "caf/sec.hpp"
...
@@ -116,6 +117,11 @@ public:
...
@@ -116,6 +117,11 @@ public:
ship_frame
(
down
,
text_buf_
);
ship_frame
(
down
,
text_buf_
);
}
}
template
<
class
LowerLayerPtr
>
void
close
(
LowerLayerPtr
down
,
int
code
,
string_view
reason
)
{
ship_close
(
down
,
code
,
reason
);
}
template
<
class
LowerLayerPtr
>
template
<
class
LowerLayerPtr
>
static
void
abort_reason
(
LowerLayerPtr
parent
,
error
reason
)
{
static
void
abort_reason
(
LowerLayerPtr
parent
,
error
reason
)
{
return
parent
->
abort_reason
(
std
::
move
(
reason
));
return
parent
->
abort_reason
(
std
::
move
(
reason
));
...
@@ -278,6 +284,23 @@ private:
...
@@ -278,6 +284,23 @@ private:
down
->
end_output
();
down
->
end_output
();
}
}
template
<
class
LowerLayerPtr
>
void
ship_close
(
LowerLayerPtr
down
,
uint16_t
code
,
string_view
reason
)
{
byte_buffer
payload
{
sizeof
(
code
)
+
reason
.
size
()};
auto
status_code
=
caf
::
detail
::
to_network_order
(
code
);
memcpy
(
payload
.
data
(),
&
status_code
,
sizeof
(
status_code
));
memcpy
(
payload
.
data
()
+
sizeof
(
status_code
),
reason
.
data
(),
reason
.
size
());
uint32_t
mask_key
=
0
;
if
(
mask_outgoing_frames
)
{
mask_key
=
static_cast
<
uint32_t
>
(
rng_
());
detail
::
rfc6455
::
mask_data
(
mask_key
,
payload
);
}
down
->
begin_output
();
detail
::
rfc6455
::
assemble_frame
(
detail
::
rfc6455
::
connection_close
,
mask_key
,
payload
,
down
->
output_buffer
());
down
->
end_output
();
}
template
<
class
LowerLayerPtr
,
class
T
>
template
<
class
LowerLayerPtr
,
class
T
>
void
ship_frame
(
LowerLayerPtr
down
,
std
::
vector
<
T
>&
buf
)
{
void
ship_frame
(
LowerLayerPtr
down
,
std
::
vector
<
T
>&
buf
)
{
uint32_t
mask_key
=
0
;
uint32_t
mask_key
=
0
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment