| 371 | |
| 372 | template<typename Protocol> |
| 373 | void client_endpoint_impl<Protocol>::connect_cbk(boost::system::error_code const& _error) { |
| 374 | |
| 375 | if (_error == boost::asio::error::operation_aborted || endpoint_impl<Protocol>::sending_blocked_) { |
| 376 | VSOMEIP_WARNING_P << "Endpoint stopped, remote: " << get_remote_information() << ", endpoint > " << this << " socket state > " |
| 377 | << to_string(state_.load()); |
| 378 | close_socket(false, false); |
| 379 | return; |
| 380 | } |
| 381 | std::shared_ptr<boardnet_endpoint_host> its_host = this->endpoint_host_.lock(); |
| 382 | if (its_host) { |
| 383 | if (_error && _error != boost::asio::error::already_connected) { |
| 384 | VSOMEIP_WARNING_P << "Restarting socket due to " << _error.message() << " (" << _error.value() |
| 385 | << "), remote: " << get_remote_information() << ", endpoint > " << this << " socket state > " |
| 386 | << to_string(state_.load()); |
| 387 | |
| 388 | close_socket(true, true); |
| 389 | |
| 390 | its_host->on_disconnect(this->shared_from_this()); |
| 391 | |
| 392 | if (get_max_allowed_reconnects() == MAX_RECONNECTS_UNLIMITED || get_max_allowed_reconnects() >= ++reconnect_counter_) { |
| 393 | is_sending_ = false; |
| 394 | was_not_connected_ = true; |
| 395 | start_connect_timer(); |
| 396 | } else { |
| 397 | max_allowed_reconnects_reached(); |
| 398 | } |
| 399 | // After 30 attempts of 100ms (3s) increase the timer exponential |
| 400 | // Double the timeout as long as the maximum allowed is larger |
| 401 | if (connect_timeout_ < VSOMEIP_MAX_CONNECT_TIMEOUT && reconnect_counter_ > 30) |
| 402 | connect_timeout_ = (connect_timeout_ << 1); |
| 403 | } else { |
| 404 | if (_error) { |
| 405 | VSOMEIP_WARNING_P << "connect_cbk attempt (" << _error.value() << "):" << _error.message() |
| 406 | << ", remote: " << get_remote_information() << ", endpoint > " << this << " socket state > " |
| 407 | << to_string(state_.load()); |
| 408 | } |
| 409 | { |
| 410 | std::scoped_lock its_lock(connect_timer_mutex_); |
| 411 | connect_timer_.cancel(); |
| 412 | } |
| 413 | connect_timeout_ = VSOMEIP_DEFAULT_CONNECT_TIMEOUT; // TODO: use config variable |
| 414 | reconnect_counter_ = 0; |
| 415 | { |
| 416 | std::scoped_lock its_lock(mutex_); |
| 417 | if (was_not_connected_) { |
| 418 | was_not_connected_ = false; |
| 419 | auto its_entry = get_front(); |
| 420 | if (its_entry.first) { |
| 421 | is_sending_ = true; |
| 422 | boost::asio::dispatch(strand_, std::bind(&client_endpoint_impl::send_queued, this->shared_from_this(), its_entry)); |
| 423 | VSOMEIP_WARNING_P << "Resume sending to: " << get_remote_information() << " endpoint > " << this |
| 424 | << " socket state > " << to_string(state_.load()); |
| 425 | } |
| 426 | } |
| 427 | } |
| 428 | if (state_ != cei_state_e::ESTABLISHED) { |
| 429 | its_host->on_connect(this->shared_from_this()); |
| 430 | } |
nothing calls this directly
no test coverage detected