Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
90ae4d83
Commit
90ae4d83
authored
Oct 20, 2012
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Made the tests use the bsp_listen_dynamic_port() as well as bsp_listen().
parent
d38723f4
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
66 additions
and
16 deletions
+66
-16
bsp.cpp
dlib/test/bsp.cpp
+66
-16
No files found.
dlib/test/bsp.cpp
View file @
90ae4d83
...
...
@@ -4,6 +4,7 @@
#include <dlib/bsp.h>
#include <dlib/threads.h>
#include <dlib/pipe.h>
#include "tester.h"
...
...
@@ -52,6 +53,55 @@ namespace
}
// ----------------------------------------------------------------------------------------
template
<
typename
funct
>
struct
callfunct_helper_pn
{
callfunct_helper_pn
(
funct
f_
,
int
port_
,
bool
&
error_occurred_
,
dlib
::
pipe
<
unsigned
short
>&
port_pipe_
)
:
f
(
f_
),
port
(
port_
),
error_occurred
(
error_occurred_
),
port_pipe
(
port_pipe_
)
{}
funct
f
;
int
port
;
bool
&
error_occurred
;
dlib
::
pipe
<
unsigned
short
>&
port_pipe
;
struct
helper
{
helper
(
dlib
::
pipe
<
unsigned
short
>&
port_pipe_
)
:
port_pipe
(
port_pipe_
)
{}
dlib
::
pipe
<
unsigned
short
>&
port_pipe
;
void
operator
()
(
unsigned
short
p
)
{
port_pipe
.
enqueue
(
p
);
}
};
void
operator
()
(
)
const
{
try
{
bsp_listen_dynamic_port
(
port
,
helper
(
port_pipe
),
f
);
}
catch
(
exception
&
e
)
{
dlog
<<
LERROR
<<
"error calling bsp_listen_dynamic_port(): "
<<
e
.
what
();
error_occurred
=
true
;
}
}
};
template
<
typename
funct
>
callfunct_helper_pn
<
funct
>
callfunct
(
funct
f
,
int
port
,
bool
&
error_occurred
,
dlib
::
pipe
<
unsigned
short
>&
port_pipe
)
{
return
callfunct_helper_pn
<
funct
>
(
f
,
port
,
error_occurred
,
port_pipe
);
}
// ----------------------------------------------------------------------------------------
void
sum_array_driver
(
...
...
@@ -227,19 +277,19 @@ namespace
print_spinner
();
bool
error_occurred
=
false
;
{
thread_function
t1
(
callfunct
(
test3_job
,
12345
,
error_occurred
));
thread_function
t2
(
callfunct
(
test3_job
,
12346
,
error_occurred
));
thread_function
t3
(
callfunct
(
test3_job
,
12347
,
error_occurred
));
dlib
::
pipe
<
unsigned
short
>
ports
(
5
);
thread_function
t1
(
callfunct
(
test3_job
,
12345
,
error_occurred
,
ports
));
thread_function
t2
(
callfunct
(
test3_job
,
0
,
error_occurred
,
ports
));
thread_function
t3
(
callfunct
(
test3_job
,
12347
,
error_occurred
,
ports
));
// wait a little bit for the threads to start up
dlib
::
sleep
(
200
);
try
{
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>
hosts
;
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12345
));
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12346
));
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12347
));
unsigned
short
port
;
ports
.
dequeue
(
port
);
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
port
));
dlog
<<
LINFO
<<
"PORT: "
<<
port
;
ports
.
dequeue
(
port
);
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
port
));
dlog
<<
LINFO
<<
"PORT: "
<<
port
;
ports
.
dequeue
(
port
);
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
port
));
dlog
<<
LINFO
<<
"PORT: "
<<
port
;
int
result
=
0
;
const
int
expected
=
1
+
2
+
3
+
0
+
2
+
3
+
0
+
1
+
3
+
0
+
1
+
2
;
bsp_connect
(
hosts
,
test3_job_driver
,
dlib
::
ref
(
result
));
...
...
@@ -319,19 +369,19 @@ namespace
print_spinner
();
bool
error_occurred
=
false
;
{
thread_function
t1
(
callfunct
(
test4_job
,
12345
,
error_occurred
));
thread_function
t2
(
callfunct
(
test4_job
,
12346
,
error_occurred
));
thread_function
t3
(
callfunct
(
test4_job
,
12347
,
error_occurred
));
dlib
::
pipe
<
unsigned
short
>
ports
(
5
);
thread_function
t1
(
callfunct
(
test4_job
,
0
,
error_occurred
,
ports
));
thread_function
t2
(
callfunct
(
test4_job
,
0
,
error_occurred
,
ports
));
thread_function
t3
(
callfunct
(
test4_job
,
0
,
error_occurred
,
ports
));
// wait a little bit for the threads to start up
dlib
::
sleep
(
200
);
try
{
std
::
vector
<
std
::
pair
<
std
::
string
,
unsigned
short
>
>
hosts
;
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12345
));
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12346
));
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
12347
));
unsigned
short
port
;
ports
.
dequeue
(
port
);
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
port
));
dlog
<<
LINFO
<<
"PORT: "
<<
port
;
ports
.
dequeue
(
port
);
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
port
));
dlog
<<
LINFO
<<
"PORT: "
<<
port
;
ports
.
dequeue
(
port
);
hosts
.
push_back
(
make_pair
(
"127.0.0.1"
,
port
));
dlog
<<
LINFO
<<
"PORT: "
<<
port
;
int
result
=
0
;
const
int
expected
=
1
+
2
+
3
+
0
+
2
+
3
+
0
+
1
+
3
+
0
+
1
+
2
;
bsp_connect
(
hosts
,
test4_job_driver
,
dlib
::
ref
(
result
));
...
...
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