Commit bae98e17 authored by Dominik Charousset's avatar Dominik Charousset

Add convenience functions and fix some type errors

parent c6fbe7ad
......@@ -26,11 +26,11 @@ struct CAF_NET_EXPORT tcp_stream_socket : stream_socket {
expected<tcp_stream_socket>
CAF_NET_EXPORT make_connected_tcp_stream_socket(ip_endpoint node);
/// Create a `tcp_stream_socket` connected to `auth`.
/// @param node Host and port of the remote node.
/// Creates a `tcp_stream_socket` connected to @p auth.
/// @param auth Host and port of the remote node.
/// @returns The connected socket or an error.
/// @relates tcp_stream_socket
expected<tcp_stream_socket> CAF_NET_EXPORT
make_connected_tcp_stream_socket(const uri::authority_type& node);
make_connected_tcp_stream_socket(const uri::authority_type& auth);
} // namespace caf::net
......@@ -4,14 +4,13 @@
#pragma once
#include <algorithm>
#include "caf/byte_span.hpp"
#include "caf/detail/base64.hpp"
#include "caf/error.hpp"
#include "caf/hash/sha1.hpp"
#include "caf/logger.hpp"
#include "caf/net/fwd.hpp"
#include "caf/net/message_flow_bridge.hpp"
#include "caf/net/receive_policy.hpp"
#include "caf/net/web_socket/framing.hpp"
#include "caf/net/web_socket/handshake.hpp"
......@@ -20,6 +19,8 @@
#include "caf/tag/mixed_message_oriented.hpp"
#include "caf/tag/stream_oriented.hpp"
#include <algorithm>
namespace caf::net::web_socket {
/// Implements the client part for the WebSocket Protocol as defined in RFC
......@@ -179,4 +180,17 @@ private:
settings cfg_;
};
template <template <class> class Transport = stream_transport, class Socket,
class T, class Trait>
void run_client(multiplexer& mpx, Socket fd, handshake hs,
async::consumer_resource<T> in, async::producer_resource<T> out,
Trait trait) {
using app_t = message_flow_bridge<T, Trait, tag::mixed_message_oriented>;
using stack_t = Transport<client<app_t>>;
auto mgr = make_socket_manager<stack_t>(fd, &mpx, std::move(hs),
std::move(trait));
mgr->top_layer().connect_flows(mgr.get(), std::move(in), std::move(out));
mpx.init(mgr);
}
} // namespace caf::net::web_socket
......@@ -4,8 +4,6 @@
#pragma once
#include <algorithm>
#include "caf/byte_span.hpp"
#include "caf/error.hpp"
#include "caf/logger.hpp"
......@@ -23,6 +21,8 @@
#include "caf/tag/mixed_message_oriented.hpp"
#include "caf/tag/stream_oriented.hpp"
#include <algorithm>
namespace caf::net::web_socket {
/// Implements the server part for the WebSocket Protocol as defined in RFC
......@@ -385,11 +385,11 @@ public:
return decorated().convert(x, text);
}
bool convert(const_byte_span bytes, int32_t&x) {
bool convert(const_byte_span bytes, value_type& x) {
return decorated().convert(bytes, x);
}
bool convert(string_view text, int32_t& x) {
bool convert(string_view text, value_type& x) {
return decorated().convert(text, x);
}
......
......@@ -83,4 +83,12 @@ make_connected_tcp_stream_socket(const uri::authority_type& node) {
return make_error(sec::cannot_connect_to_node, to_string(node));
}
expected<tcp_stream_socket> make_connected_tcp_stream_socket(std::string host,
uint16_t port) {
uri::authority_type auth;
auth.host = std::move(host);
auth.port = port;
return make_connected_tcp_stream_socket(auth);
}
} // namespace caf::net
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment