summaryrefslogtreecommitdiff
path: root/implementation/endpoints
diff options
context:
space:
mode:
authorJuergen Gehring <juergen.gehring@bmw.de>2018-01-25 00:40:08 -0800
committerJuergen Gehring <juergen.gehring@bmw.de>2018-01-25 00:40:08 -0800
commit565b97b0108a02ef41284629a6d226c053c0dd7e (patch)
tree5a0b28ba67e3ac8d4cf349ea3a464d8cfd4a5ac1 /implementation/endpoints
parent8936891b5db1a0c894a3ec0af52c081b52cca46c (diff)
downloadvSomeIP-565b97b0108a02ef41284629a6d226c053c0dd7e.tar.gz
vsomeip 2.10.82.10.8
Diffstat (limited to 'implementation/endpoints')
-rw-r--r--implementation/endpoints/include/client_endpoint_impl.hpp7
-rw-r--r--implementation/endpoints/src/client_endpoint_impl.cpp20
-rw-r--r--implementation/endpoints/src/local_client_endpoint_impl.cpp6
-rw-r--r--implementation/endpoints/src/tcp_client_endpoint_impl.cpp10
-rw-r--r--implementation/endpoints/src/udp_client_endpoint_impl.cpp7
5 files changed, 35 insertions, 15 deletions
diff --git a/implementation/endpoints/include/client_endpoint_impl.hpp b/implementation/endpoints/include/client_endpoint_impl.hpp
index d8c758d..b72ea7e 100644
--- a/implementation/endpoints/include/client_endpoint_impl.hpp
+++ b/implementation/endpoints/include/client_endpoint_impl.hpp
@@ -70,6 +70,11 @@ public:
virtual void print_status() = 0;
protected:
+ enum class cei_state_e : std::uint8_t {
+ CLOSED,
+ CONNECTING,
+ ESTABLISHED
+ };
virtual void send_queued() = 0;
void shutdown_and_close_socket(bool _recreate_socket);
void shutdown_and_close_socket_unlocked(bool _recreate_socket);
@@ -84,7 +89,7 @@ protected:
std::mutex connect_timer_mutex_;
boost::asio::steady_timer connect_timer_;
std::atomic<uint32_t> connect_timeout_;
- std::atomic<bool> is_connected_;
+ std::atomic<cei_state_e> state_;
// send data
message_buffer_ptr_t packetizer_;
diff --git a/implementation/endpoints/src/client_endpoint_impl.cpp b/implementation/endpoints/src/client_endpoint_impl.cpp
index 55316a9..be8e684 100644
--- a/implementation/endpoints/src/client_endpoint_impl.cpp
+++ b/implementation/endpoints/src/client_endpoint_impl.cpp
@@ -37,7 +37,7 @@ client_endpoint_impl<Protocol>::client_endpoint_impl(
socket_(new socket_type(_io)), remote_(_remote),
flush_timer_(_io), connect_timer_(_io),
connect_timeout_(VSOMEIP_DEFAULT_CONNECT_TIMEOUT), // TODO: use config variable
- is_connected_(false),
+ state_(cei_state_e::CLOSED),
packetizer_(std::make_shared<message_buffer_t>()),
queue_size_(0),
was_not_connected_(false),
@@ -55,11 +55,16 @@ bool client_endpoint_impl<Protocol>::is_client() const {
template<typename Protocol>
bool client_endpoint_impl<Protocol>::is_connected() const {
- return is_connected_;
+ return state_ == cei_state_e::ESTABLISHED;
}
template<typename Protocol>
-void client_endpoint_impl<Protocol>::set_connected(bool _connected) { is_connected_ = _connected; }
+void client_endpoint_impl<Protocol>::set_connected(bool _connected) {
+ if (_connected) {
+ state_ = cei_state_e::ESTABLISHED;
+ } else {
+ state_ = cei_state_e::CLOSED;
+ } }
template<typename Protocol> void client_endpoint_impl<Protocol>::stop() {
{
std::lock_guard<std::mutex> its_lock(mutex_);
@@ -222,8 +227,8 @@ void client_endpoint_impl<Protocol>::connect_cbk(
if (connect_timeout_ < VSOMEIP_MAX_CONNECT_TIMEOUT)
connect_timeout_ = (connect_timeout_ << 1);
- if (is_connected_) {
- is_connected_ = false;
+ if (state_ != cei_state_e::ESTABLISHED) {
+ state_ = cei_state_e::CLOSED;
its_host->on_disconnect(this->shared_from_this());
}
} else {
@@ -233,7 +238,7 @@ void client_endpoint_impl<Protocol>::connect_cbk(
}
connect_timeout_ = VSOMEIP_DEFAULT_CONNECT_TIMEOUT; // TODO: use config variable
set_local_port();
- if (!is_connected_) {
+ if (state_ != cei_state_e::ESTABLISHED) {
its_host->on_connect(this->shared_from_this());
}
@@ -270,7 +275,7 @@ void client_endpoint_impl<Protocol>::send_cbk(
send_queued();
}
} else if (_error == boost::asio::error::broken_pipe) {
- is_connected_ = false;
+ state_ = cei_state_e::CLOSED;
bool stopping(false);
{
std::lock_guard<std::mutex> its_lock(mutex_);
@@ -319,6 +324,7 @@ void client_endpoint_impl<Protocol>::send_cbk(
connect();
} else if (_error == boost::asio::error::not_connected
|| _error == boost::asio::error::bad_descriptor) {
+ state_ = cei_state_e::CLOSED;
was_not_connected_ = true;
shutdown_and_close_socket(true);
connect();
diff --git a/implementation/endpoints/src/local_client_endpoint_impl.cpp b/implementation/endpoints/src/local_client_endpoint_impl.cpp
index 009ac9f..b84cb0a 100644
--- a/implementation/endpoints/src/local_client_endpoint_impl.cpp
+++ b/implementation/endpoints/src/local_client_endpoint_impl.cpp
@@ -46,7 +46,10 @@ bool local_client_endpoint_impl::is_local() const {
}
void local_client_endpoint_impl::restart() {
- is_connected_ = false;
+ if (state_ == cei_state_e::CONNECTING) {
+ return;
+ }
+ state_ = cei_state_e::CONNECTING;
{
std::lock_guard<std::mutex> its_lock(mutex_);
sending_blocked_ = false;
@@ -113,6 +116,7 @@ void local_client_endpoint_impl::connect() {
VSOMEIP_WARNING << "local_client_endpoint_impl::connect: "
<< "couldn't enable SO_REUSEADDR: " << its_error.message();
}
+ state_ = cei_state_e::CONNECTING;
socket_->connect(remote_, its_connect_error);
// Credentials
diff --git a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp
index 143b95a..b1a2f74 100644
--- a/implementation/endpoints/src/tcp_client_endpoint_impl.cpp
+++ b/implementation/endpoints/src/tcp_client_endpoint_impl.cpp
@@ -61,7 +61,10 @@ void tcp_client_endpoint_impl::start() {
}
void tcp_client_endpoint_impl::restart() {
- is_connected_ = false;
+ if (state_ == cei_state_e::CONNECTING) {
+ return;
+ }
+ state_ = cei_state_e::CONNECTING;
std::string address_port_local;
{
std::lock_guard<std::mutex> its_lock(socket_mutex_);
@@ -137,7 +140,7 @@ void tcp_client_endpoint_impl::connect() {
"Error binding socket: " << its_bind_error.message();
}
}
-
+ state_ = cei_state_e::CONNECTING;
socket_->async_connect(
remote_,
std::bind(
@@ -180,7 +183,6 @@ void tcp_client_endpoint_impl::receive(message_buffer_ptr_t _recv_buffer,
_recv_buffer->resize(its_required_capacity, 0x0);
}
buffer_size = _missing_capacity;
- _missing_capacity = 0;
} else if (buffer_shrink_threshold_
&& shrink_count_ > buffer_shrink_threshold_
&& _recv_buffer_size == 0) {
@@ -517,7 +519,7 @@ void tcp_client_endpoint_impl::receive_cbk(
<< _error.message() << "( " << std::dec << _error.value()
<< ") local: " << get_address_port_local()
<< " remote: " << get_address_port_remote();
- is_connected_ = false;
+ state_ = cei_state_e::CLOSED;
shutdown_and_close_socket_unlocked(false);
} else {
VSOMEIP_WARNING << "tcp_client_endpoint receive_cbk: "
diff --git a/implementation/endpoints/src/udp_client_endpoint_impl.cpp b/implementation/endpoints/src/udp_client_endpoint_impl.cpp
index 6bc0bf5..6252b40 100644
--- a/implementation/endpoints/src/udp_client_endpoint_impl.cpp
+++ b/implementation/endpoints/src/udp_client_endpoint_impl.cpp
@@ -51,7 +51,7 @@ void udp_client_endpoint_impl::connect() {
"Error binding socket: " << its_bind_error.message();
}
}
-
+ state_ = cei_state_e::CONNECTING;
socket_->async_connect(
remote_,
std::bind(
@@ -77,7 +77,10 @@ void udp_client_endpoint_impl::start() {
}
void udp_client_endpoint_impl::restart() {
- is_connected_ = false;
+ if (state_ == cei_state_e::CONNECTING) {
+ return;
+ }
+ state_ = cei_state_e::CONNECTING;
{
std::lock_guard<std::mutex> its_lock(mutex_);
queue_.clear();