Merge github.com:grpc/grpc into prefer-gin-n-tonic

pull/2529/head
Craig Tiller 10 years ago
commit 4f101bd6b9
  1. 6
      gRPC.podspec
  2. 3
      src/compiler/objective_c_generator.cc
  3. 5
      src/compiler/objective_c_plugin.cc
  4. 32
      src/objective-c/GRPCClient/GRPCCall.m
  5. 3
      src/objective-c/GRPCClient/private/GRPCCompletionQueue.m
  6. 7
      src/objective-c/GRPCClient/private/GRPCWrappedCall.m
  7. 52
      src/objective-c/RxLibrary/GRXConcurrentWriteable.h
  8. 50
      src/objective-c/RxLibrary/GRXConcurrentWriteable.m
  9. 19
      src/objective-c/RxLibrary/GRXImmediateWriter.m
  10. 1
      src/objective-c/RxLibrary/private/GRXNSFastEnumerator.m
  11. 2
      src/objective-c/tests/Tests.xcodeproj/project.pbxproj
  12. 6
      templates/gRPC.podspec.template
  13. 2
      tools/jenkins/grpc_linuxbrew/Dockerfile
  14. 73
      tools/jenkins/run_distribution.sh

@ -36,14 +36,14 @@
Pod::Spec.new do |s|
s.name = 'gRPC'
s.version = '0.6.0'
s.version = '0.7.0'
s.summary = 'gRPC client library for iOS/OSX'
s.homepage = 'http://www.grpc.io'
s.license = 'New BSD'
s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' }
# s.source = { :git => 'https://github.com/grpc/grpc.git',
# :tag => 'release-0_9_1-objectivec-0.5.1' }
# :tag => 'release-0_10_0-objectivec-0.6.0' }
s.ios.deployment_target = '6.0'
s.osx.deployment_target = '10.8'
@ -518,6 +518,8 @@ Pod::Spec.new do |s|
ss.requires_arc = false
ss.libraries = 'z'
ss.dependency 'OpenSSL', '~> 1.0.200'
# ss.compiler_flags = '-GCC_WARN_INHIBIT_ALL_WARNINGS', '-w'
end
# This is a workaround for Cocoapods Issue #1437.

@ -186,9 +186,6 @@ string GetHeader(const ServiceDescriptor *service) {
grpc::protobuf::io::StringOutputStream output_stream(&output);
Printer printer(&output_stream, '$');
printer.Print("@protocol GRXWriteable;\n");
printer.Print("@protocol GRXWriter;\n\n");
map<string, string> vars = {{"service_class", ServiceClassName(service)}};
printer.Print(vars, "@protocol $service_class$ <NSObject>\n\n");

@ -63,7 +63,9 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
// Generate .pbrpc.h
string imports = string("#import \"") + file_name + ".pbobjc.h\"\n\n"
"#import <ProtoRPC/ProtoService.h>\n";
"#import <ProtoRPC/ProtoService.h>\n"
"#import <RxLibrary/GRXWriteable.h>\n"
"#import <RxLibrary/GRXWriter.h>\n";
// TODO(jcanizales): Instead forward-declare the input and output types
// and import the files in the .pbrpc.m
@ -89,7 +91,6 @@ class ObjectiveCGrpcGenerator : public grpc::protobuf::compiler::CodeGenerator {
string imports = string("#import \"") + file_name + ".pbrpc.h\"\n\n"
"#import <ProtoRPC/ProtoRPC.h>\n"
"#import <RxLibrary/GRXWriteable.h>\n"
"#import <RxLibrary/GRXWriter+Immediate.h>\n";
string definitions;

@ -35,10 +35,10 @@
#include <grpc/grpc.h>
#include <grpc/support/time.h>
#import <RxLibrary/GRXConcurrentWriteable.h>
#import "private/GRPCChannel.h"
#import "private/GRPCCompletionQueue.h"
#import "private/GRPCDelegateWrapper.h"
#import "private/GRPCWrappedCall.h"
#import "private/NSData+GRPC.h"
#import "private/NSDictionary+GRPC.h"
@ -78,9 +78,13 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
// do. Particularly, in the face of errors, there's no ordering guarantee at
// all. This wrapper over our actual writeable ensures thread-safety and
// correct ordering.
GRPCDelegateWrapper *_responseWriteable;
GRXConcurrentWriteable *_responseWriteable;
GRXWriter *_requestWriter;
// To create a retain cycle when a call is started, up until it finishes. See
// |startWithWriteable:| and |finishWithError:|.
GRPCCall *_self;
NSMutableDictionary *_requestMetadata;
NSMutableDictionary *_responseMetadata;
}
@ -143,8 +147,13 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
#pragma mark Finish
- (void)finishWithError:(NSError *)errorOrNil {
// If the call isn't retained anywhere else, it can be deallocated now.
_self = nil;
// If there were still request messages coming, stop them.
_requestWriter.state = GRXWriterStateFinished;
_requestWriter = nil;
if (errorOrNil) {
[_responseWriteable cancelWithError:errorOrNil];
} else {
@ -191,7 +200,7 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
return;
}
__weak GRPCCall *weakSelf = self;
__weak GRPCDelegateWrapper *weakWriteable = _responseWriteable;
__weak GRXConcurrentWriteable *weakWriteable = _responseWriteable;
dispatch_async(_callQueue, ^{
[weakSelf startReadWithHandler:^(grpc_byte_buffer *message) {
@ -216,7 +225,7 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
[weakSelf cancelCall];
return;
}
[weakWriteable enqueueMessage:data completionHandler:^{
[weakWriteable enqueueValue:data completionHandler:^{
[weakSelf startNextRead];
}];
}];
@ -276,6 +285,7 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
}
- (void)writesFinishedWithError:(NSError *)errorOrNil {
_requestWriter = nil;
if (errorOrNil) {
[self cancel];
} else {
@ -335,12 +345,14 @@ NSString * const kGRPCStatusMetadataKey = @"io.grpc.StatusMetadataKey";
#pragma mark GRXWriter implementation
- (void)startWithWriteable:(id<GRXWriteable>)writeable {
// The following produces a retain cycle self:_responseWriteable:self, which is only
// broken when writesFinishedWithError: is sent to the wrapped writeable.
// Care is taken not to retain self strongly in any of the blocks used in
// the implementation of GRPCCall, so that the life of the instance is
// determined by this retain cycle.
_responseWriteable = [[GRPCDelegateWrapper alloc] initWithWriteable:writeable writer:self];
// 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.
_self = self;
_responseWriteable = [[GRXConcurrentWriteable alloc] initWithWriteable:writeable];
[self sendHeaders:_requestMetadata];
[self invokeCall];
}

@ -65,7 +65,8 @@
dispatch_async(gDefaultConcurrentQueue, ^{
while (YES) {
// The following call blocks until an event is available.
grpc_event event = grpc_completion_queue_next(unmanagedQueue, gpr_inf_future);
grpc_event event = grpc_completion_queue_next(unmanagedQueue,
gpr_inf_future(GPR_CLOCK_REALTIME));
GRPCQueueCompletionHandler handler;
switch (event.type) {
case GRPC_OP_COMPLETE:

@ -246,8 +246,11 @@
if (!_queue) {
return nil;
}
_call = grpc_channel_create_call(channel.unmanagedChannel, _queue.unmanagedQueue,
path.UTF8String, host.UTF8String, gpr_inf_future);
_call = grpc_channel_create_call(channel.unmanagedChannel,
_queue.unmanagedQueue,
path.UTF8String,
host.UTF8String,
gpr_inf_future(GPR_CLOCK_REALTIME));
if (_call == NULL) {
return nil;
}

@ -33,49 +33,39 @@
#import <Foundation/Foundation.h>
#import <RxLibrary/GRXWriter.h>
#import "GRXWriter.h"
#import "GRXWriteable.h"
@protocol GRXWriteable;
// This is a thread-safe wrapper over a GRXWriteable instance. It lets one
// enqueue calls to a GRXWriteable instance for the main thread, guaranteeing
// that writesFinishedWithError: is the last message sent to it (no matter what
// messages are sent to the wrapper, in what order, nor from which thread). It
// also guarantees that, if cancelWithError: is called from the main thread
// (e.g. by the app cancelling the writes), no further messages are sent to the
// writeable except writesFinishedWithError:.
// This is a thread-safe wrapper over a GRXWriteable instance. It lets one enqueue calls to a
// GRXWriteable instance for the main thread, guaranteeing that writesFinishedWithError: is the last
// message sent to it (no matter what messages are sent to the wrapper, in what order, nor from
// which thread). It also guarantees that, if cancelWithError: is called from the main thread (e.g.
// by the app cancelling the writes), no further messages are sent to the writeable except
// writesFinishedWithError:.
//
// TODO(jcanizales): Let the user specify another queue for the writeable
// callbacks.
// TODO(jcanizales): Rename to GRXWriteableWrapper and move to the Rx library.
@interface GRPCDelegateWrapper : NSObject
// TODO(jcanizales): Let the user specify another queue for the writeable callbacks.
@interface GRXConcurrentWriteable : NSObject
// The GRXWriteable passed is the wrapped writeable.
// Both the GRXWriter instance and the GRXWriteable instance are retained until
// writesFinishedWithError: is sent to the writeable, and released after that.
// This is used to create a retain cycle that keeps both objects alive until the
// writing is explicitly finished.
- (instancetype)initWithWriteable:(id<GRXWriteable>)writeable writer:(GRXWriter *)writer
NS_DESIGNATED_INITIALIZER;
// The GRXWriteable instance is retained until writesFinishedWithError: is sent to it, and released
// after that.
- (instancetype)initWithWriteable:(id<GRXWriteable>)writeable NS_DESIGNATED_INITIALIZER;
// Enqueues writeValue: to be sent to the writeable in the main thread.
// The passed handler is invoked from the main thread after writeValue: returns.
- (void)enqueueMessage:(NSData *)message completionHandler:(void (^)())handler;
- (void)enqueueValue:(id)value completionHandler:(void (^)())handler;
// Enqueues writesFinishedWithError:nil to be sent to the writeable in the main
// thread. After that message is sent to the writeable, all other methods of
// this object are effectively noops.
// Enqueues writesFinishedWithError:nil to be sent to the writeable in the main thread. After that
// message is sent to the writeable, all other methods of this object are effectively noops.
- (void)enqueueSuccessfulCompletion;
// If the writeable has not yet received a writesFinishedWithError: message, this
// will enqueue one to be sent to it in the main thread, and cancel all other
// pending messages to the writeable enqueued by this object (both past and
// future).
// If the writeable has not yet received a writesFinishedWithError: message, this will enqueue one
// to be sent to it in the main thread, and cancel all other pending messages to the writeable
// enqueued by this object (both past and future).
// The error argument cannot be nil.
- (void)cancelWithError:(NSError *)error;
// Cancels all pending messages to the writeable enqueued by this object (both
// past and future). Because the writeable won't receive writesFinishedWithError:,
// this also releases the writeable and the writer.
// Cancels all pending messages to the writeable enqueued by this object (both past and future).
// Because the writeable won't receive writesFinishedWithError:, this also releases the writeable.
- (void)cancelSilently;
@end

@ -31,45 +31,42 @@
*
*/
#import "GRPCDelegateWrapper.h"
#import "GRXConcurrentWriteable.h"
#import <RxLibrary/GRXWriteable.h>
@interface GRPCDelegateWrapper ()
// These are atomic so that cancellation can nillify them from any thread.
@interface GRXConcurrentWriteable ()
// This is atomic so that cancellation can nillify it from any thread.
@property(atomic, strong) id<GRXWriteable> writeable;
@property(atomic, strong) GRXWriter *writer;
@end
@implementation GRPCDelegateWrapper {
@implementation GRXConcurrentWriteable {
dispatch_queue_t _writeableQueue;
// This ensures that writesFinishedWithError: is only sent once to the writeable.
dispatch_once_t _alreadyFinished;
}
- (instancetype)init {
return [self initWithWriteable:nil writer:nil];
return [self initWithWriteable:nil];
}
// Designated initializer
- (instancetype)initWithWriteable:(id<GRXWriteable>)writeable writer:(GRXWriter *)writer {
- (instancetype)initWithWriteable:(id<GRXWriteable>)writeable {
if (self = [super init]) {
_writeableQueue = dispatch_get_main_queue();
_writeable = writeable;
_writer = writer;
}
return self;
}
- (void)enqueueMessage:(NSData *)message completionHandler:(void (^)())handler {
- (void)enqueueValue:(id)value completionHandler:(void (^)())handler {
dispatch_async(_writeableQueue, ^{
// We're racing a possible cancellation performed by another thread. To turn
// all already-enqueued messages into noops, cancellation nillifies the
// writeable property. If we get it before it's nil, we won
// the race.
// We're racing a possible cancellation performed by another thread. To turn all already-
// enqueued messages into noops, cancellation nillifies the writeable property. If we get it
// before it's nil, we won the race.
id<GRXWriteable> writeable = self.writeable;
if (writeable) {
[writeable writeValue:message];
[writeable writeValue:value];
handler();
}
});
@ -78,13 +75,11 @@
- (void)enqueueSuccessfulCompletion {
dispatch_async(_writeableQueue, ^{
dispatch_once(&_alreadyFinished, ^{
// Cancellation is now impossible. None of the other three blocks can run
// concurrently with this one.
// Cancellation is now impossible. None of the other three blocks can run concurrently with
// this one.
[self.writeable writesFinishedWithError:nil];
// Break the retain cycle with writer, and skip any possible message to the
// wrapped writeable enqueued after this one.
// Skip any possible message to the wrapped writeable enqueued after this one.
self.writeable = nil;
self.writer = nil;
});
});
}
@ -92,29 +87,24 @@
- (void)cancelWithError:(NSError *)error {
NSAssert(error, @"For a successful completion, use enqueueSuccessfulCompletion.");
dispatch_once(&_alreadyFinished, ^{
// Skip any of the still-enqueued messages to the wrapped writeable. We use
// the atomic setter to nillify writer and writeable because we might be
// running concurrently with the blocks in _writeableQueue, and assignment
// with ARC isn't atomic.
// Skip any of the still-enqueued messages to the wrapped writeable. We use the atomic setter to
// nillify writeable because we might be running concurrently with the blocks in
// _writeableQueue, and assignment with ARC isn't atomic.
id<GRXWriteable> writeable = self.writeable;
self.writeable = nil;
dispatch_async(_writeableQueue, ^{
[writeable writesFinishedWithError:error];
// Break the retain cycle with writer.
self.writer = nil;
});
});
}
- (void)cancelSilently {
dispatch_once(&_alreadyFinished, ^{
// Skip any of the still-enqueued messages to the wrapped writeable. We use
// the atomic setter to nillify writer and writeable because we might be
// running concurrently with the blocks in _writeableQueue, and assignment
// with ARC isn't atomic.
// Skip any of the still-enqueued messages to the wrapped writeable. We use the atomic setter to
// nillify writeable because we might be running concurrently with the blocks in
// _writeableQueue, and assignment with ARC isn't atomic.
self.writeable = nil;
self.writer = nil;
});
}
@end

@ -76,28 +76,15 @@
}
+ (GRXWriter *)writerWithValue:(id)value {
if (value) {
return [self writerWithEnumerator:[NSEnumerator grx_enumeratorWithSingleValue:value]];
} else {
return [self emptyWriter];
}
return [self writerWithEnumerator:[NSEnumerator grx_enumeratorWithSingleValue:value]];
}
+ (GRXWriter *)writerWithError:(NSError *)error {
if (error) {
return [self writerWithEnumerator:nil error:error];
} else {
return [self emptyWriter];
}
return [self writerWithEnumerator:nil error:error];
}
+ (GRXWriter *)emptyWriter {
static GRXImmediateWriter *emptyWriter;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
emptyWriter = [self writerWithEnumerator:nil error:nil];
});
return emptyWriter;
return [self writerWithEnumerator:nil error:nil];
}
#pragma mark Conformance with GRXWriter

@ -59,7 +59,6 @@
// Designated initializer.
- (instancetype)initWithContainer:(id<NSFastEnumeration>)container {
NSAssert(container, @"container can't be nil");
if ((self = [super init])) {
_container = container;
}

@ -391,7 +391,6 @@
635697DC1B14FC11007A7283 /* Debug */ = {
isa = XCBuildConfiguration;
buildSettings = {
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};
@ -400,7 +399,6 @@
635697DD1B14FC11007A7283 /* Release */ = {
isa = XCBuildConfiguration;
buildSettings = {
OTHER_LDFLAGS = "-ObjC";
PRODUCT_NAME = "$(TARGET_NAME)";
SKIP_INSTALL = YES;
};

@ -61,14 +61,14 @@ def grpc_private_headers(libs):
%>
Pod::Spec.new do |s|
s.name = 'gRPC'
s.version = '0.6.0'
s.version = '0.7.0'
s.summary = 'gRPC client library for iOS/OSX'
s.homepage = 'http://www.grpc.io'
s.license = 'New BSD'
s.authors = { 'The gRPC contributors' => 'grpc-packages@google.com' }
# s.source = { :git => 'https://github.com/grpc/grpc.git',
# :tag => 'release-0_9_1-objectivec-0.5.1' }
# :tag => 'release-0_10_0-objectivec-0.6.0' }
s.ios.deployment_target = '6.0'
s.osx.deployment_target = '10.8'
@ -95,6 +95,8 @@ Pod::Spec.new do |s|
ss.requires_arc = false
ss.libraries = 'z'
ss.dependency 'OpenSSL', '~> 1.0.200'
# ss.compiler_flags = '-GCC_WARN_INHIBIT_ALL_WARNINGS', '-w'
end
# This is a workaround for Cocoapods Issue #1437.

@ -55,7 +55,7 @@ RUN /bin/bash -l -c "\curl -sSL https://get.rvm.io | bash -s stable"
RUN /bin/bash -l -c "rvm install ruby-2.1"
# PHP dependency
RUN apt-get update && apt-get install -y php5 php5-dev phpunit unzip
RUN apt-get update && apt-get install -y php5 php5-dev php-pear phpunit unzip
RUN /bin/bash -l -c "echo 'export PATH=/home/linuxbrew/.linuxbrew/bin:\$PATH' >> ~/.bashrc"

@ -32,24 +32,67 @@
# linuxbrew installation of a selected language
set -ex
sha1=$(sha1sum tools/jenkins/grpc_linuxbrew/Dockerfile | cut -f1 -d\ )
DOCKER_IMAGE_NAME=grpc_linuxbrew_$sha1
if [ "$platform" == "linux" ]; then
docker build -t $DOCKER_IMAGE_NAME tools/jenkins/grpc_linuxbrew
if [ "$dist_channel" == "homebrew" ]; then
supported="python nodejs ruby php"
sha1=$(sha1sum tools/jenkins/grpc_linuxbrew/Dockerfile | cut -f1 -d\ )
DOCKER_IMAGE_NAME=grpc_linuxbrew_$sha1
docker build -t $DOCKER_IMAGE_NAME tools/jenkins/grpc_linuxbrew
supported="python nodejs ruby php"
if [ "$language" == "core" ]; then
command="curl -fsSL https://goo.gl/getgrpc | bash -"
elif [[ "$supported" =~ "$language" ]]; then
command="curl -fsSL https://goo.gl/getgrpc | bash -s $language"
else
echo "unsupported language $language"
exit 1
fi
docker run $DOCKER_IMAGE_NAME bash -l \
-c "nvm use 0.12; \
npm set unsafe-perm true; \
rvm use ruby-2.1; \
$command"
else
echo "Unsupported $platform dist_channel $dist_channel"
exit 1
fi
elif [ "$platform" == "macos" ]; then
if [ "$dist_channel" == "homebrew" ]; then
which brew # TODO: for debug, can be removed later
brew list -l
dir=/tmp/homebrew-test-$language
rm -rf $dir
mkdir -p $dir
git clone https://github.com/Homebrew/homebrew.git $dir
cd $dir
# TODO: Uncomment these when the general structure of the script is verified
# PATH=$dir/bin:$PATH brew tap homebrew/dupes
# PATH=$dir/bin:$PATH brew install zlib
# PATH=$dir/bin:$PATH brew install openssl
# PATH=$dir/bin:$PATH brew tap grpc/grpc
# PATH=$dir/bin:$PATH brew install --without-python google-protobuf
# PATH=$dir/bin:$PATH brew install grpc
PATH=$dir/bin:$PATH brew list -l
brew list -l
cd ~/
rm -rf $dir
echo $PATH # TODO: for debug, can be removed later
brew list -l # TODO: for debug, can be removed later
else
echo "Unsupported $platform dist_channel $dist_channel"
exit 1
fi
if [ "$language" == "core" ]; then
command="curl -fsSL https://goo.gl/getgrpc | bash -"
elif [[ "$supported" =~ "$language" ]]; then
command="curl -fsSL https://goo.gl/getgrpc | bash -s $language"
else
echo "unsupported language $language"
echo "unsupported platform $platform"
exit 1
fi
docker run $DOCKER_IMAGE_NAME bash -l \
-c "nvm use 0.12; \
npm set unsafe-perm true; \
rvm use ruby-2.1; \
$command"

Loading…
Cancel
Save