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
9912b5b4
Commit
9912b5b4
authored
Aug 07, 2023
by
Samir Halilcevic
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initial autobahn echo server
parent
29879209
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
103 additions
and
0 deletions
+103
-0
libcaf_net/tests/drivers/autobahn.cpp
libcaf_net/tests/drivers/autobahn.cpp
+103
-0
No files found.
libcaf_net/tests/drivers/autobahn.cpp
0 → 100644
View file @
9912b5b4
// Simple WebSocket server that sends everything it receives back to the sender.
#include "caf/net/middleman.hpp"
#include "caf/net/octet_stream/transport.hpp"
#include "caf/net/web_socket/acceptor.hpp"
#include "caf/net/web_socket/framing.hpp"
#include "caf/net/web_socket/lower_layer.hpp"
#include "caf/net/web_socket/upper_layer.hpp"
#include "caf/actor_system.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/caf_main.hpp"
#include <iostream>
#include <utility>
// -- constants ----------------------------------------------------------------
static
constexpr
uint16_t
default_port
=
8080
;
static
constexpr
size_t
default_max_connections
=
128
;
// -- configuration setup ------------------------------------------------------
struct
config
:
caf
::
actor_system_config
{
config
()
{
opt_group
{
custom_options_
,
"global"
}
//
.
add
<
uint16_t
>
(
"port,p"
,
"port to listen for incoming connections"
)
.
add
<
size_t
>
(
"max-connections,m"
,
"limit for concurrent clients"
);
}
};
// -- synchronous web server implementation ------------------------------------
class
web_socket_app
:
public
caf
::
net
::
web_socket
::
upper_layer
::
server
{
public:
static
auto
make
()
{
return
std
::
make_unique
<
web_socket_app
>
();
}
caf
::
error
start
(
caf
::
net
::
web_socket
::
lower_layer
*
ll
)
override
{
down
=
ll
;
down
->
request_messages
();
return
caf
::
none
;
}
caf
::
error
accept
(
const
caf
::
net
::
http
::
request_header
&
hdr
)
override
{
return
caf
::
none
;
}
void
prepare_send
()
override
{
// nop
}
bool
done_sending
()
override
{
return
true
;
}
void
abort
(
const
caf
::
error
&
reason
)
override
{
CAF_LOG_ERROR
(
reason
);
}
ptrdiff_t
consume_text
(
std
::
string_view
text
)
override
{
down
->
begin_text_message
();
auto
&
buffer
=
down
->
text_message_buffer
();
buffer
.
insert
(
buffer
.
end
(),
text
.
begin
(),
text
.
end
());
down
->
end_text_message
();
return
static_cast
<
ptrdiff_t
>
(
text
.
size
());
}
ptrdiff_t
consume_binary
(
caf
::
byte_span
bytes
)
override
{
down
->
begin_binary_message
();
auto
&
buffer
=
down
->
binary_message_buffer
();
buffer
.
insert
(
buffer
.
end
(),
bytes
.
begin
(),
bytes
.
end
());
down
->
end_binary_message
();
return
static_cast
<
ptrdiff_t
>
(
bytes
.
size
());
}
caf
::
net
::
web_socket
::
lower_layer
*
down
=
nullptr
;
};
int
caf_main
(
caf
::
actor_system
&
sys
,
const
config
&
cfg
)
{
namespace
ws
=
caf
::
net
::
web_socket
;
// Read the configuration.
auto
port
=
caf
::
get_or
(
cfg
,
"port"
,
default_port
);
auto
max_connections
=
caf
::
get_or
(
cfg
,
"max-connections"
,
default_max_connections
);
auto
app_layer
=
web_socket_app
::
make
();
auto
app
=
app_layer
.
get
();
auto
uut_layer
=
caf
::
net
::
web_socket
::
framing
::
make_server
(
std
::
move
(
app_layer
));
auto
uut
=
uut_layer
.
get
();
auto
transport
=
caf
::
net
::
octet_stream
::
transport
::
make
(
std
::
move
(
uut_layer
));
// transport->configure_read(caf::net::receive_policy::up_to(2048u));
return
EXIT_SUCCESS
;
}
CAF_MAIN
(
caf
::
net
::
middleman
)
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