Skip to content

Commit c0173a7

Browse files
brunoldsilvaDuarte Fonseca
authored andcommitted
Disconnect on error
Summary Close all connections on "client error". Details These changes related to e716737 but here it's the server that loses connection to the client. Since the server application may not be consuming services from the client, the process of re-requesting service availability triggers from the routing host does not work. Instead, the server will forcibly terminate all connections to the client, forcing them to re-establish the connections to the server. An alternative was considered where the server would instead try to reconnect to the client when it tried to send something, but it was a bigger change that introduced several issues during testing.
1 parent 272fd08 commit c0173a7

11 files changed

+97
-1
lines changed

implementation/endpoints/include/local_tcp_server_endpoint_impl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ class local_tcp_server_endpoint_impl
6969

7070
client_t assign_client(const byte_t *_data, uint32_t _size);
7171

72+
/// @brief Disconnects from the given client.
73+
///
74+
/// @param _client ID of the remote client.
75+
void disconnect_from(const client_t _client) override;
76+
7277
private:
7378
class connection: public std::enable_shared_from_this<connection> {
7479

implementation/endpoints/include/local_uds_server_endpoint_impl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ class local_uds_server_endpoint_impl: public local_uds_server_endpoint_base_impl
6767

6868
client_t assign_client(const byte_t *_data, uint32_t _size);
6969

70+
/// @brief Disconnects from the given client.
71+
///
72+
/// @param _client ID of the remote client.
73+
void disconnect_from(const client_t _client) override;
74+
7075
private:
7176
class connection: public std::enable_shared_from_this<connection> {
7277

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (C) 2025 Bayerische Motoren Werke Aktiengesellschaft (BMW AG)
2+
// This Source Code Form is subject to the terms of the Mozilla Public
3+
// License, v. 2.0. If a copy of the MPL was not distributed with this
4+
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
5+
6+
#ifndef VSOMEIP_V3_SERVER_ENDPOINT_HPP_
7+
#define VSOMEIP_V3_SERVER_ENDPOINT_HPP_
8+
9+
#include <vsomeip/primitive_types.hpp>
10+
11+
namespace vsomeip_v3 {
12+
13+
/// @brief An endpoint to which clients connect.
14+
class server_endpoint {
15+
public:
16+
/// @brief Destructor.
17+
virtual ~server_endpoint() = default;
18+
19+
/// @brief Disconnects from the given client.
20+
///
21+
/// @param _client ID of the remote client.
22+
virtual void disconnect_from(const client_t _client) = 0;
23+
};
24+
25+
}
26+
27+
#endif // VSOMEIP_V3_SERVER_ENDPOINT_HPP_

implementation/endpoints/include/server_endpoint_impl.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
#include "buffer.hpp"
2020
#include "endpoint_impl.hpp"
21+
#include "server_endpoint.hpp"
2122
#include "tp.hpp"
2223
#if defined(__QNX__)
2324
#include "../../utility/include/qnx_helper.hpp"
@@ -26,7 +27,8 @@
2627
namespace vsomeip_v3 {
2728

2829
template<typename Protocol>
29-
class server_endpoint_impl : public endpoint_impl<Protocol>,
30+
class server_endpoint_impl : public server_endpoint,
31+
public endpoint_impl<Protocol>,
3032
public std::enable_shared_from_this<server_endpoint_impl<Protocol>> {
3133
public:
3234
typedef typename Protocol::socket socket_type;

implementation/endpoints/include/tcp_server_endpoint_impl.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,12 @@ class tcp_server_endpoint_impl: public tcp_server_endpoint_base_impl {
6565
void print_status();
6666

6767
bool is_suspended() const;
68+
69+
/// @brief Disconnects from the given client.
70+
///
71+
/// @param _client ID of the remote client.
72+
void disconnect_from(const client_t _client) override;
73+
6874
private:
6975
class connection: public std::enable_shared_from_this<connection> {
7076

implementation/endpoints/include/udp_server_endpoint_impl.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ class udp_server_endpoint_impl: public udp_server_endpoint_base_impl {
8080
bool is_joined(const std::string &_address) const;
8181
bool is_joined(const std::string &_address, bool& _received) const;
8282

83+
/// @brief Disconnects from the given client.
84+
///
85+
/// @param _client ID of the remote client.
86+
void disconnect_from(const client_t _client) override;
87+
8388
private:
8489
void leave_unlocked(const std::string &_address);
8590
void set_broadcast();

implementation/endpoints/src/local_tcp_server_endpoint_impl.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include "../../configuration/include/configuration.hpp"
2727
#include "../../protocol/include/assign_client_command.hpp"
2828
#include "../../protocol/include/assign_client_ack_command.hpp"
29+
#include "../../protocol/include/protocol.hpp"
2930
#include "../../routing/include/routing_host.hpp"
3031
#include "../../security/include/policy_manager_impl.hpp"
3132
#include "../../security/include/security.hpp"
@@ -520,6 +521,15 @@ client_t local_tcp_server_endpoint_impl::assign_client(
520521
its_command.get_name(), its_command.get_client());
521522
}
522523

524+
void local_tcp_server_endpoint_impl::disconnect_from(const client_t _client) {
525+
std::scoped_lock lock {connections_mutex_};
526+
if (connections_.find(_client) == connections_.end()) {
527+
return;
528+
}
529+
connections_.at(_client)->stop();
530+
connections_.erase(_client);
531+
}
532+
523533
void local_tcp_server_endpoint_impl::get_configured_times_from_endpoint(
524534
service_t _service,
525535
method_t _method, std::chrono::nanoseconds *_debouncing,
@@ -728,6 +738,18 @@ void local_tcp_server_endpoint_impl::connection::receive_cbk(
728738
sec_client_.port = htons(its_port);
729739
its_server->configuration_->get_security()->sync_client(&sec_client_);
730740

741+
// Associate a client ID to this connection.
742+
if (bound_client_ == VSOMEIP_CLIENT_UNSET) {
743+
client_t its_client = VSOMEIP_CLIENT_UNSET;
744+
std::memcpy(
745+
&its_client,
746+
&recv_buffer_[its_start + protocol::COMMAND_POSITION_CLIENT],
747+
sizeof(client_t));
748+
749+
set_bound_client(its_client);
750+
its_server->add_connection(its_client, shared_from_this());
751+
}
752+
731753
its_host->on_message(&recv_buffer_[its_start],
732754
uint32_t(its_end - its_start), its_server.get(),
733755
false, bound_client_, &sec_client_,

implementation/endpoints/src/local_uds_server_endpoint_impl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -559,6 +559,15 @@ client_t local_uds_server_endpoint_impl::assign_client(
559559
its_command.get_name(), its_command.get_client());
560560
}
561561

562+
void local_uds_server_endpoint_impl::disconnect_from(const client_t _client) {
563+
std::scoped_lock lock {connections_mutex_};
564+
if (connections_.find(_client) == connections_.end()) {
565+
return;
566+
}
567+
connections_.at(_client)->stop();
568+
connections_.erase(_client);
569+
}
570+
562571
void local_uds_server_endpoint_impl::get_configured_times_from_endpoint(
563572
service_t _service,
564573
method_t _method, std::chrono::nanoseconds *_debouncing,

implementation/endpoints/src/tcp_server_endpoint_impl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,10 @@ bool tcp_server_endpoint_impl::is_suspended() const {
318318
return false;
319319
}
320320

321+
void tcp_server_endpoint_impl::disconnect_from(const client_t) {
322+
return;
323+
}
324+
321325
///////////////////////////////////////////////////////////////////////////////
322326
// class tcp_service_impl::connection
323327
///////////////////////////////////////////////////////////////////////////////

implementation/endpoints/src/udp_server_endpoint_impl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,10 @@ void udp_server_endpoint_impl::leave(const std::string& _address) {
539539
leave_unlocked(_address);
540540
}
541541

542+
void udp_server_endpoint_impl::disconnect_from(const client_t) {
543+
return;
544+
}
545+
542546
void udp_server_endpoint_impl::leave_unlocked(const std::string& _address) {
543547

544548
try {

0 commit comments

Comments
 (0)