Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
U
UDP Protocol
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
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
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
BIAS
Receivers
UDP Protocol
Compare revisions
6db61b0ad0499fe596cb6e2176d93cb7e8c68b10 to 4a6f9e51a53137ddc7c133dfac21d38efaa0611f
Compare revisions
Changes are shown as if the
source
revision was being merged into the
target
revision.
Learn more about comparing revisions.
Source
bias/connection-protocols/udp-protocol
Select target project
No results found
4a6f9e51a53137ddc7c133dfac21d38efaa0611f
Select Git revision
Branches
main
old
Tags
v1.0
Swap
Target
bias/connection-protocols/udp-protocol
Select target project
bias/connection-protocols/udp-protocol
1 result
6db61b0ad0499fe596cb6e2176d93cb7e8c68b10
Select Git revision
Branches
main
old
Tags
v1.0
Show changes
Only incoming changes from source
Include changes to target since source was created
Compare
Commits on Source (1)
timeout reduction
· 4a6f9e51
Valerio Pastore
authored
1 year ago
4a6f9e51
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/UDP_Protocol.cpp
+11
-7
11 additions, 7 deletions
src/UDP_Protocol.cpp
with
11 additions
and
7 deletions
src/UDP_Protocol.cpp
View file @
4a6f9e51
...
@@ -26,10 +26,7 @@ UDPProtocol::UDPProtocol(std::string ip, int port) :
...
@@ -26,10 +26,7 @@ UDPProtocol::UDPProtocol(std::string ip, int port) :
srvaddr
.
sin_family
=
AF_INET
;
// IPv4
srvaddr
.
sin_family
=
AF_INET
;
// IPv4
srvaddr
.
sin_addr
.
s_addr
=
inet_addr
(
ip
.
c_str
());
srvaddr
.
sin_addr
.
s_addr
=
inet_addr
(
ip
.
c_str
());
srvaddr
.
sin_port
=
htons
(
this
->
port
);
srvaddr
.
sin_port
=
htons
(
this
->
port
);
struct
timeval
timeout
;
timeout
.
tv_sec
=
5
;
timeout
.
tv_usec
=
0
;
setsockopt
(
srv_sock
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
));
}
}
UDPProtocol
::~
UDPProtocol
()
{
UDPProtocol
::~
UDPProtocol
()
{
...
@@ -42,7 +39,8 @@ int UDPProtocol::receiveAtLeastHeaderSizeBytes(uint8_t *buff, int headerSize,
...
@@ -42,7 +39,8 @@ int UDPProtocol::receiveAtLeastHeaderSizeBytes(uint8_t *buff, int headerSize,
socklen_t
len
=
sizeof
(
cliaddr
);
socklen_t
len
=
sizeof
(
cliaddr
);
while
(
bytercv
<
headerSize
)
{
while
(
bytercv
<
headerSize
)
{
int
rcv
=
recvfrom
(
srv_sock
,
&
buff
[
bytercv
],
packetSize
+
1
,
// +1 to recognized if there are more bytes than expected
int
rcv
=
recvfrom
(
srv_sock
,
&
buff
[
bytercv
],
packetSize
+
1
,
// +1 to recognized if there are more bytes than expected
MSG_WAITFORONE
,
(
struct
sockaddr
*
)
&
cliaddr
,
&
len
);
0
,
(
struct
sockaddr
*
)
&
cliaddr
,
&
len
);
bytercv
+=
rcv
;
bytercv
+=
rcv
;
if
(
rcv
<
0
)
{
if
(
rcv
<
0
)
{
return
-
1
;
return
-
1
;
...
@@ -132,9 +130,15 @@ int UDPProtocol::connectToClient() {
...
@@ -132,9 +130,15 @@ int UDPProtocol::connectToClient() {
// Set timeout to the socket
// Set timeout to the socket
struct
timeval
tv
;
struct
timeval
tv
;
tv
.
tv_sec
=
std
::
numeric_limits
<
time_t
>::
max
()
;
tv
.
tv_sec
=
1
;
tv
.
tv_usec
=
0
;
tv
.
tv_usec
=
0
;
setsockopt
(
srv_sock
,
SOL_SOCKET
,
SO_RCVTIMEO
,
(
const
char
*
)
&
tv
,
sizeof
tv
);
if
(
setsockopt
(
srv_sock
,
SOL_SOCKET
,
SO_RCVTIMEO
,
(
const
char
*
)
&
tv
,
sizeof
tv
)
<
0
)
{
time_t
now
=
time
(
nullptr
);
std
::
cerr
<<
"["
<<
std
::
put_time
(
localtime
(
&
now
),
"%Y-%m-%d %H:%M:%S"
)
<<
"]
\t
[UDP Receiver]
\t
"
<<
"Error setting timeout to socket"
<<
std
::
endl
;
return
-
1
;
}
// Bind the socket with the server address
// Bind the socket with the server address
if
(
bind
(
srv_sock
,
(
const
struct
sockaddr
*
)
&
srvaddr
,
sizeof
(
srvaddr
))
if
(
bind
(
srv_sock
,
(
const
struct
sockaddr
*
)
&
srvaddr
,
sizeof
(
srvaddr
))
...
...
This diff is collapsed.
Click to expand it.