diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/core/surface/call.h | 13 | ||||
-rw-r--r-- | src/core/surface/call_log_batch.c | 16 | ||||
-rw-r--r-- | src/core/surface/server.c | 3 | ||||
-rw-r--r-- | src/core/tsi/ssl_transport_security.c | 10 | ||||
-rw-r--r-- | src/objective-c/README.md | 119 |
5 files changed, 138 insertions, 23 deletions
diff --git a/src/core/surface/call.h b/src/core/surface/call.h index 60222bf389..9116538948 100644 --- a/src/core/surface/call.h +++ b/src/core/surface/call.h @@ -122,6 +122,16 @@ void grpc_call_log_batch(char *file, int line, gpr_log_severity severity, grpc_call *call, const grpc_op *ops, size_t nops, void *tag); +void grpc_server_log_request_call(char *file, int line, + gpr_log_severity severity, + grpc_server *server, + grpc_call **call, + grpc_call_details *details, + grpc_metadata_array *initial_metadata, + grpc_completion_queue *cq_bound_to_call, + grpc_completion_queue *cq_for_notification, + void *tag); + /* Set a context pointer. No thread safety guarantees are made wrt this value. */ void grpc_call_context_set(grpc_call *call, grpc_context_index elem, void *value, @@ -132,6 +142,9 @@ void *grpc_call_context_get(grpc_call *call, grpc_context_index elem); #define GRPC_CALL_LOG_BATCH(sev, call, ops, nops, tag) \ if (grpc_trace_batch) grpc_call_log_batch(sev, call, ops, nops, tag) +#define GRPC_SERVER_LOG_REQUEST_CALL(sev, server, call, details, initial_metadata, cq_bound_to_call, cq_for_notifications, tag) \ + if (grpc_trace_batch) grpc_server_log_request_call(sev, server, call, details, initial_metadata, cq_bound_to_call, cq_for_notifications, tag) + gpr_uint8 grpc_call_is_client(grpc_call *call); #endif /* GRPC_INTERNAL_CORE_SURFACE_CALL_H */ diff --git a/src/core/surface/call_log_batch.c b/src/core/surface/call_log_batch.c index e3b3f75b45..9905401bee 100644 --- a/src/core/surface/call_log_batch.c +++ b/src/core/surface/call_log_batch.c @@ -119,3 +119,19 @@ void grpc_call_log_batch(char *file, int line, gpr_log_severity severity, gpr_free(tmp); } } + +void grpc_server_log_request_call(char *file, int line, + gpr_log_severity severity, + grpc_server *server, + grpc_call **call, + grpc_call_details *details, + grpc_metadata_array *initial_metadata, + grpc_completion_queue *cq_bound_to_call, + grpc_completion_queue *cq_for_notification, + void *tag) { + gpr_log(file, line, severity, + "grpc_server_request_call(server=%p, call=%p, details=%p, " + "initial_metadata=%p, cq_bound_to_call=%p, cq_for_notification=%p, " + "tag=%p)", server, call, details, initial_metadata, + cq_bound_to_call, cq_for_notification, tag); +} diff --git a/src/core/surface/server.c b/src/core/surface/server.c index 24a23ae5c4..e99e3e2b04 100644 --- a/src/core/surface/server.c +++ b/src/core/surface/server.c @@ -1010,6 +1010,9 @@ grpc_call_error grpc_server_request_call( grpc_completion_queue *cq_bound_to_call, grpc_completion_queue *cq_for_notification, void *tag) { requested_call rc; + GRPC_SERVER_LOG_REQUEST_CALL(GPR_INFO, server, call, details, + initial_metadata, cq_bound_to_call, + cq_for_notification, tag); grpc_cq_begin_op(cq_for_notification, NULL); rc.type = BATCH_CALL; rc.tag = tag; diff --git a/src/core/tsi/ssl_transport_security.c b/src/core/tsi/ssl_transport_security.c index 9718a0b048..63b4c42131 100644 --- a/src/core/tsi/ssl_transport_security.c +++ b/src/core/tsi/ssl_transport_security.c @@ -639,7 +639,7 @@ static tsi_result ssl_protector_protect(tsi_frame_protector* self, tsi_result result = TSI_OK; /* First see if we have some pending data in the SSL BIO. */ - size_t pending_in_ssl = BIO_ctrl_pending(impl->from_ssl); + size_t pending_in_ssl = BIO_pending(impl->from_ssl); if (pending_in_ssl > 0) { *unprotected_bytes_size = 0; read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, @@ -694,7 +694,7 @@ static tsi_result ssl_protector_protect_flush( impl->buffer_offset = 0; } - *still_pending_size = BIO_ctrl_pending(impl->from_ssl); + *still_pending_size = BIO_pending(impl->from_ssl); if (*still_pending_size == 0) return TSI_OK; read_from_ssl = BIO_read(impl->from_ssl, protected_output_frames, @@ -704,7 +704,7 @@ static tsi_result ssl_protector_protect_flush( return TSI_INTERNAL_ERROR; } *protected_output_frames_size = read_from_ssl; - *still_pending_size = BIO_ctrl_pending(impl->from_ssl); + *still_pending_size = BIO_pending(impl->from_ssl); return TSI_OK; } @@ -782,7 +782,7 @@ static tsi_result ssl_handshaker_get_bytes_to_send_to_peer(tsi_handshaker* self, } } *bytes_size = (size_t)bytes_read_from_ssl; - return BIO_ctrl_pending(impl->from_ssl) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; + return BIO_pending(impl->from_ssl) == 0 ? TSI_OK : TSI_INCOMPLETE_DATA; } static tsi_result ssl_handshaker_get_result(tsi_handshaker* self) { @@ -818,7 +818,7 @@ static tsi_result ssl_handshaker_process_bytes_from_peer( ssl_result = SSL_get_error(impl->ssl, ssl_result); switch (ssl_result) { case SSL_ERROR_WANT_READ: - if (BIO_ctrl_pending(impl->from_ssl) == 0) { + if (BIO_pending(impl->from_ssl) == 0) { /* We need more data. */ return TSI_INCOMPLETE_DATA; } else { diff --git a/src/objective-c/README.md b/src/objective-c/README.md index 49d7f43882..167016cc2c 100644 --- a/src/objective-c/README.md +++ b/src/objective-c/README.md @@ -1,43 +1,119 @@ # gRPC for Objective-C -## How to generate a client library from a Protocol Buffers definition +- [Install protoc with the gRPC plugin](#install) +- [Use protoc to generate a gRPC library](#protoc) +- [Integrate the generated gRPC library in your project](#cocoapods) +- [Use the generated library in your code](#use) +- [Alternative methods](#alternatives) + - [Install protoc and the gRPC plugin without using Homebrew](#nohomebrew) + - [Integrate the generated gRPC library without using Cocoapods](#nococoapods) -First install v3 of the Protocol Buffers compiler (_protoc_), by cloning [its Git repository](https://github.com/google/protobuf) and following these [installation instructions](https://github.com/google/protobuf#c-installation---unix) (the ones titled C++; don't miss the note for Mac users). +<a name="install"></a> +## Install protoc with the gRPC plugin -Then clone this repository and execute the following commands from the root directory where it was cloned. +On Mac OS X, install [homebrew][]. On Linux, install [linuxbrew][]. -Compile the gRPC plugins for _protoc_: +Run the following command to install the Protocol Buffers compiler (_protoc_) and the gRPC _protoc_ plugin: ```sh -make plugins +$ curl -fsSL https://goo.gl/getgrpc | bash - ``` +This will download and run the [gRPC install script][]. After the command completes, you're ready to proceed. + +<a name="protoc"></a> +## Use protoc to generate a gRPC library + +Run _protoc_ with the following flags to generate the client library for your `.proto` files: -Create a symbolic link to the compiled plugin binary somewhere in your `$PATH`: ```sh -ln -s `pwd`/bins/opt/grpc_objective_c_plugin /usr/local/bin/protoc-gen-objcgrpc +protoc --objc_out=. --objcgrpc_out=. *.proto ``` -(Notice that the name of the created link must begin with "protoc-gen-" for _protoc_ to recognize it as a plugin). -If you don't want to create the symbolic link, you can alternatively copy the binary (with the appropriate name). Or you might prefer instead to specify the plugin's path as a flag when invoking _protoc_, in which case no system modification nor renaming is necessary. +This will generate a pair of `.pbobjc.h`/`.pbobjc.m` files for each `.proto` file, with the messages and enums defined in them. And a pair of `.pbrpc.h`/`.pbrpc.m` files for each `.proto` file with services defined. The latter contains the code to make remote calls to the specified API. -Finally, run _protoc_ with the following flags to generate the client library for your `.proto` files: +<a name="cocoapods"></a> +## Integrate the generated gRPC library in your project + +Install [Cocoapods](https://cocoapods.org/#install). + +You need to create a Podspec file for the generated library. You may simply copy the following example to the directory where the source files were generated, updating the name and other metadata of the Podspec as necessary: + +```ruby +Pod::Spec.new do |s| + s.name = '<Podspec file name>' + s.version = '...' + s.summary = 'Client library to make RPCs to <my proto API>' + s.homepage = '...' + s.license = '...' + s.authors = { '<my name>' => '<my email>' } + + s.ios.deployment_target = '6.0' + s.osx.deployment_target = '10.8' + + s.subspec 'Messages' do |ms| + ms.source_files = '*.pbobjc.{h,m}' + ms.requires_arc = false + ms.dependency 'Protobuf', '~> 3.0' + end + + s.subspec 'Services' do |ss| + ss.source_files = '*.pbrpc.{h,m}' + ss.requires_arc = true + ss.dependency 'gRPC', '~> 0.0' + ss.dependency '<Podspec file name>/Messages' + end +end +``` + +The file should be named `<Podspec file name>.podspec`. You can refer to this [example Podspec][]. Once your library has a Podspec, Cocoapods can install it into any XCode project. For that, go into your project's directory and create a Podfile by running: ```sh -protoc --objc_out=. --objcgrpc_out=. *.proto +pod init ``` -This will generate a pair of `.pbobjc.h`/`.pbobjc.m` files for each `.proto` file, with the messages and enums defined in them. And a pair of `.pbrpc.h`/`.pbrpc.m` files for each `.proto` file with services defined. The latter contains the code to make remote calls to the specified API. +Next add a line to your Podfile to refer to your library's Podspec. Use `:path` as described [here](https://guides.cocoapods.org/using/the-podfile.html#using-the-files-from-a-folder-local-to-the-machine): + +```ruby +pod '<Podspec file name>', :path => 'path/to/the/directory/of/your/podspec' +``` + +You can look at this [example Podfile][]. + +Finally, in your project's directory, run: -## How to integrate a generated gRPC library in your project +```sh +pod install +``` + +<a name="use"></a> +## Use the generated library in your code + +Please check this [sample app][] for examples of how to use a generated gRPC library. + +<a name="alternatives"></a> +## Alternative methods -### If you use Cocoapods +<a name="nohomebrew"></a> +### Install protoc and the gRPC plugin without using Homebrew -This is the recommended approach. +First install v3 of the Protocol Buffers compiler (_protoc_), by cloning [its Git repository](https://github.com/google/protobuf) and following these [installation instructions](https://github.com/google/protobuf#c-installation---unix) (the ones titled C++; don't miss the note for Mac users). + +Then clone this repository and execute the following commands from the root directory where it was cloned. + +Compile the gRPC plugins for _protoc_: +```sh +make plugins +``` -You need to create a Podspec file for the generated library. This is simply a matter of copying an example like [this one](https://github.com/grpc/grpc/blob/master/src/objective-c/examples/Sample/RemoteTestClient/RemoteTest.podspec) to the directory where the source files were generated. Update the name and other metadata of the Podspec as suitable. +Create a symbolic link to the compiled plugin binary somewhere in your `$PATH`: +```sh +ln -s `pwd`/bins/opt/grpc_objective_c_plugin /usr/local/bin/protoc-gen-objcgrpc +``` +(Notice that the name of the created link must begin with "protoc-gen-" for _protoc_ to recognize it as a plugin). -Once your library has a Podspec, refer to it from your Podfile using `:path` as described [here](https://guides.cocoapods.org/using/the-podfile.html#using-the-files-from-a-folder-local-to-the-machine). +If you don't want to create the symbolic link, you can alternatively copy the binary (with the appropriate name). Or you might prefer instead to specify the plugin's path as a flag when invoking _protoc_, in which case no system modification nor renaming is necessary. -### If you don't use Cocoapods +<a name="nococoapods"></a> +### Integrate the generated gRPC library without using Cocoapods You need to compile the generated `.pbpbjc.*` files (the enums and messages) without ARC support, and the generated `.pbrpc.*` files (the services) with ARC support. The generated code depends on v0.3+ of the Objective-C gRPC runtime library and v3.0+ of the Objective-C Protobuf runtime library. @@ -45,3 +121,10 @@ These libraries need to be integrated into your project as described in their re * [Podspec](https://github.com/grpc/grpc/blob/master/gRPC.podspec) for the Objective-C gRPC runtime library. This can be tedious to configure manually. * [Podspec](https://github.com/jcanizales/protobuf/blob/add-podspec/Protobuf.podspec) for the Objective-C Protobuf runtime library. + +[homebrew]:http://brew.sh +[linuxbrew]:https://github.com/Homebrew/linuxbrew +[gRPC install script]:https://raw.githubusercontent.com/grpc/homebrew-grpc/master/scripts/install +[example Podspec]:https://github.com/grpc/grpc/blob/master/src/objective-c/examples/Sample/RemoteTestClient/RemoteTest.podspec +[example Podfile]:https://github.com/grpc/grpc/blob/master/src/objective-c/examples/Sample/Podfile +[sample app]: https://github.com/grpc/grpc/tree/master/src/objective-c/examples/Sample |