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
dlib
Commits
39852f09
"vscode:/vscode.git/clone" did not exist on "41b4180950cf490bd2ab9aa56672b676bc0f0e02"
Commit
39852f09
authored
Feb 21, 2022
by
Davis King
Browse files
fix race condition in sockets unit test
parent
c7ed14c9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
3 deletions
+27
-3
dlib/test/sockets.cpp
dlib/test/sockets.cpp
+27
-3
No files found.
dlib/test/sockets.cpp
View file @
39852f09
...
...
@@ -25,6 +25,7 @@ namespace {
const
char
magic_num
=
42
;
const
int
min_bytes_sent
=
10000
;
int
assigned_port
;
const
int
num_test_connections
=
10
;
logger
dlog
(
"test.sockets"
);
...
...
@@ -36,7 +37,8 @@ namespace {
serv
(
)
:
error_occurred
(
false
),
got_connections
(
false
)
got_connections
(
false
),
s
(
m
)
{}
void
on_listening_port_assigned
(
...
...
@@ -75,11 +77,33 @@ namespace {
}
got_connections
=
true
;
dlog
<<
LINFO
<<
"in serv::on_connect(): on_connect ending"
;
auto_mutex
M
(
m
);
++
num_connections
;
s
.
broadcast
();
}
bool
error_occurred
;
bool
got_connections
;
double
tag
;
void
wait_for_all_connections_to_close
()
{
auto_mutex
M
(
m
);
while
(
num_connections
!=
num_test_connections
)
{
// something has gone wrong if it takes more than 10 seconds. So just end and let
// the test fail in that case.
s
.
wait_or_timeout
(
10000
);
}
}
private:
dlib
::
mutex
m
;
dlib
::
signaler
s
;
int
num_connections
=
0
;
};
// ----------------------------------------------------------------------------------------
...
...
@@ -94,7 +118,7 @@ namespace {
serv
&
srv_
)
:
srv
(
srv_
)
{
for
(
int
i
=
0
;
i
<
10
;
++
i
)
for
(
int
i
=
0
;
i
<
num_test_connections
;
++
i
)
register_thread
(
*
this
,
&
thread_container
::
thread_proc
);
// start up the threads
...
...
@@ -211,7 +235,7 @@ namespace {
// wait until all the sending threads have ended
stuff
.
wait
();
srv
.
wait_for_all_connections_to_close
();
srv
.
clear
();
if
(
srv
.
error_occurred
)
...
...
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