Skip to content
Snippets Groups Projects
Commit 9a99da53 authored by Benny Baumann's avatar Benny Baumann
Browse files

add: unix socket client implementation

parent 1931daa8
No related branches found
No related tags found
No related merge requests found
...@@ -71,13 +71,21 @@ namespace rmrf::net { ...@@ -71,13 +71,21 @@ namespace rmrf::net {
return client_factory_construct_stream_client(socket_identifier, cb); return client_factory_construct_stream_client(socket_identifier, cb);
} }
[[nodiscard]] std::unique_ptr<connection_client> client_factory_construct_unix_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb) {
if (socket_identifier.family() != AF_UNIX) {
throw netio_exception("Expected UNIX domain socket address as target");
}
return client_factory_construct_stream_client(socket_identifier, cb);
}
[[nodiscard]] std::unique_ptr<connection_client> client_factory_construct_stream_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb) { [[nodiscard]] std::unique_ptr<connection_client> client_factory_construct_stream_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb) {
auto_fd socket_candidate{socket(socket_identifier.family(), SOCK_STREAM, 0)}; auto_fd socket_candidate{socket(socket_identifier.family(), SOCK_STREAM, 0)};
if (socket_candidate.valid()) { if (socket_candidate.valid()) {
if (connect(socket_candidate.get(), socket_identifier.ptr(), socket_identifier.size()) == 0) { if (connect(socket_candidate.get(), socket_identifier.ptr(), socket_identifier.size()) == 0) {
make_socket_nonblocking(socket_candidate); make_socket_nonblocking(socket_candidate);
const auto own_address = get_own_address_after_connect(socket_candidate); const auto own_address = socket_identifier.family() != AF_UNIX ? get_own_address_after_connect(socket_candidate) : socketaddr{};
// TODO create client object using socket_candidate, own_address and socket_identifier as remote address // TODO create client object using socket_candidate, own_address and socket_identifier as remote address
auto c = std::make_unique<tcp_client>(nullptr, std::move(socket_candidate), own_address, socket_identifier); auto c = std::make_unique<tcp_client>(nullptr, std::move(socket_candidate), own_address, socket_identifier);
...@@ -94,11 +102,10 @@ namespace rmrf::net { ...@@ -94,11 +102,10 @@ namespace rmrf::net {
switch(type) { switch(type) {
case socket_t::TCP: case socket_t::TCP:
return client_factory_construct_tcp_client(address); return client_factory_construct_tcp_client(address);
case socket_t::UNIX:
return client_factory_construct_unix_client(address);
case socket_t::UDP: case socket_t::UDP:
return client_factory_construct_udp_client(address); return client_factory_construct_udp_client(address);
case socket_t::UNIX:
// TODO implement
return nullptr;
default: default:
return nullptr; return nullptr;
} }
......
...@@ -11,6 +11,7 @@ namespace rmrf::net { ...@@ -11,6 +11,7 @@ namespace rmrf::net {
[[nodiscard]] std::unique_ptr<udp_client> client_factory_construct_udp_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb = nullptr); [[nodiscard]] std::unique_ptr<udp_client> client_factory_construct_udp_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb = nullptr);
[[nodiscard]] std::unique_ptr<connection_client> client_factory_construct_tcp_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb = nullptr); [[nodiscard]] std::unique_ptr<connection_client> client_factory_construct_tcp_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb = nullptr);
[[nodiscard]] std::unique_ptr<connection_client> client_factory_construct_unix_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb = nullptr);
[[nodiscard]] std::unique_ptr<connection_client> client_factory_construct_stream_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb = nullptr); [[nodiscard]] std::unique_ptr<connection_client> client_factory_construct_stream_client(const socketaddr& socket_identifier, connection_client::incomming_data_cb cb = nullptr);
/** /**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment