Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
code
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ReadMailReallyFast
code
Commits
07274320
Commit
07274320
authored
2 years ago
by
Leon Dietrich
Committed by
Benny Baumann
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
chg: Move local endpoint name retrieval to utility header
parent
49b026a0
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/net/client_factory.hpp
+0
-9
0 additions, 9 deletions
src/net/client_factory.hpp
src/net/socket_utils.cpp
+25
-0
25 additions, 0 deletions
src/net/socket_utils.cpp
src/net/socket_utils.hpp
+10
-0
10 additions, 0 deletions
src/net/socket_utils.hpp
with
35 additions
and
9 deletions
src/net/client_factory.hpp
+
0
−
9
View file @
07274320
...
...
@@ -12,15 +12,6 @@ namespace rmrf::net {
[[
nodiscard
]]
std
::
unique_ptr
<
udp_client
>
client_factory_construct_udp_client
(
const
socketaddr
&
socket_identifier
,
connection_client
::
incomming_data_cb
cb
=
nullptr
);
[[
nodiscard
]]
std
::
unique_ptr
<
tcp_client
>
client_factory_construct_tcp_client
(
const
socketaddr
&
socket_identifier
,
connection_client
::
incomming_data_cb
cb
=
nullptr
);
/**
* This method queries the remote address of a connected client. Please note that only TCP sockets are supported
* at the moment. This operation will fail if an unsupported socket type is provided.
* @brief Get the address of the connected remote client
* @param socket The socket representing the client
* @return The remote socketaddr pair
*/
[[
nodiscard
]]
socketaddr
get_own_address_after_connect
(
const
auto_fd
&
socket
);
/**
* This method directly connects to the given address and returns an invalid pointer if it fails.
* @brief Connect to a remote destination
...
...
This diff is collapsed.
Click to expand it.
src/net/socket_utils.cpp
+
25
−
0
View file @
07274320
...
...
@@ -11,4 +11,29 @@ namespace rmrf::net {
throw
netio_exception
(
"Failed to set socket mode. fcntl resulted in error:"
+
std
::
to_string
(
errno
));
}
}
[[
nodiscard
]]
socketaddr
get_own_address_after_connect
(
const
auto_fd
&
socket
)
{
socketaddr
own_address
;
socklen_t
sa_local_len
=
sizeof
(
sockaddr_storage
);
if
(
getsockname
(
socket
.
get
(),
own_address
.
ptr
(),
&
sa_local_len
)
==
0
)
{
// Update length field after the internal structure was modified
// TODO: Maybe make this an internal method in socketaddr to update the size
own_address
=
own_address
.
ptr
();
}
else
{
switch
(
errno
)
{
case
EBADF
:
case
ENOTSOCK
:
throw
netio_exception
(
"Invalid file descriptor provided to obtain own address. ERRNO: "
+
std
::
to_string
(
errno
));
case
EFAULT
:
case
EINVAL
:
throw
netio_exception
(
"Invlid data structure for information retrival of own socket address provided. ERRNO: "
+
std
::
to_string
(
errno
));
case
ENOBUFS
:
throw
netio_exception
(
"Kernel temporarily out of buffer space to store own address informatio.n ERRNO:."
+
std
::
to_string
(
errno
));
default:
throw
netio_exception
(
"Unexpected error while requesting own socket address. ERRNO: "
+
std
::
to_string
(
errno
));
}
}
return
own_address
;
}
}
This diff is collapsed.
Click to expand it.
src/net/socket_utils.hpp
+
10
−
0
View file @
07274320
#pragma once
#include
"net/async_fd.hpp"
#include
"net/socketaddress.hpp"
namespace
rmrf
::
net
{
/**
...
...
@@ -8,4 +9,13 @@ namespace rmrf::net {
* @param socket The socket to modify
*/
void
make_socket_nonblocking
(
auto_fd
&
socket
);
/**
* This method queries the remote address of a connected client. Please note that only TCP sockets are supported
* at the moment. This operation will fail if an unsupported socket type is provided.
* @brief Get the address of the connected remote client
* @param socket The socket representing the client
* @return The remote socketaddr pair
*/
[[
nodiscard
]]
socketaddr
get_own_address_after_connect
(
const
auto_fd
&
socket
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment