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
3a11d261
Unverified
Commit
3a11d261
authored
Jun 03, 2019
by
Chao Ma
Committed by
GitHub
Jun 03, 2019
Browse files
update (#593)
parent
01a4cc5b
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
14 deletions
+8
-14
tests/cpp/socket_communicator_test.cc
tests/cpp/socket_communicator_test.cc
+8
-14
No files found.
tests/cpp/socket_communicator_test.cc
View file @
3a11d261
...
...
@@ -21,19 +21,13 @@ bool start_server();
#include <unistd.h>
TEST
(
SocketCommunicatorTest
,
SendAndRecv
)
{
int
pid
=
fork
();
ASSERT_GE
(
pid
,
0
);
if
(
pid
>
0
)
{
EXPECT_TRUE
(
start_server
());
}
else
{
start_client
();
}
std
::
thread
client_thread
(
start_client
);
start_server
();
client_thread
.
join
();
}
#else // WIN32
// Win32 doesn't have a fork() equivalent so use threads instead.
#include <windows.h>
#include <winsock2.h>
...
...
@@ -79,12 +73,12 @@ TEST(SocketCommunicatorTest, SendAndRecv) {
#endif // WIN32
void
start_client
()
{
const
char
*
msg
=
"
0
123456789"
;
const
char
*
msg
=
"123456789"
;
sleep
(
1
);
SocketSender
sender
;
sender
.
AddReceiver
(
"127.0.0.1"
,
2049
,
0
);
sender
.
Connect
();
sender
.
Send
(
msg
,
10
,
0
);
sender
.
Send
(
msg
,
9
,
0
);
sender
.
Finalize
();
}
...
...
@@ -92,8 +86,8 @@ bool start_server() {
char
serbuff
[
10
];
memset
(
serbuff
,
'\0'
,
10
);
SocketReceiver
receiver
;
receiver
.
Wait
(
"127.0.0.1"
,
2049
,
1
,
500
);
receiver
.
Recv
(
serbuff
,
10
);
receiver
.
Wait
(
"127.0.0.1"
,
2049
,
1
,
500
*
1024
);
receiver
.
Recv
(
serbuff
,
9
);
receiver
.
Finalize
();
return
string
(
"
0
123456789"
)
==
string
(
serbuff
);
return
string
(
"123456789"
)
==
string
(
serbuff
);
}
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