Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
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
Operations
Operations
Metrics
Environments
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 Framework
Commits
1f04207b
Commit
1f04207b
authored
Apr 01, 2023
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow to start multiple switch_protocol routes
parent
2c9adcaf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
8 deletions
+19
-8
libcaf_net/caf/net/web_socket/switch_protocol.hpp
libcaf_net/caf/net/web_socket/switch_protocol.hpp
+19
-8
No files found.
libcaf_net/caf/net/web_socket/switch_protocol.hpp
View file @
1f04207b
...
...
@@ -61,12 +61,18 @@ private:
};
template
<
class
OnRequest
,
class
OnStart
>
struct
ws_switch_protocol_state
{
ws_switch_protocol_state
(
OnRequest
on_request_fn
,
OnStart
on_start_fn
)
:
on_request
(
std
::
move
(
on_request_fn
)),
on_start
(
std
::
move
(
on_start_fn
))
{
struct
ws_switch_protocol_state
:
public
ref_counted
{
template
<
class
OnStartInit
>
ws_switch_protocol_state
(
OnRequest
on_request_fn
,
OnStartInit
&&
on_start_fn
)
:
on_request
(
std
::
move
(
on_request_fn
)),
on_start
(
std
::
forward
<
OnStartInit
>
(
on_start_fn
))
{
// nop
}
ws_switch_protocol_state
*
copy
()
const
{
return
new
ws_switch_protocol_state
{
on_request
,
on_start
};
}
OnRequest
on_request
;
std
::
optional
<
OnStart
>
on_start
;
};
...
...
@@ -83,7 +89,7 @@ public:
using
shared_producer_type
=
std
::
shared_ptr
<
producer_type
>
;
explicit
ws_switch_protocol
(
std
::
shared
_ptr
<
State
>
state
)
explicit
ws_switch_protocol
(
intrusive
_ptr
<
State
>
state
)
:
state_
(
std
::
move
(
state
))
{
// nop
}
...
...
@@ -142,7 +148,12 @@ public:
}
void
init
()
{
if
(
auto
&
on_start
=
state_
->
on_start
;
on_start
)
{
// Once we call init(), the route becomes active. Before, this step, we want
// to allow the route to copy this instance freely and have multiple
// "potential" routes. But once the server actually starts, we detach this
// instance from the others and it becomes a "live" object.
auto
&
st
=
state_
.
unshared
();
if
(
auto
&
on_start
=
st
.
on_start
;
on_start
)
{
auto
[
pull
,
push
]
=
async
::
make_spsc_buffer_resource
<
accept_event
>
();
using
producer_t
=
async
::
blocking_producer
<
accept_event
>
;
producer_
=
std
::
make_shared
<
producer_t
>
(
producer_t
{
push
.
try_open
()});
...
...
@@ -152,7 +163,7 @@ public:
}
private:
std
::
shared
_ptr
<
State
>
state_
;
intrusive_cow
_ptr
<
State
>
state_
;
shared_producer_type
producer_
;
};
...
...
@@ -184,7 +195,7 @@ private:
using
namespace
detail
;
using
state_t
=
ws_switch_protocol_state
<
OnRequest
,
OnStart
>
;
using
impl_t
=
ws_switch_protocol
<
Trait
,
state_t
,
type_list
<
Out
...
>
,
Ts
...
>
;
auto
state
=
std
::
make_shar
ed
<
state_t
>
(
std
::
move
(
on_request_
),
auto
state
=
make_count
ed
<
state_t
>
(
std
::
move
(
on_request_
),
std
::
move
(
on_start
));
static_assert
(
http_route_has_init_v
<
impl_t
>
);
return
impl_t
{
std
::
move
(
state
)};
...
...
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