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
087992f1
Unverified
Commit
087992f1
authored
Jul 02, 2020
by
Chao Ma
Committed by
GitHub
Jul 02, 2020
Browse files
update (#1737)
parent
9eb0efcf
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
2 deletions
+22
-2
tests/cpp/socket_communicator_test.cc
tests/cpp/socket_communicator_test.cc
+22
-2
No files found.
tests/cpp/socket_communicator_test.cc
View file @
087992f1
...
@@ -8,6 +8,11 @@
...
@@ -8,6 +8,11 @@
#include <string>
#include <string>
#include <thread>
#include <thread>
#include <vector>
#include <vector>
#include <fstream>
#include <streambuf>
#include <stdlib.h>
#include <time.h>
#include "../src/rpc/network/msg_queue.h"
#include "../src/rpc/network/msg_queue.h"
#include "../src/rpc/network/socket_communicator.h"
#include "../src/rpc/network/socket_communicator.h"
...
@@ -132,6 +137,13 @@ TEST(SocketCommunicatorTest, SendAndRecv) {
...
@@ -132,6 +137,13 @@ TEST(SocketCommunicatorTest, SendAndRecv) {
WSADATA
wsaData
;
WSADATA
wsaData
;
DWORD
retcode
,
exitcode
;
DWORD
retcode
,
exitcode
;
srand
((
unsigned
)
time
(
NULL
));
int
port
=
(
rand
()
%
(
5000
-
3000
+
1
))
+
3000
;
std
::
string
ip_addr
=
"socket://127.0.0.1:"
+
std
::
to_string
(
port
);
std
::
ofstream
out
(
"addr.txt"
);
out
<<
ip_addr
;
out
.
close
();
ASSERT_EQ
(
::
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
wsaData
),
0
);
ASSERT_EQ
(
::
WSAStartup
(
MAKEWORD
(
2
,
2
),
&
wsaData
),
0
);
hThreads
[
0
]
=
::
CreateThread
(
NULL
,
0
,
_ClientThreadFunc
,
NULL
,
0
,
NULL
);
// client
hThreads
[
0
]
=
::
CreateThread
(
NULL
,
0
,
_ClientThreadFunc
,
NULL
,
0
,
NULL
);
// client
...
@@ -153,8 +165,12 @@ TEST(SocketCommunicatorTest, SendAndRecv) {
...
@@ -153,8 +165,12 @@ TEST(SocketCommunicatorTest, SendAndRecv) {
static
void
start_client
()
{
static
void
start_client
()
{
sleep
(
1
);
sleep
(
1
);
std
::
ifstream
t
(
"addr.txt"
);
std
::
string
ip_addr
((
std
::
istreambuf_iterator
<
char
>
(
t
)),
std
::
istreambuf_iterator
<
char
>
());
t
.
close
();
SocketSender
sender
(
kQueueSize
);
SocketSender
sender
(
kQueueSize
);
sender
.
AddReceiver
(
"socket://127.0.0.1:8001"
,
0
);
sender
.
AddReceiver
(
ip_addr
.
c_str
()
,
0
);
sender
.
Connect
();
sender
.
Connect
();
char
*
str_data
=
new
char
[
9
];
char
*
str_data
=
new
char
[
9
];
memcpy
(
str_data
,
"123456789"
,
9
);
memcpy
(
str_data
,
"123456789"
,
9
);
...
@@ -165,8 +181,12 @@ static void start_client() {
...
@@ -165,8 +181,12 @@ static void start_client() {
}
}
static
bool
start_server
()
{
static
bool
start_server
()
{
std
::
ifstream
t
(
"addr.txt"
);
std
::
string
ip_addr
((
std
::
istreambuf_iterator
<
char
>
(
t
)),
std
::
istreambuf_iterator
<
char
>
());
t
.
close
();
SocketReceiver
receiver
(
kQueueSize
);
SocketReceiver
receiver
(
kQueueSize
);
receiver
.
Wait
(
"socket://127.0.0.1:8001"
,
1
);
receiver
.
Wait
(
ip_addr
.
c_str
()
,
1
);
Message
msg
;
Message
msg
;
EXPECT_EQ
(
receiver
.
RecvFrom
(
&
msg
,
0
),
REMOVE_SUCCESS
);
EXPECT_EQ
(
receiver
.
RecvFrom
(
&
msg
,
0
),
REMOVE_SUCCESS
);
receiver
.
Finalize
();
receiver
.
Finalize
();
...
...
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