const bool can_use_bcast = use_bcast && (socket_type_ == SOCKET_RAW);
reconnect_ctl_ = makeReconnectCtl();
- auto sopen = openSocketsWithRetry(reconnect_ctl_, family, port, can_use_bcast);
+ auto sopen = openSocketsWithRetry(reconnect_ctl_, family, port, can_use_bcast, false);
if (!sopen) {
// If no socket were opened, log a warning because the server will
reconnect_ctl_->resetRetries();
- openSocketsWithRetry(reconnect_ctl_, family, port, can_use_bcast);
+ openSocketsWithRetry(reconnect_ctl_, family, port, can_use_bcast, true);
}
std::pair<bool, bool>
bool
CfgIface::openSocketsWithRetry(ReconnectCtlPtr reconnect_ctl,
const uint16_t family, const uint16_t port,
- const bool can_use_bcast) const {
+ const bool can_use_bcast, bool skip_opened) const {
MultiThreadingCriticalSection cs;
// The detection must be done before resetting and setting the
}
// Skip opened sockets in the retry calls.
- bool is_initial_call = (reconnect_ctl->retriesLeft() == reconnect_ctl->maxRetries());
+ bool is_initial_call = false;
+ if (!skip_opened) {
+ is_initial_call = (reconnect_ctl->retriesLeft() == reconnect_ctl->maxRetries());
+ }
auto result_pair = CfgIface::openSocketsForFamily(family, port, can_use_bcast, !is_initial_call);
bool sopen = result_pair.first;
bool has_errors = !result_pair.second;
std::bind(&CfgIface::openSocketsWithRetry,
this,
reconnect_ctl, family,
- port, can_use_bcast),
+ port, can_use_bcast, false),
reconnect_ctl->retryInterval(),
asiolink::IntervalTimer::ONE_SHOT);
}
/// traffic should be received through the socket and the raw sockets are
/// used. For the UDP sockets, we only handle the relayed (unicast)
/// traffic. This parameter is ignored for IPv6.
+ /// @param skip_opened Omits the already opened sockets (doesn't try to
+ /// re-bind).
///
/// @return True if at least one socket opened successfully.
bool openSocketsWithRetry(util::ReconnectCtlPtr reconnect_ctl,
const uint16_t family, const uint16_t port,
- const bool can_use_bcast) const;
+ const bool can_use_bcast, bool skip_opened) const;
/// @brief Represents a set of interface names.
typedef std::set<std::string> IfaceSet;