Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[20262] Add non-throwing getters for socket info #4319

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Refs #20262: Apply suggestions
Signed-off-by: Jesus Perez <jesusperez@eprosima.com>
  • Loading branch information
jepemi authored and JesusPoderoso committed Feb 8, 2024
commit 45b281a6ad3336d211fa7a2024e49971f5305aec
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);
MiguelCompany marked this conversation as resolved.
Show resolved Hide resolved

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