Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
069068aa
Unverified
Commit
069068aa
authored
Jul 27, 2022
by
Rhett Ying
Committed by
GitHub
Jul 27, 2022
Browse files
[Log] fix confusing error log in TCPSocket::Bind() (#4299)
* [Log] fix confusing error log in TCPSocket::Bind() * fix lint
parent
4f797295
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
5 deletions
+21
-5
src/rpc/network/tcp_socket.cc
src/rpc/network/tcp_socket.cc
+13
-5
tests/cpp/socket_communicator_test.cc
tests/cpp/socket_communicator_test.cc
+8
-0
No files found.
src/rpc/network/tcp_socket.cc
View file @
069068aa
...
@@ -64,14 +64,22 @@ bool TCPSocket::Bind(const char * ip, int port) {
...
@@ -64,14 +64,22 @@ bool TCPSocket::Bind(const char * ip, int port) {
SAI
sa_server
;
SAI
sa_server
;
sa_server
.
sin_family
=
AF_INET
;
sa_server
.
sin_family
=
AF_INET
;
sa_server
.
sin_port
=
htons
(
port
);
sa_server
.
sin_port
=
htons
(
port
);
int
retval
=
0
;
int
ret
=
0
;
ret
=
inet_pton
(
AF_INET
,
ip
,
&
sa_server
.
sin_addr
);
if
(
ret
==
0
)
{
LOG
(
ERROR
)
<<
"Invalid IP: "
<<
ip
;
return
false
;
}
else
if
(
ret
<
0
)
{
LOG
(
ERROR
)
<<
"Failed to convert ["
<<
ip
<<
"] to binary form, error: "
<<
strerror
(
errno
);
return
false
;
}
do
{
// retry if EINTR failure appears
do
{
// retry if EINTR failure appears
if
(
0
<
inet_pton
(
AF_INET
,
ip
,
&
sa_server
.
sin_addr
)
&&
if
(
0
<=
(
ret
=
bind
(
socket_
,
reinterpret_cast
<
SA
*>
(
&
sa_server
),
0
<=
(
retval
=
bind
(
socket_
,
reinterpret_cast
<
SA
*>
(
&
sa_server
),
sizeof
(
sa_server
))))
{
sizeof
(
sa_server
))))
{
return
true
;
return
true
;
}
}
}
while
(
ret
val
==
-
1
&&
errno
==
EINTR
);
}
while
(
ret
==
-
1
&&
errno
==
EINTR
);
LOG
(
ERROR
)
<<
"Failed bind on "
<<
ip
<<
":"
<<
port
<<
" , error: "
<<
strerror
(
errno
);
LOG
(
ERROR
)
<<
"Failed bind on "
<<
ip
<<
":"
<<
port
<<
" , error: "
<<
strerror
(
errno
);
return
false
;
return
false
;
...
...
tests/cpp/socket_communicator_test.cc
View file @
069068aa
...
@@ -154,6 +154,14 @@ void start_server(int id) {
...
@@ -154,6 +154,14 @@ void start_server(int id) {
receiver
.
Finalize
();
receiver
.
Finalize
();
}
}
TEST
(
SocketCommunicatorTest
,
TCPSocketBind
)
{
dgl
::
network
::
TCPSocket
socket
;
testing
::
internal
::
CaptureStderr
();
EXPECT_EQ
(
socket
.
Bind
(
"127.0.0"
,
50001
),
false
);
const
std
::
string
stderr
=
testing
::
internal
::
GetCapturedStderr
();
EXPECT_NE
(
stderr
.
find
(
"Invalid IP: 127.0.0"
),
std
::
string
::
npos
);
}
#else
#else
#include <windows.h>
#include <windows.h>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment