Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
Grpc
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
4f61528b
Commit
4f61528b
authored
9 years ago
by
yang-g
Browse files
Options
Downloads
Patches
Plain Diff
Support two clients calling start simultaneously
parent
c9c69e27
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
test/cpp/interop/reconnect_interop_server.cc
+32
-3
32 additions, 3 deletions
test/cpp/interop/reconnect_interop_server.cc
with
32 additions
and
3 deletions
test/cpp/interop/reconnect_interop_server.cc
+
32
−
3
View file @
4f61528b
...
@@ -31,9 +31,10 @@
...
@@ -31,9 +31,10 @@
*
*
*/
*/
#include
<condition_variable>
#include
<memory>
#include
<memory>
#include
<mutex>
#include
<sstream>
#include
<sstream>
#include
<thread>
#include
<signal.h>
#include
<signal.h>
#include
<unistd.h>
#include
<unistd.h>
...
@@ -47,7 +48,6 @@
...
@@ -47,7 +48,6 @@
#include
<grpc++/server_context.h>
#include
<grpc++/server_context.h>
#include
<grpc++/server_credentials.h>
#include
<grpc++/server_credentials.h>
#include
<grpc++/status.h>
#include
<grpc++/status.h>
#include
<grpc++/stream.h>
#include
"test/core/util/reconnect_server.h"
#include
"test/core/util/reconnect_server.h"
#include
"test/cpp/util/test_config.h"
#include
"test/cpp/util/test_config.h"
#include
"test/proto/test.grpc.pb.h"
#include
"test/proto/test.grpc.pb.h"
...
@@ -76,7 +76,8 @@ static bool got_sigint = false;
...
@@ -76,7 +76,8 @@ static bool got_sigint = false;
class
ReconnectServiceImpl
:
public
ReconnectService
::
Service
{
class
ReconnectServiceImpl
:
public
ReconnectService
::
Service
{
public:
public:
explicit
ReconnectServiceImpl
(
int
retry_port
)
:
retry_port_
(
retry_port
)
{
explicit
ReconnectServiceImpl
(
int
retry_port
)
:
retry_port_
(
retry_port
),
serving_
(
false
),
shutdown_
(
false
)
{
reconnect_server_init
(
&
tcp_server_
);
reconnect_server_init
(
&
tcp_server_
);
}
}
...
@@ -89,6 +90,16 @@ class ReconnectServiceImpl : public ReconnectService::Service {
...
@@ -89,6 +90,16 @@ class ReconnectServiceImpl : public ReconnectService::Service {
void
Poll
(
int
seconds
)
{
reconnect_server_poll
(
&
tcp_server_
,
seconds
);
}
void
Poll
(
int
seconds
)
{
reconnect_server_poll
(
&
tcp_server_
,
seconds
);
}
Status
Start
(
ServerContext
*
context
,
const
Empty
*
request
,
Empty
*
response
)
{
Status
Start
(
ServerContext
*
context
,
const
Empty
*
request
,
Empty
*
response
)
{
std
::
unique_lock
<
std
::
mutex
>
lock
(
mu_
);
while
(
serving_
&&
!
shutdown_
)
{
cv_
.
wait
(
lock
);
}
if
(
shutdown_
)
{
return
Status
(
grpc
::
StatusCode
::
UNAVAILABLE
,
"shutting down"
);
}
serving_
=
true
;
lock
.
unlock
();
if
(
!
tcp_server_
.
tcp_server
)
{
if
(
!
tcp_server_
.
tcp_server
)
{
reconnect_server_start
(
&
tcp_server_
,
retry_port_
);
reconnect_server_start
(
&
tcp_server_
,
retry_port_
);
}
else
{
}
else
{
...
@@ -102,6 +113,11 @@ class ReconnectServiceImpl : public ReconnectService::Service {
...
@@ -102,6 +113,11 @@ class ReconnectServiceImpl : public ReconnectService::Service {
// extract timestamps and set response
// extract timestamps and set response
Verify
(
response
);
Verify
(
response
);
reconnect_server_clear_timestamps
(
&
tcp_server_
);
reconnect_server_clear_timestamps
(
&
tcp_server_
);
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mu_
);
serving_
=
false
;
}
cv_
.
notify_one
();
return
Status
::
OK
;
return
Status
::
OK
;
}
}
...
@@ -130,9 +146,21 @@ class ReconnectServiceImpl : public ReconnectService::Service {
...
@@ -130,9 +146,21 @@ class ReconnectServiceImpl : public ReconnectService::Service {
response
->
set_passed
(
passed
);
response
->
set_passed
(
passed
);
}
}
void
Shutdown
()
{
{
std
::
lock_guard
<
std
::
mutex
>
lock
(
mu_
);
shutdown_
=
true
;
}
cv_
.
notify_all
();
}
private
:
private
:
int
retry_port_
;
int
retry_port_
;
reconnect_server
tcp_server_
;
reconnect_server
tcp_server_
;
bool
serving_
;
bool
shutdown_
;
std
::
mutex
mu_
;
std
::
condition_variable
cv_
;
};
};
void
RunServer
()
{
void
RunServer
()
{
...
@@ -149,6 +177,7 @@ void RunServer() {
...
@@ -149,6 +177,7 @@ void RunServer() {
while
(
!
got_sigint
)
{
while
(
!
got_sigint
)
{
service
.
Poll
(
5
);
service
.
Poll
(
5
);
}
}
service
.
Shutdown
();
}
}
static
void
sigint_handler
(
int
x
)
{
got_sigint
=
true
;
}
static
void
sigint_handler
(
int
x
)
{
got_sigint
=
true
;
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment