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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
tci-gateway-module
Grpc
Commits
5bbd8186
Commit
5bbd8186
authored
Jul 21, 2015
by
Jan Tattermusch
Browse files
Options
Downloads
Patches
Plain Diff
refactor server call handlers
parent
7f23a754
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
+13
-11
13 additions, 11 deletions
src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
src/csharp/Grpc.Core/Server.cs
+12
-11
12 additions, 11 deletions
src/csharp/Grpc.Core/Server.cs
with
25 additions
and
22 deletions
src/csharp/Grpc.Core/Internal/ServerCallHandler.cs
+
13
−
11
View file @
5bbd8186
...
...
@@ -42,7 +42,7 @@ namespace Grpc.Core.Internal
{
internal
interface
IServerCallHandler
{
Task
HandleCall
(
string
methodName
,
CallSafeHandle
call
,
GrpcEnvironment
environment
);
Task
HandleCall
(
ServerRpcNew
newRpc
,
GrpcEnvironment
environment
);
}
internal
class
UnaryServerCallHandler
<
TRequest
,
TResponse
>
:
IServerCallHandler
...
...
@@ -58,14 +58,14 @@ namespace Grpc.Core.Internal
this
.
handler
=
handler
;
}
public
async
Task
HandleCall
(
string
methodName
,
CallSafeHandle
call
,
GrpcEnvironment
environment
)
public
async
Task
HandleCall
(
ServerRpcNew
newRpc
,
GrpcEnvironment
environment
)
{
var
asyncCall
=
new
AsyncCallServer
<
TRequest
,
TResponse
>(
method
.
ResponseMarshaller
.
Serializer
,
method
.
RequestMarshaller
.
Deserializer
,
environment
);
asyncCall
.
Initialize
(
c
all
);
asyncCall
.
Initialize
(
newRpc
.
C
all
);
var
finishedTask
=
asyncCall
.
ServerSideCallAsync
();
var
requestStream
=
new
ServerRequestStream
<
TRequest
,
TResponse
>(
asyncCall
);
var
responseStream
=
new
ServerResponseStream
<
TRequest
,
TResponse
>(
asyncCall
);
...
...
@@ -111,14 +111,14 @@ namespace Grpc.Core.Internal
this
.
handler
=
handler
;
}
public
async
Task
HandleCall
(
string
methodName
,
CallSafeHandle
call
,
GrpcEnvironment
environment
)
public
async
Task
HandleCall
(
ServerRpcNew
newRpc
,
GrpcEnvironment
environment
)
{
var
asyncCall
=
new
AsyncCallServer
<
TRequest
,
TResponse
>(
method
.
ResponseMarshaller
.
Serializer
,
method
.
RequestMarshaller
.
Deserializer
,
environment
);
asyncCall
.
Initialize
(
c
all
);
asyncCall
.
Initialize
(
newRpc
.
C
all
);
var
finishedTask
=
asyncCall
.
ServerSideCallAsync
();
var
requestStream
=
new
ServerRequestStream
<
TRequest
,
TResponse
>(
asyncCall
);
var
responseStream
=
new
ServerResponseStream
<
TRequest
,
TResponse
>(
asyncCall
);
...
...
@@ -165,14 +165,14 @@ namespace Grpc.Core.Internal
this
.
handler
=
handler
;
}
public
async
Task
HandleCall
(
string
methodName
,
CallSafeHandle
call
,
GrpcEnvironment
environment
)
public
async
Task
HandleCall
(
ServerRpcNew
newRpc
,
GrpcEnvironment
environment
)
{
var
asyncCall
=
new
AsyncCallServer
<
TRequest
,
TResponse
>(
method
.
ResponseMarshaller
.
Serializer
,
method
.
RequestMarshaller
.
Deserializer
,
environment
);
asyncCall
.
Initialize
(
c
all
);
asyncCall
.
Initialize
(
newRpc
.
C
all
);
var
finishedTask
=
asyncCall
.
ServerSideCallAsync
();
var
requestStream
=
new
ServerRequestStream
<
TRequest
,
TResponse
>(
asyncCall
);
var
responseStream
=
new
ServerResponseStream
<
TRequest
,
TResponse
>(
asyncCall
);
...
...
@@ -222,14 +222,14 @@ namespace Grpc.Core.Internal
this
.
handler
=
handler
;
}
public
async
Task
HandleCall
(
string
methodName
,
CallSafeHandle
call
,
GrpcEnvironment
environment
)
public
async
Task
HandleCall
(
ServerRpcNew
newRpc
,
GrpcEnvironment
environment
)
{
var
asyncCall
=
new
AsyncCallServer
<
TRequest
,
TResponse
>(
method
.
ResponseMarshaller
.
Serializer
,
method
.
RequestMarshaller
.
Deserializer
,
environment
);
asyncCall
.
Initialize
(
c
all
);
asyncCall
.
Initialize
(
newRpc
.
C
all
);
var
finishedTask
=
asyncCall
.
ServerSideCallAsync
();
var
requestStream
=
new
ServerRequestStream
<
TRequest
,
TResponse
>(
asyncCall
);
var
responseStream
=
new
ServerResponseStream
<
TRequest
,
TResponse
>(
asyncCall
);
...
...
@@ -259,13 +259,15 @@ namespace Grpc.Core.Internal
internal
class
NoSuchMethodCallHandler
:
IServerCallHandler
{
public
async
Task
HandleCall
(
string
methodName
,
CallSafeHandle
call
,
GrpcEnvironment
environment
)
public
static
readonly
NoSuchMethodCallHandler
Instance
=
new
NoSuchMethodCallHandler
();
public
async
Task
HandleCall
(
ServerRpcNew
newRpc
,
GrpcEnvironment
environment
)
{
// We don't care about the payload type here.
var
asyncCall
=
new
AsyncCallServer
<
byte
[],
byte
[
]>
(
(
payload
)
=>
payload
,
(
payload
)
=>
payload
,
environment
);
asyncCall
.
Initialize
(
c
all
);
asyncCall
.
Initialize
(
newRpc
.
C
all
);
var
finishedTask
=
asyncCall
.
ServerSideCallAsync
();
var
requestStream
=
new
ServerRequestStream
<
byte
[],
byte
[
]>
(
asyncCall
);
var
responseStream
=
new
ServerResponseStream
<
byte
[],
byte
[
]>
(
asyncCall
);
...
...
This diff is collapsed.
Click to expand it.
src/csharp/Grpc.Core/Server.cs
+
12
−
11
View file @
5bbd8186
...
...
@@ -218,16 +218,16 @@ namespace Grpc.Core
/// <summary>
/// Selects corresponding handler for given call and handles the call.
/// </summary>
private
async
Task
InvokeCall
Handle
r
(
Call
SafeHandle
call
,
string
method
)
private
async
Task
HandleCall
Async
(
ServerRpcNew
newRpc
)
{
try
{
IServerCallHandler
callHandler
;
if
(!
callHandlers
.
TryGetValue
(
m
ethod
,
out
callHandler
))
if
(!
callHandlers
.
TryGetValue
(
newRpc
.
M
ethod
,
out
callHandler
))
{
callHandler
=
new
NoSuchMethodCallHandler
()
;
callHandler
=
NoSuchMethodCallHandler
.
Instance
;
}
await
callHandler
.
HandleCall
(
method
,
call
,
environment
);
await
callHandler
.
HandleCall
(
newRpc
,
environment
);
}
catch
(
Exception
e
)
{
...
...
@@ -240,14 +240,15 @@ namespace Grpc.Core
/// </summary>
private
void
HandleNewServerRpc
(
bool
success
,
BatchContextSafeHandle
ctx
)
{
// TODO: handle error
if
(
success
)
{
ServerRpcNew
newRpc
=
ctx
.
GetServerRpcNew
();
// after server shutdown, the callback returns with null call
if
(!
newRpc
.
Call
.
IsInvalid
)
{
Task
.
Run
(
async
()
=>
await
InvokeCallHandler
(
newRpc
.
Call
,
newRpc
.
Method
));
Task
.
Run
(
async
()
=>
await
HandleCallAsync
(
newRpc
));
}
}
AllowOneRpc
();
...
...
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
sign in
to comment