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
23f19d88
Commit
23f19d88
authored
Jul 18, 2017
by
Muxi Yan
Browse files
Options
Downloads
Patches
Plain Diff
Move closure to a method of GRPCCall
parent
8ad304ba
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/objective-c/GRPCClient/GRPCCall.m
+33
-35
33 additions, 35 deletions
src/objective-c/GRPCClient/GRPCCall.m
with
33 additions
and
35 deletions
src/objective-c/GRPCClient/GRPCCall.m
+
33
−
35
View file @
23f19d88
...
@@ -415,40 +415,26 @@ static NSString * const kBearerPrefix = @"Bearer ";
...
@@ -415,40 +415,26 @@ static NSString * const kBearerPrefix = @"Bearer ";
#pragma mark GRXWriter implementation
#pragma mark GRXWriter implementation
-
(
void
)
startWithWriteable
:(
id
<
GRXWriteable
>
)
writeable
{
-
(
void
)
startCallWithWriteable
:(
id
<
GRXWriteable
>
)
writeable
{
@synchronized
(
self
)
{
_responseWriteable
=
[[
GRXConcurrentWriteable
alloc
]
initWithWriteable
:
writeable
_state
=
GRXWriterStateStarted
;
dispatchQueue:
_responseQueue
];
}
// Create a retain cycle so that this instance lives until the RPC finishes (or is cancelled).
// This makes RPCs in which the call isn't externally retained possible (as long as it is started
// before being autoreleased).
// Care is taken not to retain self strongly in any of the blocks used in this implementation, so
// that the life of the instance is determined by this retain cycle.
_retainSelf
=
self
;
__weak
typeof
(
self
)
weakSelf
=
self
;
void
(
^
performCall
)()
=
^
{
typeof
(
self
)
strongSelf
=
weakSelf
;
if
(
strongSelf
)
{
strongSelf
->
_responseWriteable
=
[[
GRXConcurrentWriteable
alloc
]
initWithWriteable
:
writeable
dispatchQueue:
strongSelf
->
_responseQueue
];
strongSelf
->
_wrappedCall
=
[[
GRPCWrappedCall
alloc
]
initWithHost
:
strongSelf
->
_host
_wrappedCall
=
[[
GRPCWrappedCall
alloc
]
initWithHost
:
_host
serverName:
strongSelf
->
_serverName
serverName:
_serverName
path:
strongSelf
->
_path
];
path:
_path
];
NSAssert
(
_wrappedCall
,
@"Error allocating RPC objects. Low memory?"
);
NSAssert
(
_wrappedCall
,
@"Error allocating RPC objects. Low memory?"
);
[
strongS
elf
sendHeaders
:
_requestHeaders
];
[
s
elf
sendHeaders
:
_requestHeaders
];
[
strongS
elf
invokeCall
];
[
s
elf
invokeCall
];
// TODO(jcanizales): Extract this logic somewhere common.
// TODO(jcanizales): Extract this logic somewhere common.
NSString
*
host
=
[
NSURL
URLWithString
:[
@"https://"
stringByAppendingString
:
strongSelf
->
_host
]].
host
;
NSString
*
host
=
[
NSURL
URLWithString
:[
@"https://"
stringByAppendingString
:
_host
]].
host
;
if
(
!
host
)
{
if
(
!
host
)
{
// TODO(jcanizales): Check this on init.
// TODO(jcanizales): Check this on init.
[
NSException
raise
:
NSInvalidArgumentException
format
:
@"host of %@ is nil"
,
strongSelf
->
_host
];
[
NSException
raise
:
NSInvalidArgumentException
format
:
@"host of %@ is nil"
,
_host
];
}
}
strongSelf
->
_connectivityMonitor
=
[
GRPCConnectivityMonitor
monitorWithHost
:
host
];
_connectivityMonitor
=
[
GRPCConnectivityMonitor
monitorWithHost
:
host
];
__weak
typeof
(
self
)
weakSelf
=
self
;
void
(
^
handler
)()
=
^
{
void
(
^
handler
)()
=
^
{
typeof
(
self
)
strongSelf
=
weakSelf
;
typeof
(
self
)
strongSelf
=
weakSelf
;
[
strongSelf
finishWithError
:[
NSError
errorWithDomain
:
kGRPCErrorDomain
[
strongSelf
finishWithError
:[
NSError
errorWithDomain
:
kGRPCErrorDomain
...
@@ -458,10 +444,22 @@ static NSString * const kBearerPrefix = @"Bearer ";
...
@@ -458,10 +444,22 @@ static NSString * const kBearerPrefix = @"Bearer ";
[
_connectivityMonitor
handleLossWithHandler
:
handler
[
_connectivityMonitor
handleLossWithHandler
:
handler
wifiStatusChangeHandler:
nil
];
wifiStatusChangeHandler:
nil
];
}
}
};
-
(
void
)
startWithWriteable
:(
id
<
GRXWriteable
>
)
writeable
{
@synchronized
(
self
)
{
_state
=
GRXWriterStateStarted
;
}
// Create a retain cycle so that this instance lives until the RPC finishes (or is cancelled).
// This makes RPCs in which the call isn't externally retained possible (as long as it is started
// before being autoreleased).
// Care is taken not to retain self strongly in any of the blocks used in this implementation, so
// that the life of the instance is determined by this retain cycle.
_retainSelf
=
self
;
if
(
self
.
oauthToken
!=
nil
)
{
if
(
self
.
oauthToken
!=
nil
)
{
self
.
isWaitingForToken
=
YES
;
self
.
isWaitingForToken
=
YES
;
__weak
typeof
(
self
)
weakSelf
=
self
;
[
self
.
oauthToken
getTokenWithHandler
:
^
(
NSString
*
token
){
[
self
.
oauthToken
getTokenWithHandler
:
^
(
NSString
*
token
){
typeof
(
self
)
strongSelf
=
weakSelf
;
typeof
(
self
)
strongSelf
=
weakSelf
;
if
(
strongSelf
&&
strongSelf
.
isWaitingForToken
)
{
if
(
strongSelf
&&
strongSelf
.
isWaitingForToken
)
{
...
@@ -469,12 +467,12 @@ static NSString * const kBearerPrefix = @"Bearer ";
...
@@ -469,12 +467,12 @@ static NSString * const kBearerPrefix = @"Bearer ";
NSString
*
t
=
[
kBearerPrefix
stringByAppendingString
:
token
];
NSString
*
t
=
[
kBearerPrefix
stringByAppendingString
:
token
];
strongSelf
.
requestHeaders
[
kAuthorizationHeader
]
=
t
;
strongSelf
.
requestHeaders
[
kAuthorizationHeader
]
=
t
;
}
}
performCall
()
;
[
strongSelf
startCallWithWriteable
:
writeable
]
;
strongSelf
.
isWaitingForToken
=
NO
;
strongSelf
.
isWaitingForToken
=
NO
;
}
}
}];
}];
}
else
{
}
else
{
performCall
()
;
[
self
startCallWithWriteable
:
writeable
]
;
}
}
}
}
...
...
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