Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
U
UERANSIM
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Libraries
UERANSIM
Commits
801d2fb3
Commit
801d2fb3
authored
Dec 03, 2021
by
Louis Royer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Avoid starvation
parent
003d7e9d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
4 deletions
+14
-4
src/lib/udp/server.cpp
src/lib/udp/server.cpp
+1
-2
src/utils/network.cpp
src/utils/network.cpp
+13
-2
No files found.
src/lib/udp/server.cpp
View file @
801d2fb3
...
...
@@ -27,8 +27,7 @@ UdpServer::UdpServer(const std::string &address, uint16_t port): sockets{}
int
UdpServer
::
Receive
(
uint8_t
*
buffer
,
size_t
bufferSize
,
int
timeoutMs
,
InetAddress
&
outPeerAddress
)
{
// Use the first socket ready for receiving data
// Warning: this may lead to starvation since there is no round robin implemented yet in `Socket::Select`
// Choose at random a ready socket for receiving data
std
::
vector
<
Socket
>
ws
;
return
Socket
::
Select
(
sockets
,
ws
,
timeoutMs
).
receive
(
buffer
,
bufferSize
,
0
,
outPeerAddress
);
}
...
...
src/utils/network.cpp
View file @
801d2fb3
...
...
@@ -13,6 +13,7 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <random>
#include <stdexcept>
#include <sys/socket.h>
#include <sys/types.h>
...
...
@@ -273,10 +274,20 @@ Socket Socket::Select(const std::vector<Socket> &readSockets, const std::vector<
std
::
vector
<
Socket
>
rs
,
ws
;
Select
(
readSockets
,
writeSockets
,
rs
,
ws
,
timeout
);
// Return a socket choosen at random from selection
// to avoid starvation
std
::
default_random_engine
generator
;
if
(
!
rs
.
empty
())
return
rs
[
0
];
{
std
::
uniform_int_distribution
<
int
>
drs
(
0
,
rs
.
size
()
-
1
);
return
rs
[
drs
(
generator
)];
}
if
(
!
ws
.
empty
())
return
rs
[
0
];
{
std
::
uniform_int_distribution
<
int
>
dws
(
0
,
ws
.
size
()
-
1
);
return
rs
[
dws
(
generator
)];
}
return
{};
}
...
...
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