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
070b3ae1
Commit
070b3ae1
authored
Apr 22, 2022
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add missing comments
parent
d9a8f6d3
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
2 deletions
+5
-2
examples/web_socket/echo.cpp
examples/web_socket/echo.cpp
+5
-2
No files found.
examples/web_socket/echo.cpp
View file @
070b3ae1
// Simple WebSocket server that sends everything it receives back to the sender.
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/caf_main.hpp"
...
...
@@ -61,7 +63,7 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
.
subscribe
(
push
);
});
});
//
Handler for
//
Callback for incoming WebSocket requests.
auto
on_request
=
[](
const
caf
::
settings
&
hdr
,
auto
&
req
)
{
// The hdr parameter is a dictionary with fields from the WebSocket
// handshake such as the path.
...
...
@@ -75,11 +77,12 @@ int caf_main(caf::actor_system& sys, const config& cfg) {
}
else
{
// Calling `reject` aborts the connection with HTTP status code 400 (Bad
// Request). The error gets converted to a string and send to the client
// to give some indication to the client why the request was re
fus
ed.
// to give some indication to the client why the request was re
ject
ed.
auto
err
=
caf
::
make_error
(
caf
::
sec
::
invalid_argument
,
"unrecognized path, try '/'"
);
req
.
reject
(
std
::
move
(
err
));
}
// Note: calling neither accept nor reject also rejects the connection.
};
// Set everything in motion.
cn
::
web_socket
::
accept
(
sys
,
fd
,
std
::
move
(
sres
),
on_request
);
...
...
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