@@ -191,6 +191,7 @@ void TCPTransportInterface::clean()
191
191
192
192
{
193
193
std::vector<std::shared_ptr<TCPChannelResource>> channels;
194
+ std::vector<eprosima::fastdds::rtps::Locator> delete_channels;
194
195
195
196
{
196
197
std::unique_lock<std::mutex> scopedLock (sockets_map_mutex_);
@@ -200,10 +201,22 @@ void TCPTransportInterface::clean()
200
201
201
202
for (auto & channel : channel_resources_)
202
203
{
203
- channels.push_back (channel.second );
204
+ if (std::find (channels.begin (), channels.end (), channel.second ) == channels.end ())
205
+ {
206
+ channels.push_back (channel.second );
207
+ }
208
+ else
209
+ {
210
+ delete_channels.push_back (channel.first );
211
+ }
204
212
}
205
213
}
206
214
215
+ for (auto & delete_channel : delete_channels)
216
+ {
217
+ channel_resources_.erase (delete_channel);
218
+ }
219
+
207
220
for (auto & channel : channels)
208
221
{
209
222
if (channel->connection_established ())
@@ -279,7 +292,7 @@ Locator TCPTransportInterface::local_endpoint_to_locator(
279
292
return locator;
280
293
}
281
294
282
- void TCPTransportInterface::bind_socket (
295
+ ResponseCode TCPTransportInterface::bind_socket (
283
296
std::shared_ptr<TCPChannelResource>& channel)
284
297
{
285
298
std::unique_lock<std::mutex> scopedLock (sockets_map_mutex_);
@@ -288,7 +301,29 @@ void TCPTransportInterface::bind_socket(
288
301
auto it_remove = std::find (unbound_channel_resources_.begin (), unbound_channel_resources_.end (), channel);
289
302
assert (it_remove != unbound_channel_resources_.end ());
290
303
unbound_channel_resources_.erase (it_remove);
291
- channel_resources_[channel->locator ()] = channel;
304
+
305
+ ResponseCode ret = RETCODE_OK;
306
+ const auto insert_ret = channel_resources_.insert (
307
+ decltype (channel_resources_)::value_type{channel->locator (), channel});
308
+ if (false == insert_ret.second )
309
+ {
310
+ // There is an existing channel that can be used. Force the Client to close unnecessary socket
311
+ ret = RETCODE_SERVER_ERROR;
312
+ }
313
+
314
+ std::vector<fastdds::rtps::IPFinder::info_IP> local_interfaces;
315
+ // Check if the locator is from an owned interface to link all local interfaces to the channel
316
+ is_own_interface (channel->locator (), local_interfaces);
317
+ if (!local_interfaces.empty ())
318
+ {
319
+ Locator local_locator (channel->locator ());
320
+ for (auto & interface_it : local_interfaces)
321
+ {
322
+ IPLocator::setIPv4 (local_locator, interface_it.locator );
323
+ channel_resources_.insert (decltype (channel_resources_)::value_type{local_locator, channel});
324
+ }
325
+ }
326
+ return ret;
292
327
}
293
328
294
329
bool TCPTransportInterface::check_crc (
@@ -923,7 +958,7 @@ bool TCPTransportInterface::CreateInitialConnect(
923
958
std::lock_guard<std::mutex> socketsLock (sockets_map_mutex_);
924
959
925
960
// We try to find a SenderResource that has this locator.
926
- // Note: This is done in this level because if we do in NetworkFactory level, we have to mantain what transport
961
+ // Note: This is done in this level because if we do it at NetworkFactory level, we have to mantain what transport
927
962
// already reuses a SenderResource.
928
963
for (auto & sender_resource : send_resource_list)
929
964
{
@@ -987,6 +1022,19 @@ bool TCPTransportInterface::CreateInitialConnect(
987
1022
send_resource_list.emplace_back (
988
1023
static_cast <SenderResource*>(new TCPSenderResource (*this , physical_locator)));
989
1024
1025
+ std::vector<fastdds::rtps::IPFinder::info_IP> local_interfaces;
1026
+ // Check if the locator is from an owned interface to link all local interfaces to the channel
1027
+ is_own_interface (physical_locator, local_interfaces);
1028
+ if (!local_interfaces.empty ())
1029
+ {
1030
+ Locator local_locator (physical_locator);
1031
+ for (auto & interface_it : local_interfaces)
1032
+ {
1033
+ IPLocator::setIPv4 (local_locator, interface_it.locator );
1034
+ channel_resources_[local_locator] = channel;
1035
+ }
1036
+ }
1037
+
990
1038
return true ;
991
1039
}
992
1040
@@ -2079,6 +2127,28 @@ void TCPTransportInterface::send_channel_pending_logical_ports(
2079
2127
}
2080
2128
}
2081
2129
2130
+ void TCPTransportInterface::is_own_interface (
2131
+ const Locator& locator,
2132
+ std::vector<fastdds::rtps::IPFinder::info_IP>& locNames) const
2133
+ {
2134
+ std::vector<fastdds::rtps::IPFinder::info_IP> local_interfaces;
2135
+ get_ips (local_interfaces, true , false );
2136
+ for (const auto & interface_it : local_interfaces)
2137
+ {
2138
+ if (IPLocator::compareAddress (locator, interface_it.locator ) && is_interface_allowed (interface_it.name ))
2139
+ {
2140
+ locNames = local_interfaces;
2141
+ // Remove interface of original locator from the list
2142
+ locNames.erase (std::remove_if (locNames.begin (), locNames.end (),
2143
+ [&interface_it](const fastdds::rtps::IPFinder::info_IP& locInterface)
2144
+ {
2145
+ return locInterface.locator == interface_it.locator ;
2146
+ }), locNames.end ());
2147
+ break ;
2148
+ }
2149
+ }
2150
+ }
2151
+
2082
2152
} // namespace rtps
2083
2153
} // namespace fastdds
2084
2154
} // namespace eprosima
0 commit comments