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
74c38a1f
Unverified
Commit
74c38a1f
authored
Mar 21, 2021
by
Da Zheng
Committed by
GitHub
Mar 21, 2021
Browse files
Print error messages when using TCP socket (#2763)
* print error messages. * fix.
parent
bb542066
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
5 deletions
+6
-5
src/rpc/network/tcp_socket.cc
src/rpc/network/tcp_socket.cc
+6
-5
No files found.
src/rpc/network/tcp_socket.cc
View file @
74c38a1f
...
@@ -28,13 +28,13 @@ TCPSocket::TCPSocket() {
...
@@ -28,13 +28,13 @@ TCPSocket::TCPSocket() {
// init socket
// init socket
socket_
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
);
socket_
=
socket
(
AF_INET
,
SOCK_STREAM
,
IPPROTO_TCP
);
if
(
socket_
<
0
)
{
if
(
socket_
<
0
)
{
LOG
(
FATAL
)
<<
"Can't create new socket. Err
no=
"
<<
errno
;
LOG
(
FATAL
)
<<
"Can't create new socket. Err
or:
"
<<
strerror
(
errno
)
;
}
}
#ifndef _WIN32
#ifndef _WIN32
// This is to make sure the same port can be reused right after the socket is closed.
// This is to make sure the same port can be reused right after the socket is closed.
int
enable
=
1
;
int
enable
=
1
;
if
(
setsockopt
(
socket_
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
enable
,
sizeof
(
int
))
<
0
)
{
if
(
setsockopt
(
socket_
,
SOL_SOCKET
,
SO_REUSEADDR
,
&
enable
,
sizeof
(
int
))
<
0
)
{
LOG
(
WARNING
)
<<
"cannot make the socket reusable. Err
no=
"
<<
errno
;
LOG
(
WARNING
)
<<
"cannot make the socket reusable. Err
or:
"
<<
strerror
(
errno
)
;
}
}
#endif // _WIN32
#endif // _WIN32
}
}
...
@@ -73,7 +73,7 @@ bool TCPSocket::Bind(const char * ip, int port) {
...
@@ -73,7 +73,7 @@ bool TCPSocket::Bind(const char * ip, int port) {
}
}
}
while
(
retval
==
-
1
&&
errno
==
EINTR
);
}
while
(
retval
==
-
1
&&
errno
==
EINTR
);
LOG
(
ERROR
)
<<
"Failed bind on "
<<
ip
<<
":"
<<
port
<<
" ,err
no=
"
<<
errno
;
LOG
(
ERROR
)
<<
"Failed bind on "
<<
ip
<<
":"
<<
port
<<
" ,
err
or:
"
<<
strerror
(
errno
)
;
return
false
;
return
false
;
}
}
...
@@ -85,7 +85,7 @@ bool TCPSocket::Listen(int max_connection) {
...
@@ -85,7 +85,7 @@ bool TCPSocket::Listen(int max_connection) {
}
}
}
while
(
retval
==
-
1
&&
errno
==
EINTR
);
}
while
(
retval
==
-
1
&&
errno
==
EINTR
);
LOG
(
ERROR
)
<<
"Failed listen on socket fd: "
<<
socket_
<<
" ,err
no=
"
<<
errno
;
LOG
(
ERROR
)
<<
"Failed listen on socket fd: "
<<
socket_
<<
" ,
err
or:
"
<<
strerror
(
errno
)
;
return
false
;
return
false
;
}
}
...
@@ -100,7 +100,8 @@ bool TCPSocket::Accept(TCPSocket * socket, std::string * ip, int * port) {
...
@@ -100,7 +100,8 @@ bool TCPSocket::Accept(TCPSocket * socket, std::string * ip, int * port) {
if
(
sock_client
<
0
)
{
if
(
sock_client
<
0
)
{
LOG
(
ERROR
)
<<
"Failed accept connection on "
<<
*
ip
<<
":"
<<
*
port
LOG
(
ERROR
)
<<
"Failed accept connection on "
<<
*
ip
<<
":"
<<
*
port
<<
" ,errno="
<<
errno
<<
(
errno
==
EAGAIN
?
" SO_RCVTIMEO timeout reached"
:
""
);
<<
", error: "
<<
strerror
(
errno
)
<<
(
errno
==
EAGAIN
?
" SO_RCVTIMEO timeout reached"
:
""
);
return
false
;
return
false
;
}
}
...
...
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