Skip to content

Commit

Permalink
Refs #20262: Apply suggestions
Browse files Browse the repository at this point in the history
Signed-off-by: Jesus Perez <jesusperez@eprosima.com>
  • Loading branch information
jepemi committed Jan 30, 2024
1 parent 05a78fc commit 807f8ba
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 9 deletions.
20 changes: 20 additions & 0 deletions src/cpp/rtps/transport/TCPChannelResource.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,13 +130,33 @@ class TCPChannelResource : public ChannelResource
size_t size,
asio::error_code& ec) = 0;

/**
* @brief Gets the remote endpoint of the socket connection.
* @throws Exception on failure.
* @return asio::ip::tcp::endpoint of the remote endpoint.
*/
virtual asio::ip::tcp::endpoint remote_endpoint() const = 0;

/**
* @brief Gets the local endpoint of the socket connection.
* @throws Exception on failure.
* @return asio::ip::tcp::endpoint of the local endpoint.
*/
virtual asio::ip::tcp::endpoint local_endpoint() const = 0;

/**
* @brief Gets the remote endpoint, setting error code if any.
* @param ec Set to indicate what error occurred, if any.
* @return asio::ip::tcp::endpoint of the remote endpoint or returns a default-constructed endpoint object if an error occurred.
*/
virtual asio::ip::tcp::endpoint remote_endpoint(
asio::error_code& ec) const = 0;

/**
* @brief Gets the local endpoint, setting error code if any.
* @param ec Set to indicate what error occurred, if any.
* @return asio::ip::tcp::endpoint of the remote endpoint or returns a default-constructed endpoint object if an error occurred.
*/
virtual asio::ip::tcp::endpoint local_endpoint(
asio::error_code& ec) const = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/cpp/rtps/transport/TCPChannelResourceBasic.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,11 @@ class TCPChannelResourceBasic : public TCPChannelResource
size_t size,
asio::error_code& ec) override;

// Non-throwing asio calls
// Throwing asio calls
asio::ip::tcp::endpoint remote_endpoint() const override;
asio::ip::tcp::endpoint local_endpoint() const override;

// Throwing asio calls
// Non-throwing asio calls
asio::ip::tcp::endpoint remote_endpoint(
asio::error_code& ec) const override;
asio::ip::tcp::endpoint local_endpoint(
Expand Down
23 changes: 16 additions & 7 deletions src/cpp/rtps/transport/TCPTransportInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,19 @@ void TCPTransportInterface::clean()
}
}

Locator TCPTransportInterface::remote_endpoint_to_locator(
const std::shared_ptr<TCPChannelResource>& channel) const
{
Locator locator;
asio::error_code ec;
endpoint_to_locator(channel->remote_endpoint(ec), locator);
if (ec)
{
LOCATOR_INVALID(locator);
}
return locator;
}

void TCPTransportInterface::bind_socket(
std::shared_ptr<TCPChannelResource>& channel)
{
Expand Down Expand Up @@ -898,12 +911,8 @@ void TCPTransportInterface::perform_listen_operation(
if (rtcp_message_manager)
{
channel = channel_weak.lock();
asio::error_code ec;
endpoint_to_locator(channel->remote_endpoint(ec), remote_locator);
if (ec)
{
remote_locator.kind = LOCATOR_KIND_INVALID;
}

remote_locator = remote_endpoint_to_locator(channel);

if (channel)
{
Expand Down Expand Up @@ -1185,7 +1194,7 @@ bool TCPTransportInterface::Receive(
{
if (!IsLocatorValid(remote_locator))
{
endpoint_to_locator(channel->remote_endpoint(), remote_locator);
remote_locator = remote_endpoint_to_locator(channel);
}
IPLocator::setLogicalPort(remote_locator, tcp_header.logical_port);
EPROSIMA_LOG_INFO(RTCP_MSG_IN, "[RECEIVE] From: " << remote_locator \
Expand Down
6 changes: 6 additions & 0 deletions src/cpp/rtps/transport/TCPTransportInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,12 @@ class TCPTransportInterface : public TransportInterface
const asio::ip::tcp::endpoint& endpoint,
Locator& locator) const = 0;

/**
* Converts a remote endpoint to a locator if possible. Otherwise, it sets an invalid locator.
*/
Locator remote_endpoint_to_locator(
const std::shared_ptr<TCPChannelResource>& channel) const;

/**
* Shutdown method to close the connections of the transports.
*/
Expand Down

0 comments on commit 807f8ba

Please sign in to comment.