Browse Source

Merge branch 'master' into node_method_name_conflicts

murgatroid99 10 years ago
parent
commit
1e9dd32803
100 changed files with 434 additions and 297 deletions
  1. 19 4
      INSTALL
  2. 2 0
      Makefile
  3. 39 2
      build.json
  4. 3 3
      doc/connection-backoff-interop-test-description.md
  5. 9 0
      doc/connection-backoff.md
  6. 2 2
      include/grpc++/async_unary_call.h
  7. 1 1
      include/grpc++/auth_context.h
  8. 2 2
      include/grpc++/byte_buffer.h
  9. 8 1
      include/grpc++/client_context.h
  10. 5 4
      include/grpc++/dynamic_thread_pool.h
  11. 2 2
      include/grpc++/generic_stub.h
  12. 4 0
      include/grpc++/impl/README.md
  13. 6 18
      include/grpc++/impl/call.h
  14. 0 1
      include/grpc++/impl/grpc_library.h
  15. 3 3
      include/grpc++/impl/serialization_traits.h
  16. 6 2
      include/grpc++/impl/sync_no_cxx11.h
  17. 11 10
      include/grpc++/impl/thd_no_cxx11.h
  18. 13 3
      include/grpc++/server.h
  19. 7 6
      include/grpc++/server_builder.h
  20. 2 2
      include/grpc++/server_context.h
  21. 3 6
      include/grpc++/stream.h
  22. 9 4
      include/grpc/compression.h
  23. 7 13
      include/grpc/grpc.h
  24. 1 1
      include/grpc/status.h
  25. 1 1
      include/grpc/support/alloc.h
  26. 1 1
      include/grpc/support/atm.h
  27. 1 1
      include/grpc/support/atm_gcc_atomic.h
  28. 1 1
      include/grpc/support/atm_gcc_sync.h
  29. 18 19
      include/grpc/support/atm_win32.h
  30. 1 1
      include/grpc/support/cmdline.h
  31. 1 1
      include/grpc/support/cpu.h
  32. 1 1
      include/grpc/support/histogram.h
  33. 1 1
      include/grpc/support/host_port.h
  34. 1 1
      include/grpc/support/log.h
  35. 1 1
      include/grpc/support/log_win32.h
  36. 2 1
      include/grpc/support/port_platform.h
  37. 1 1
      include/grpc/support/slice.h
  38. 1 1
      include/grpc/support/string_util.h
  39. 1 1
      include/grpc/support/subprocess.h
  40. 1 1
      include/grpc/support/sync.h
  41. 4 10
      include/grpc/support/sync_generic.h
  42. 1 1
      include/grpc/support/sync_posix.h
  43. 1 1
      include/grpc/support/sync_win32.h
  44. 1 1
      include/grpc/support/thd.h
  45. 2 1
      include/grpc/support/time.h
  46. 2 2
      include/grpc/support/tls.h
  47. 7 3
      include/grpc/support/tls_gcc.h
  48. 7 3
      include/grpc/support/tls_msvc.h
  49. 5 5
      include/grpc/support/useful.h
  50. 1 1
      src/core/channel/census_filter.h
  51. 23 15
      src/core/channel/client_channel.c
  52. 4 3
      src/core/channel/client_channel.h
  53. 46 11
      src/core/channel/compress_filter.c
  54. 1 1
      src/core/channel/compress_filter.h
  55. 1 1
      src/core/channel/http_client_filter.h
  56. 1 1
      src/core/channel/http_server_filter.h
  57. 1 1
      src/core/channel/noop_filter.h
  58. 2 1
      src/core/client_config/resolvers/dns_resolver.c
  59. 4 4
      src/core/client_config/resolvers/zookeeper_resolver.c
  60. 2 0
      src/core/client_config/subchannel.h
  61. 5 5
      src/core/client_config/subchannel_factory_decorators/add_channel_arg.c
  62. 3 2
      src/core/client_config/subchannel_factory_decorators/add_channel_arg.h
  63. 2 2
      src/core/client_config/subchannel_factory_decorators/merge_channel_args.c
  64. 3 2
      src/core/client_config/subchannel_factory_decorators/merge_channel_args.h
  65. 11 4
      src/core/compression/algorithm.c
  66. 4 4
      src/core/debug/trace.c
  67. 1 1
      src/core/debug/trace.h
  68. 4 2
      src/core/httpcli/format_request.c
  69. 1 1
      src/core/httpcli/format_request.h
  70. 1 1
      src/core/httpcli/parser.h
  71. 2 3
      src/core/iomgr/alarm.c
  72. 1 1
      src/core/iomgr/alarm.h
  73. 5 5
      src/core/iomgr/alarm_heap.c
  74. 1 1
      src/core/iomgr/alarm_heap.h
  75. 1 1
      src/core/iomgr/alarm_internal.h
  76. 2 1
      src/core/iomgr/endpoint.c
  77. 3 2
      src/core/iomgr/endpoint.h
  78. 1 1
      src/core/iomgr/endpoint_pair.h
  79. 13 7
      src/core/iomgr/endpoint_pair_windows.c
  80. 16 19
      src/core/iomgr/iocp_windows.c
  81. 5 5
      src/core/iomgr/iocp_windows.h
  82. 1 1
      src/core/iomgr/iomgr.h
  83. 1 1
      src/core/iomgr/iomgr_internal.h
  84. 1 1
      src/core/iomgr/iomgr_posix.c
  85. 1 1
      src/core/iomgr/iomgr_posix.h
  86. 1 1
      src/core/iomgr/iomgr_windows.c
  87. 1 2
      src/core/iomgr/pollset_multipoller_with_epoll.c
  88. 2 3
      src/core/iomgr/pollset_multipoller_with_poll_posix.c
  89. 8 8
      src/core/iomgr/pollset_posix.c
  90. 2 1
      src/core/iomgr/pollset_posix.h
  91. 5 5
      src/core/iomgr/pollset_windows.c
  92. 1 1
      src/core/iomgr/resolve_address.h
  93. 1 4
      src/core/iomgr/resolve_address_posix.c
  94. 1 1
      src/core/iomgr/sockaddr.h
  95. 1 1
      src/core/iomgr/sockaddr_posix.h
  96. 4 2
      src/core/iomgr/sockaddr_utils.c
  97. 1 1
      src/core/iomgr/sockaddr_utils.h
  98. 1 1
      src/core/iomgr/sockaddr_win32.h
  99. 1 1
      src/core/iomgr/socket_utils_posix.h
  100. 1 1
      src/core/iomgr/socket_windows.c

+ 19 - 4
INSTALL

@@ -9,25 +9,40 @@ wiki pages:
 * If you are in a hurry *
 * If you are in a hurry *
 *************************
 *************************
 
 
+On Linux (Debian):
+
+ Note: you will need to add the Debian 'unstable' distribution to your sources
+ file first.
+
+ Add the following line to your `/etc/apt/sources.list` file:
+
+   deb http://ftp.us.debian.org/debian unstable main contrib non-free
+
+ Install the gRPC library:
+
+ $ [sudo] apt-get install libgrpc-dev
+
+OR
+
  $ git clone https://github.com/grpc/grpc.git
  $ git clone https://github.com/grpc/grpc.git
  $ cd grpc
  $ cd grpc
  $ git submodule update --init
  $ git submodule update --init
  $ make 
  $ make 
- $ sudo make install
+ $ [sudo] make install
 
 
 You don't need anything else than GNU Make, gcc and autotools. Under a Debian
 You don't need anything else than GNU Make, gcc and autotools. Under a Debian
 or Ubuntu system, this should boil down to the following packages:
 or Ubuntu system, this should boil down to the following packages:
 
 
-  $ apt-get install build-essential autoconf libtool
+ $ [sudo] apt-get install build-essential autoconf libtool
 
 
 Building the python wrapper requires the following:
 Building the python wrapper requires the following:
 
 
-  # apt-get install python-all-dev python-virtualenv
+ $ [sudo] apt-get install python-all-dev python-virtualenv
 
 
 If you want to install in a different directory than the default /usr/lib, you can
 If you want to install in a different directory than the default /usr/lib, you can
 override it on the command line:
 override it on the command line:
 
 
-  # make install prefix=/opt
+ $ [sudo] make install prefix=/opt
 
 
 
 
 *******************************
 *******************************

File diff suppressed because it is too large
+ 2 - 0
Makefile


+ 39 - 2
build.json

@@ -592,8 +592,7 @@
       "external_deps": [
       "external_deps": [
         "zookeeper"
         "zookeeper"
       ],
       ],
-      "secure": "no",
-      "vs_project_guid": "{F14EBEC1-DC43-45D3-8A7D-1A47072EFE50}"
+      "secure": "no"
     },
     },
     {
     {
       "name": "reconnect_server",
       "name": "reconnect_server",
@@ -733,6 +732,7 @@
         "test/cpp/interop/client_helper.h"
         "test/cpp/interop/client_helper.h"
       ],
       ],
       "src": [
       "src": [
+        "test/proto/messages.proto",
         "test/cpp/interop/client_helper.cc"
         "test/cpp/interop/client_helper.cc"
       ],
       ],
       "deps": [
       "deps": [
@@ -992,6 +992,20 @@
         "gpr"
         "gpr"
       ]
       ]
     },
     },
+    {
+      "name": "compression_test",
+      "build": "test",
+      "language": "c",
+      "src": [
+        "test/core/compression/compression_test.c"
+      ],
+      "deps": [
+        "grpc_test_util",
+        "grpc",
+        "gpr_test_util",
+        "gpr"
+      ]
+    },
     {
     {
       "name": "dualstack_socket_test",
       "name": "dualstack_socket_test",
       "build": "test",
       "build": "test",
@@ -2474,6 +2488,9 @@
         "gpr",
         "gpr",
         "grpc++_test_config"
         "grpc++_test_config"
       ],
       ],
+      "exclude_configs": [
+        "tsan"
+      ],
       "platforms": [
       "platforms": [
         "mac",
         "mac",
         "linux",
         "linux",
@@ -2596,6 +2613,26 @@
         "gpr"
         "gpr"
       ]
       ]
     },
     },
+    {
+      "name": "shutdown_test",
+      "build": "test",
+      "language": "c++",
+      "src": [
+        "test/cpp/end2end/shutdown_test.cc"
+      ],
+      "deps": [
+        "grpc++_test_util",
+        "grpc_test_util",
+        "grpc++",
+        "grpc_zookeeper",
+        "grpc",
+        "gpr_test_util",
+        "gpr"
+      ],
+      "external_deps": [
+        "zookeeper"
+      ]
+    },
     {
     {
       "name": "status_test",
       "name": "status_test",
       "build": "test",
       "build": "test",

+ 3 - 3
doc/connection-backoff-interop-test-description.md

@@ -31,9 +31,9 @@ Clients should accept these arguments:
 * --server_retry_port=PORT
 * --server_retry_port=PORT
     * The server port to connect to for testing backoffs. For example, "8081"
     * The server port to connect to for testing backoffs. For example, "8081"
 
 
-The client must connect to the control port without TLS. The client should
-either assert on the server returned backoff status or check the returned
-backoffs on its own.
+The client must connect to the control port without TLS. The client must connect
+to the retry port with TLS. The client should either assert on the server
+returned backoff status or check the returned backoffs on its own.
 
 
 Procedure of client:
 Procedure of client:
 
 

+ 9 - 0
doc/connection-backoff.md

@@ -44,3 +44,12 @@ different jitter logic.
 Alternate implementations must ensure that connection backoffs started at the
 Alternate implementations must ensure that connection backoffs started at the
 same time disperse, and must not attempt connections substantially more often
 same time disperse, and must not attempt connections substantially more often
 than the above algorithm.
 than the above algorithm.
+
+## Reset Backoff
+
+The back off should be reset to INITIAL_BACKOFF at some time point, so that the
+reconnecting behavior is consistent no matter the connection is a newly started
+one or a previously disconnected one.
+
+We choose to reset the Backoff when the SETTINGS frame is received, at that time
+point, we know for sure that this connection was accepted by the server.

+ 2 - 2
include/grpc++/async_unary_call.h

@@ -121,8 +121,8 @@ class ServerAsyncResponseWriter GRPC_FINAL
     }
     }
     // The response is dropped if the status is not OK.
     // The response is dropped if the status is not OK.
     if (status.ok()) {
     if (status.ok()) {
-      finish_buf_.ServerSendStatus(
-          ctx_->trailing_metadata_, finish_buf_.SendMessage(msg));
+      finish_buf_.ServerSendStatus(ctx_->trailing_metadata_,
+                                   finish_buf_.SendMessage(msg));
     } else {
     } else {
       finish_buf_.ServerSendStatus(ctx_->trailing_metadata_, status);
       finish_buf_.ServerSendStatus(ctx_->trailing_metadata_, status);
     }
     }

+ 1 - 1
include/grpc++/auth_context.h

@@ -62,6 +62,7 @@ class AuthPropertyIterator
   AuthPropertyIterator();
   AuthPropertyIterator();
   AuthPropertyIterator(const grpc_auth_property* property,
   AuthPropertyIterator(const grpc_auth_property* property,
                        const grpc_auth_property_iterator* iter);
                        const grpc_auth_property_iterator* iter);
+
  private:
  private:
   friend class SecureAuthContext;
   friend class SecureAuthContext;
   const grpc_auth_property* property_;
   const grpc_auth_property* property_;
@@ -92,4 +93,3 @@ class AuthContext {
 }  // namespace grpc
 }  // namespace grpc
 
 
 #endif  // GRPCXX_AUTH_CONTEXT_H
 #endif  // GRPCXX_AUTH_CONTEXT_H
-

+ 2 - 2
include/grpc++/byte_buffer.h

@@ -91,8 +91,8 @@ class SerializationTraits<ByteBuffer, void> {
     dest->set_buffer(byte_buffer);
     dest->set_buffer(byte_buffer);
     return Status::OK;
     return Status::OK;
   }
   }
-  static Status Serialize(const ByteBuffer& source, grpc_byte_buffer** buffer, 
-                        bool* own_buffer) {
+  static Status Serialize(const ByteBuffer& source, grpc_byte_buffer** buffer,
+                          bool* own_buffer) {
     *buffer = source.buffer();
     *buffer = source.buffer();
     *own_buffer = false;
     *own_buffer = false;
     return Status::OK;
     return Status::OK;

+ 8 - 1
include/grpc++/client_context.h

@@ -121,6 +121,10 @@ class PropagationOptions {
   gpr_uint32 propagate_;
   gpr_uint32 propagate_;
 };
 };
 
 
+namespace testing {
+class InteropClientContextInspector;
+}  // namespace testing
+
 class ClientContext {
 class ClientContext {
  public:
  public:
   ClientContext();
   ClientContext();
@@ -181,7 +185,9 @@ class ClientContext {
 
 
   // Get and set census context
   // Get and set census context
   void set_census_context(struct census_context* ccp) { census_context_ = ccp; }
   void set_census_context(struct census_context* ccp) { census_context_ = ccp; }
-  struct census_context* census_context() const { return census_context_; }
+  struct census_context* census_context() const {
+    return census_context_;
+  }
 
 
   void TryCancel();
   void TryCancel();
 
 
@@ -190,6 +196,7 @@ class ClientContext {
   ClientContext(const ClientContext&);
   ClientContext(const ClientContext&);
   ClientContext& operator=(const ClientContext&);
   ClientContext& operator=(const ClientContext&);
 
 
+  friend class ::grpc::testing::InteropClientContextInspector;
   friend class CallOpClientRecvStatus;
   friend class CallOpClientRecvStatus;
   friend class CallOpRecvInitialMetadata;
   friend class CallOpRecvInitialMetadata;
   friend class Channel;
   friend class Channel;

+ 5 - 4
include/grpc++/dynamic_thread_pool.h

@@ -55,11 +55,12 @@ class DynamicThreadPool GRPC_FINAL : public ThreadPoolInterface {
 
 
  private:
  private:
   class DynamicThread {
   class DynamicThread {
-  public:
-    DynamicThread(DynamicThreadPool *pool);
+   public:
+    DynamicThread(DynamicThreadPool* pool);
     ~DynamicThread();
     ~DynamicThread();
-  private:
-    DynamicThreadPool *pool_;
+
+   private:
+    DynamicThreadPool* pool_;
     std::unique_ptr<grpc::thread> thd_;
     std::unique_ptr<grpc::thread> thd_;
     void ThreadFunc();
     void ThreadFunc();
   };
   };

+ 2 - 2
include/grpc++/generic_stub.h

@@ -52,8 +52,8 @@ class GenericStub GRPC_FINAL {
 
 
   // begin a call to a named method
   // begin a call to a named method
   std::unique_ptr<GenericClientAsyncReaderWriter> Call(
   std::unique_ptr<GenericClientAsyncReaderWriter> Call(
-      ClientContext* context, const grpc::string& method,
-      CompletionQueue* cq, void* tag);
+      ClientContext* context, const grpc::string& method, CompletionQueue* cq,
+      void* tag);
 
 
  private:
  private:
   std::shared_ptr<ChannelInterface> channel_;
   std::shared_ptr<ChannelInterface> channel_;

+ 4 - 0
include/grpc++/impl/README.md

@@ -0,0 +1,4 @@
+**The APIs in this directory are not stable!**
+
+This directory contains header files that need to be installed but are not part
+of the public API. Users should not use these headers directly.

+ 6 - 18
include/grpc++/impl/call.h

@@ -67,14 +67,10 @@ class WriteOptions {
   WriteOptions(const WriteOptions& other) : flags_(other.flags_) {}
   WriteOptions(const WriteOptions& other) : flags_(other.flags_) {}
 
 
   /// Clear all flags.
   /// Clear all flags.
-  inline void Clear() {
-    flags_ = 0;
-  }
+  inline void Clear() { flags_ = 0; }
 
 
   /// Returns raw flags bitset.
   /// Returns raw flags bitset.
-  inline gpr_uint32 flags() const {
-    return flags_;
-  }
+  inline gpr_uint32 flags() const { return flags_; }
 
 
   /// Sets flag for the disabling of compression for the next message write.
   /// Sets flag for the disabling of compression for the next message write.
   ///
   ///
@@ -122,9 +118,7 @@ class WriteOptions {
   /// not go out on the wire immediately.
   /// not go out on the wire immediately.
   ///
   ///
   /// \sa GRPC_WRITE_BUFFER_HINT
   /// \sa GRPC_WRITE_BUFFER_HINT
-  inline bool get_buffer_hint() const {
-    return GetBit(GRPC_WRITE_BUFFER_HINT);
-  }
+  inline bool get_buffer_hint() const { return GetBit(GRPC_WRITE_BUFFER_HINT); }
 
 
   WriteOptions& operator=(const WriteOptions& rhs) {
   WriteOptions& operator=(const WriteOptions& rhs) {
     flags_ = rhs.flags_;
     flags_ = rhs.flags_;
@@ -132,17 +126,11 @@ class WriteOptions {
   }
   }
 
 
  private:
  private:
-  void SetBit(const gpr_int32 mask) {
-    flags_ |= mask;
-  }
+  void SetBit(const gpr_int32 mask) { flags_ |= mask; }
 
 
-  void ClearBit(const gpr_int32 mask) {
-    flags_ &= ~mask;
-  }
+  void ClearBit(const gpr_int32 mask) { flags_ &= ~mask; }
 
 
-  bool GetBit(const gpr_int32 mask) const {
-    return flags_ & mask;
-  }
+  bool GetBit(const gpr_int32 mask) const { return flags_ & mask; }
 
 
   gpr_uint32 flags_;
   gpr_uint32 flags_;
 };
 };

+ 0 - 1
include/grpc++/impl/grpc_library.h

@@ -46,5 +46,4 @@ class GrpcLibrary {
 
 
 }  // namespace grpc
 }  // namespace grpc
 
 
-
 #endif  // GRPCXX_IMPL_GRPC_LIBRARY_H
 #endif  // GRPCXX_IMPL_GRPC_LIBRARY_H

+ 3 - 3
include/grpc++/impl/serialization_traits.h

@@ -37,12 +37,12 @@
 namespace grpc {
 namespace grpc {
 
 
 /// Defines how to serialize and deserialize some type.
 /// Defines how to serialize and deserialize some type.
-/// 
+///
 /// Used for hooking different message serialization API's into GRPC.
 /// Used for hooking different message serialization API's into GRPC.
 /// Each SerializationTraits implementation must provide the following
 /// Each SerializationTraits implementation must provide the following
 /// functions:
 /// functions:
 ///   static Status Serialize(const Message& msg,
 ///   static Status Serialize(const Message& msg,
-///                           grpc_byte_buffer** buffer, 
+///                           grpc_byte_buffer** buffer,
 //                            bool* own_buffer);
 //                            bool* own_buffer);
 ///   static Status Deserialize(grpc_byte_buffer* buffer,
 ///   static Status Deserialize(grpc_byte_buffer* buffer,
 ///                             Message* msg,
 ///                             Message* msg,
@@ -57,7 +57,7 @@ namespace grpc {
 /// msg. max_message_size is passed in as a bound on the maximum number of
 /// msg. max_message_size is passed in as a bound on the maximum number of
 /// message bytes Deserialize should accept.
 /// message bytes Deserialize should accept.
 ///
 ///
-/// Both functions return a Status, allowing them to explain what went 
+/// Both functions return a Status, allowing them to explain what went
 /// wrong if required.
 /// wrong if required.
 template <class Message,
 template <class Message,
           class UnusedButHereForPartialTemplateSpecialization = void>
           class UnusedButHereForPartialTemplateSpecialization = void>

+ 6 - 2
include/grpc++/impl/sync_no_cxx11.h

@@ -38,7 +38,7 @@
 
 
 namespace grpc {
 namespace grpc {
 
 
-template<class mutex>
+template <class mutex>
 class lock_guard;
 class lock_guard;
 class condition_variable;
 class condition_variable;
 
 
@@ -46,6 +46,7 @@ class mutex {
  public:
  public:
   mutex() { gpr_mu_init(&mu_); }
   mutex() { gpr_mu_init(&mu_); }
   ~mutex() { gpr_mu_destroy(&mu_); }
   ~mutex() { gpr_mu_destroy(&mu_); }
+
  private:
  private:
   ::gpr_mu mu_;
   ::gpr_mu mu_;
   template <class mutex>
   template <class mutex>
@@ -58,6 +59,7 @@ class lock_guard {
  public:
  public:
   lock_guard(mutex &mu) : mu_(mu), locked(true) { gpr_mu_lock(&mu.mu_); }
   lock_guard(mutex &mu) : mu_(mu), locked(true) { gpr_mu_lock(&mu.mu_); }
   ~lock_guard() { unlock_internal(); }
   ~lock_guard() { unlock_internal(); }
+
  protected:
  protected:
   void lock_internal() {
   void lock_internal() {
     if (!locked) gpr_mu_lock(&mu_.mu_);
     if (!locked) gpr_mu_lock(&mu_.mu_);
@@ -67,6 +69,7 @@ class lock_guard {
     if (locked) gpr_mu_unlock(&mu_.mu_);
     if (locked) gpr_mu_unlock(&mu_.mu_);
     locked = false;
     locked = false;
   }
   }
+
  private:
  private:
   mutex &mu_;
   mutex &mu_;
   bool locked;
   bool locked;
@@ -76,7 +79,7 @@ class lock_guard {
 template <class mutex>
 template <class mutex>
 class unique_lock : public lock_guard<mutex> {
 class unique_lock : public lock_guard<mutex> {
  public:
  public:
-  unique_lock(mutex &mu) : lock_guard<mutex>(mu) { }
+  unique_lock(mutex &mu) : lock_guard<mutex>(mu) {}
   void lock() { this->lock_internal(); }
   void lock() { this->lock_internal(); }
   void unlock() { this->unlock_internal(); }
   void unlock() { this->unlock_internal(); }
 };
 };
@@ -92,6 +95,7 @@ class condition_variable {
   }
   }
   void notify_one() { gpr_cv_signal(&cv_); }
   void notify_one() { gpr_cv_signal(&cv_); }
   void notify_all() { gpr_cv_broadcast(&cv_); }
   void notify_all() { gpr_cv_broadcast(&cv_); }
+
  private:
  private:
   gpr_cv cv_;
   gpr_cv cv_;
 };
 };

+ 11 - 10
include/grpc++/impl/thd_no_cxx11.h

@@ -40,7 +40,8 @@ namespace grpc {
 
 
 class thread {
 class thread {
  public:
  public:
-  template<class T> thread(void (T::*fptr)(), T *obj) {
+  template <class T>
+  thread(void (T::*fptr)(), T *obj) {
     func_ = new thread_function<T>(fptr, obj);
     func_ = new thread_function<T>(fptr, obj);
     joined_ = false;
     joined_ = false;
     start();
     start();
@@ -53,28 +54,28 @@ class thread {
     gpr_thd_join(thd_);
     gpr_thd_join(thd_);
     joined_ = true;
     joined_ = true;
   }
   }
+
  private:
  private:
   void start() {
   void start() {
     gpr_thd_options options = gpr_thd_options_default();
     gpr_thd_options options = gpr_thd_options_default();
     gpr_thd_options_set_joinable(&options);
     gpr_thd_options_set_joinable(&options);
-    gpr_thd_new(&thd_, thread_func, (void *) func_, &options);
+    gpr_thd_new(&thd_, thread_func, (void *)func_, &options);
   }
   }
   static void thread_func(void *arg) {
   static void thread_func(void *arg) {
-    thread_function_base *func = (thread_function_base *) arg;
+    thread_function_base *func = (thread_function_base *)arg;
     func->call();
     func->call();
   }
   }
   class thread_function_base {
   class thread_function_base {
    public:
    public:
-    virtual ~thread_function_base() { }
+    virtual ~thread_function_base() {}
     virtual void call() = 0;
     virtual void call() = 0;
   };
   };
-  template<class T>
+  template <class T>
   class thread_function : public thread_function_base {
   class thread_function : public thread_function_base {
    public:
    public:
-    thread_function(void (T::*fptr)(), T *obj)
-      : fptr_(fptr)
-      , obj_(obj) { }
+    thread_function(void (T::*fptr)(), T *obj) : fptr_(fptr), obj_(obj) {}
     virtual void call() { (obj_->*fptr_)(); }
     virtual void call() { (obj_->*fptr_)(); }
+
    private:
    private:
     void (T::*fptr_)();
     void (T::*fptr_)();
     T *obj_;
     T *obj_;
@@ -84,8 +85,8 @@ class thread {
   bool joined_;
   bool joined_;
 
 
   // Disallow copy and assign.
   // Disallow copy and assign.
-  thread(const thread&);
-  void operator=(const thread&);
+  thread(const thread &);
+  void operator=(const thread &);
 };
 };
 
 
 }  // namespace grpc
 }  // namespace grpc

+ 13 - 3
include/grpc++/server.h

@@ -63,7 +63,14 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
   ~Server();
   ~Server();
 
 
   // Shutdown the server, block until all rpc processing finishes.
   // Shutdown the server, block until all rpc processing finishes.
-  void Shutdown();
+  // Forcefully terminate pending calls after deadline expires.
+  template <class T>
+  void Shutdown(const T& deadline) {
+    ShutdownInternal(TimePoint<T>(deadline).raw_time());
+  }
+
+  // Shutdown the server, waiting for all rpc processing to finish.
+  void Shutdown() { ShutdownInternal(gpr_inf_future(GPR_CLOCK_MONOTONIC)); }
 
 
   // Block waiting for all work to complete (the server must either
   // Block waiting for all work to complete (the server must either
   // be shutting down or some other thread must call Shutdown for this
   // be shutting down or some other thread must call Shutdown for this
@@ -84,8 +91,9 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
          int max_message_size);
          int max_message_size);
   // Register a service. This call does not take ownership of the service.
   // Register a service. This call does not take ownership of the service.
   // The service must exist for the lifetime of the Server instance.
   // The service must exist for the lifetime of the Server instance.
-  bool RegisterService(const grpc::string *host, RpcService* service);
-  bool RegisterAsyncService(const grpc::string *host, AsynchronousService* service);
+  bool RegisterService(const grpc::string* host, RpcService* service);
+  bool RegisterAsyncService(const grpc::string* host,
+                            AsynchronousService* service);
   void RegisterAsyncGenericService(AsyncGenericService* service);
   void RegisterAsyncGenericService(AsyncGenericService* service);
   // Add a listening port. Can be called multiple times.
   // Add a listening port. Can be called multiple times.
   int AddListeningPort(const grpc::string& addr, ServerCredentials* creds);
   int AddListeningPort(const grpc::string& addr, ServerCredentials* creds);
@@ -98,6 +106,8 @@ class Server GRPC_FINAL : public GrpcLibrary, private CallHook {
 
 
   void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) GRPC_OVERRIDE;
   void PerformOpsOnCall(CallOpSetInterface* ops, Call* call) GRPC_OVERRIDE;
 
 
+  void ShutdownInternal(gpr_timespec deadline);
+
   class BaseAsyncRequest : public CompletionQueueTag {
   class BaseAsyncRequest : public CompletionQueueTag {
    public:
    public:
     BaseAsyncRequest(Server* server, ServerContext* context,
     BaseAsyncRequest(Server* server, ServerContext* context,

+ 7 - 6
include/grpc++/server_builder.h

@@ -76,15 +76,14 @@ class ServerBuilder {
   // The service must exist for the lifetime of the Server instance returned by
   // The service must exist for the lifetime of the Server instance returned by
   // BuildAndStart().
   // BuildAndStart().
   // Only matches requests with :authority \a host
   // Only matches requests with :authority \a host
-  void RegisterService(const grpc::string& host, 
-                       SynchronousService* service);
+  void RegisterService(const grpc::string& host, SynchronousService* service);
 
 
   // Register an asynchronous service.
   // Register an asynchronous service.
   // This call does not take ownership of the service or completion queue.
   // This call does not take ownership of the service or completion queue.
   // The service and completion queuemust exist for the lifetime of the Server
   // The service and completion queuemust exist for the lifetime of the Server
   // instance returned by BuildAndStart().
   // instance returned by BuildAndStart().
   // Only matches requests with :authority \a host
   // Only matches requests with :authority \a host
-  void RegisterAsyncService(const grpc::string& host, 
+  void RegisterAsyncService(const grpc::string& host,
                             AsynchronousService* service);
                             AsynchronousService* service);
 
 
   // Set max message size in bytes.
   // Set max message size in bytes.
@@ -117,9 +116,10 @@ class ServerBuilder {
   };
   };
 
 
   typedef std::unique_ptr<grpc::string> HostString;
   typedef std::unique_ptr<grpc::string> HostString;
-  template <class T> struct NamedService {
+  template <class T>
+  struct NamedService {
     explicit NamedService(T* s) : service(s) {}
     explicit NamedService(T* s) : service(s) {}
-    NamedService(const grpc::string& h, T *s)
+    NamedService(const grpc::string& h, T* s)
         : host(new grpc::string(h)), service(s) {}
         : host(new grpc::string(h)), service(s) {}
     HostString host;
     HostString host;
     T* service;
     T* service;
@@ -127,7 +127,8 @@ class ServerBuilder {
 
 
   int max_message_size_;
   int max_message_size_;
   std::vector<std::unique_ptr<NamedService<RpcService>>> services_;
   std::vector<std::unique_ptr<NamedService<RpcService>>> services_;
-  std::vector<std::unique_ptr<NamedService<AsynchronousService>>> async_services_;
+  std::vector<std::unique_ptr<NamedService<AsynchronousService>>>
+      async_services_;
   std::vector<Port> ports_;
   std::vector<Port> ports_;
   std::vector<ServerCompletionQueue*> cqs_;
   std::vector<ServerCompletionQueue*> cqs_;
   std::shared_ptr<ServerCredentials> creds_;
   std::shared_ptr<ServerCredentials> creds_;

+ 2 - 2
include/grpc++/server_context.h

@@ -81,7 +81,7 @@ class CompletionQueue;
 class Server;
 class Server;
 
 
 namespace testing {
 namespace testing {
-class InteropContextInspector;
+class InteropServerContextInspector;
 }  // namespace testing
 }  // namespace testing
 
 
 // Interface of server side rpc context.
 // Interface of server side rpc context.
@@ -136,7 +136,7 @@ class ServerContext {
   }
   }
 
 
  private:
  private:
-  friend class ::grpc::testing::InteropContextInspector;
+  friend class ::grpc::testing::InteropServerContextInspector;
   friend class ::grpc::Server;
   friend class ::grpc::Server;
   template <class W, class R>
   template <class W, class R>
   friend class ::grpc::ServerAsyncReader;
   friend class ::grpc::ServerAsyncReader;

+ 3 - 6
include/grpc++/stream.h

@@ -85,9 +85,7 @@ class WriterInterface {
   // Returns false when the stream has been closed.
   // Returns false when the stream has been closed.
   virtual bool Write(const W& msg, const WriteOptions& options) = 0;
   virtual bool Write(const W& msg, const WriteOptions& options) = 0;
 
 
-  inline bool Write(const W& msg) {
-    return Write(msg, WriteOptions());
-  }
+  inline bool Write(const W& msg) { return Write(msg, WriteOptions()); }
 };
 };
 
 
 template <class R>
 template <class R>
@@ -640,9 +638,8 @@ class ServerAsyncReader GRPC_FINAL : public ServerAsyncStreamingInterface,
     }
     }
     // The response is dropped if the status is not OK.
     // The response is dropped if the status is not OK.
     if (status.ok()) {
     if (status.ok()) {
-      finish_ops_.ServerSendStatus(
-          ctx_->trailing_metadata_,
-          finish_ops_.SendMessage(msg));
+      finish_ops_.ServerSendStatus(ctx_->trailing_metadata_,
+                                   finish_ops_.SendMessage(msg));
     } else {
     } else {
       finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status);
       finish_ops_.ServerSendStatus(ctx_->trailing_metadata_, status);
     }
     }

+ 9 - 4
include/grpc/compression.h

@@ -34,6 +34,8 @@
 #ifndef GRPC_COMPRESSION_H
 #ifndef GRPC_COMPRESSION_H
 #define GRPC_COMPRESSION_H
 #define GRPC_COMPRESSION_H
 
 
+#include <stdlib.h>
+
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
 #endif
 #endif
@@ -58,13 +60,16 @@ typedef enum {
   GRPC_COMPRESS_LEVEL_COUNT
   GRPC_COMPRESS_LEVEL_COUNT
 } grpc_compression_level;
 } grpc_compression_level;
 
 
-/** Parses \a name as a grpc_compression_algorithm instance, updating \a
- * algorithm. Returns 1 upon success, 0 otherwise. */
-int grpc_compression_algorithm_parse(const char *name,
+/** Parses the first \a name_length bytes of \a name as a
+ * grpc_compression_algorithm instance, updating \a algorithm. Returns 1 upon
+ * success, 0 otherwise. */
+int grpc_compression_algorithm_parse(const char *name, size_t name_length,
                                      grpc_compression_algorithm *algorithm);
                                      grpc_compression_algorithm *algorithm);
 
 
 /** Updates \a name with the encoding name corresponding to a valid \a
 /** Updates \a name with the encoding name corresponding to a valid \a
- * algorithm.  Returns 1 upon success, 0 otherwise. */
+ * algorithm. Note that the string returned through \a name upon success is
+ * statically allocated and shouldn't be freed. Returns 1 upon success, 0
+ * otherwise. */
 int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm,
 int grpc_compression_algorithm_name(grpc_compression_algorithm algorithm,
                                     char **name);
                                     char **name);
 
 

+ 7 - 13
include/grpc/grpc.h

@@ -378,21 +378,14 @@ typedef struct grpc_op {
 
 
 /** Registers a plugin to be initialized and destroyed with the library.
 /** Registers a plugin to be initialized and destroyed with the library.
 
 
-    The \a init and \a destroy functions will be invoked as part of 
-    \a grpc_init() and \a grpc_shutdown(), respectively. 
+    The \a init and \a destroy functions will be invoked as part of
+    \a grpc_init() and \a grpc_shutdown(), respectively.
     Note that these functions can be invoked an arbitrary number of times
     Note that these functions can be invoked an arbitrary number of times
     (and hence so will \a init and \a destroy).
     (and hence so will \a init and \a destroy).
-    It is safe to pass NULL to either argument. Plugins are destroyed in 
+    It is safe to pass NULL to either argument. Plugins are destroyed in
     the reverse order they were initialized. */
     the reverse order they were initialized. */
 void grpc_register_plugin(void (*init)(void), void (*destroy)(void));
 void grpc_register_plugin(void (*init)(void), void (*destroy)(void));
 
 
-/** Frees the memory used by all the plugin information.
-
-    While grpc_init and grpc_shutdown can be called multiple times, the plugins
-    won't be unregistered and their memory cleaned up unless you call that
-    function. Using atexit(grpc_unregister_all_plugins) is a valid method. */
-void grpc_unregister_all_plugins();
-
 /* Propagation bits: this can be bitwise or-ed to form propagation_mask for
 /* Propagation bits: this can be bitwise or-ed to form propagation_mask for
  * grpc_call */
  * grpc_call */
 /** Propagate deadline */
 /** Propagate deadline */
@@ -561,7 +554,9 @@ grpc_channel *grpc_insecure_channel_create(const char *target,
                                            void *reserved);
                                            void *reserved);
 
 
 /** Create a lame client: this client fails every operation attempted on it. */
 /** Create a lame client: this client fails every operation attempted on it. */
-grpc_channel *grpc_lame_client_channel_create(const char *target);
+grpc_channel *grpc_lame_client_channel_create(const char *target,
+                                              grpc_status_code error_code,
+                                              const char *error_message);
 
 
 /** Close and destroy a grpc channel */
 /** Close and destroy a grpc channel */
 void grpc_channel_destroy(grpc_channel *channel);
 void grpc_channel_destroy(grpc_channel *channel);
@@ -627,8 +622,7 @@ grpc_call_error grpc_server_request_registered_call(
     be specified with args. If no additional configuration is needed, args can
     be specified with args. If no additional configuration is needed, args can
     be NULL. See grpc_channel_args for more. The data in 'args' need only live
     be NULL. See grpc_channel_args for more. The data in 'args' need only live
     through the invocation of this function. */
     through the invocation of this function. */
-grpc_server *grpc_server_create(const grpc_channel_args *args,
-                                void *reserved);
+grpc_server *grpc_server_create(const grpc_channel_args *args, void *reserved);
 
 
 /** Register a completion queue with the server. Must be done for any
 /** Register a completion queue with the server. Must be done for any
     notification completion queue that is passed to grpc_server_request_*_call
     notification completion queue that is passed to grpc_server_request_*_call

+ 1 - 1
include/grpc/status.h

@@ -160,4 +160,4 @@ typedef enum {
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_STATUS_H */
+#endif /* GRPC_STATUS_H */

+ 1 - 1
include/grpc/support/alloc.h

@@ -55,4 +55,4 @@ void gpr_free_aligned(void *ptr);
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_ALLOC_H */
+#endif /* GRPC_SUPPORT_ALLOC_H */

+ 1 - 1
include/grpc/support/atm.h

@@ -89,4 +89,4 @@
 #error could not determine platform for atm
 #error could not determine platform for atm
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_ATM_H */
+#endif /* GRPC_SUPPORT_ATM_H */

+ 1 - 1
include/grpc/support/atm_gcc_atomic.h

@@ -69,4 +69,4 @@ static __inline int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
                                      __ATOMIC_RELAXED);
                                      __ATOMIC_RELAXED);
 }
 }
 
 
-#endif  /* GRPC_SUPPORT_ATM_GCC_ATOMIC_H */
+#endif /* GRPC_SUPPORT_ATM_GCC_ATOMIC_H */

+ 1 - 1
include/grpc/support/atm_gcc_sync.h

@@ -84,4 +84,4 @@ static __inline void gpr_atm_no_barrier_store(gpr_atm *p, gpr_atm value) {
 #define gpr_atm_acq_cas(p, o, n) (__sync_bool_compare_and_swap((p), (o), (n)))
 #define gpr_atm_acq_cas(p, o, n) (__sync_bool_compare_and_swap((p), (o), (n)))
 #define gpr_atm_rel_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n))
 #define gpr_atm_rel_cas(p, o, n) gpr_atm_acq_cas((p), (o), (n))
 
 
-#endif  /* GRPC_SUPPORT_ATM_GCC_SYNC_H */
+#endif /* GRPC_SUPPORT_ATM_GCC_SYNC_H */

+ 18 - 19
include/grpc/support/atm_win32.h

@@ -66,31 +66,31 @@ static __inline int gpr_atm_no_barrier_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
 /* InterlockedCompareExchangePointerNoFence() not available on vista or
 /* InterlockedCompareExchangePointerNoFence() not available on vista or
    windows7 */
    windows7 */
 #ifdef GPR_ARCH_64
 #ifdef GPR_ARCH_64
-  return o == (gpr_atm)InterlockedCompareExchangeAcquire64((volatile LONGLONG *) p,
-                                                           (LONGLONG) n, (LONGLONG) o);
+  return o == (gpr_atm)InterlockedCompareExchangeAcquire64(
+                  (volatile LONGLONG *)p, (LONGLONG)n, (LONGLONG)o);
 #else
 #else
-  return o == (gpr_atm)InterlockedCompareExchangeAcquire((volatile LONG *) p,
-                                                         (LONG) n, (LONG) o);
+  return o == (gpr_atm)InterlockedCompareExchangeAcquire((volatile LONG *)p,
+                                                         (LONG)n, (LONG)o);
 #endif
 #endif
 }
 }
 
 
 static __inline int gpr_atm_acq_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
 static __inline int gpr_atm_acq_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
 #ifdef GPR_ARCH_64
 #ifdef GPR_ARCH_64
-  return o == (gpr_atm)InterlockedCompareExchangeAcquire64((volatile LONGLONG *) p,
-                                                           (LONGLONG) n, (LONGLONG) o);
+  return o == (gpr_atm)InterlockedCompareExchangeAcquire64(
+                  (volatile LONGLONG *)p, (LONGLONG)n, (LONGLONG)o);
 #else
 #else
-  return o == (gpr_atm)InterlockedCompareExchangeAcquire((volatile LONG *) p,
-                                                         (LONG) n, (LONG) o);
+  return o == (gpr_atm)InterlockedCompareExchangeAcquire((volatile LONG *)p,
+                                                         (LONG)n, (LONG)o);
 #endif
 #endif
 }
 }
 
 
 static __inline int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
 static __inline int gpr_atm_rel_cas(gpr_atm *p, gpr_atm o, gpr_atm n) {
 #ifdef GPR_ARCH_64
 #ifdef GPR_ARCH_64
-  return o == (gpr_atm)InterlockedCompareExchangeRelease64((volatile LONGLONG *) p,
-                                                           (LONGLONG) n, (LONGLONG) o);
+  return o == (gpr_atm)InterlockedCompareExchangeRelease64(
+                  (volatile LONGLONG *)p, (LONGLONG)n, (LONGLONG)o);
 #else
 #else
-  return o == (gpr_atm)InterlockedCompareExchangeRelease((volatile LONG *) p,
-                                                         (LONG) n, (LONG) o);
+  return o == (gpr_atm)InterlockedCompareExchangeRelease((volatile LONG *)p,
+                                                         (LONG)n, (LONG)o);
 #endif
 #endif
 }
 }
 
 
@@ -110,17 +110,16 @@ static __inline gpr_atm gpr_atm_full_fetch_add(gpr_atm *p, gpr_atm delta) {
 #ifdef GPR_ARCH_64
 #ifdef GPR_ARCH_64
   do {
   do {
     old = *p;
     old = *p;
-  } while (old != (gpr_atm)InterlockedCompareExchange64((volatile LONGLONG *) p,
-                                                        (LONGLONG) old + delta,
-                                                        (LONGLONG) old));
+  } while (old != (gpr_atm)InterlockedCompareExchange64((volatile LONGLONG *)p,
+                                                        (LONGLONG)old + delta,
+                                                        (LONGLONG)old));
 #else
 #else
   do {
   do {
     old = *p;
     old = *p;
-  } while (old != (gpr_atm)InterlockedCompareExchange((volatile LONG *) p,
-                                                      (LONG) old + delta,
-                                                      (LONG) old));
+  } while (old != (gpr_atm)InterlockedCompareExchange(
+                      (volatile LONG *)p, (LONG)old + delta, (LONG)old));
 #endif
 #endif
   return old;
   return old;
 }
 }
 
 
-#endif  /* GRPC_SUPPORT_ATM_WIN32_H */
+#endif /* GRPC_SUPPORT_ATM_WIN32_H */

+ 1 - 1
include/grpc/support/cmdline.h

@@ -94,4 +94,4 @@ char *gpr_cmdline_usage_string(gpr_cmdline *cl, const char *argv0);
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_CMDLINE_H */
+#endif /* GRPC_SUPPORT_CMDLINE_H */

+ 1 - 1
include/grpc/support/cpu.h

@@ -54,4 +54,4 @@ unsigned gpr_cpu_current_cpu(void);
 }  // extern "C"
 }  // extern "C"
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_CPU_H */
+#endif /* GRPC_SUPPORT_CPU_H */

+ 1 - 1
include/grpc/support/histogram.h

@@ -73,4 +73,4 @@ void gpr_histogram_merge_contents(gpr_histogram *histogram,
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_HISTOGRAM_H */
+#endif /* GRPC_SUPPORT_HISTOGRAM_H */

+ 1 - 1
include/grpc/support/host_port.h

@@ -61,4 +61,4 @@ int gpr_split_host_port(const char *name, char **host, char **port);
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_HOST_PORT_H */
+#endif /* GRPC_SUPPORT_HOST_PORT_H */

+ 1 - 1
include/grpc/support/log.h

@@ -105,4 +105,4 @@ void gpr_set_log_function(gpr_log_func func);
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_LOG_H */
+#endif /* GRPC_SUPPORT_LOG_H */

+ 1 - 1
include/grpc/support/log_win32.h

@@ -48,4 +48,4 @@ char *gpr_format_message(DWORD messageid);
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_LOG_WIN32_H */
+#endif /* GRPC_SUPPORT_LOG_WIN32_H */

+ 2 - 1
include/grpc/support/port_platform.h

@@ -64,7 +64,8 @@
 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
 #undef GRPC_NOMINMAX_WAS_NOT_DEFINED
 #undef NOMINMAX
 #undef NOMINMAX
 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
 #endif /* GRPC_WIN32_LEAN_AND_MEAN_WAS_NOT_DEFINED */
-#endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || defined(WIN32) */
+#endif /* defined(_WIN64) || defined(WIN64) || defined(_WIN32) || \
+          defined(WIN32) */
 
 
 /* Override this file with one for your platform if you need to redefine
 /* Override this file with one for your platform if you need to redefine
    things.  */
    things.  */

+ 1 - 1
include/grpc/support/slice.h

@@ -96,7 +96,7 @@ typedef struct gpr_slice {
 #define GPR_SLICE_LENGTH(slice)                      \
 #define GPR_SLICE_LENGTH(slice)                      \
   ((slice).refcount ? (slice).data.refcounted.length \
   ((slice).refcount ? (slice).data.refcounted.length \
                     : (slice).data.inlined.length)
                     : (slice).data.inlined.length)
-#define GPR_SLICE_SET_LENGTH(slice, newlen)                       \
+#define GPR_SLICE_SET_LENGTH(slice, newlen)                               \
   ((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \
   ((slice).refcount ? ((slice).data.refcounted.length = (size_t)(newlen)) \
                     : ((slice).data.inlined.length = (gpr_uint8)(newlen)))
                     : ((slice).data.inlined.length = (gpr_uint8)(newlen)))
 #define GPR_SLICE_END_PTR(slice) \
 #define GPR_SLICE_END_PTR(slice) \

+ 1 - 1
include/grpc/support/string_util.h

@@ -58,4 +58,4 @@ int gpr_asprintf(char **strp, const char *format, ...);
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_STRING_UTIL_H */
+#endif /* GRPC_SUPPORT_STRING_UTIL_H */

+ 1 - 1
include/grpc/support/subprocess.h

@@ -36,7 +36,7 @@
 
 
 #ifdef __cplusplus
 #ifdef __cplusplus
 extern "C" {
 extern "C" {
-#endif	
+#endif
 
 
 typedef struct gpr_subprocess gpr_subprocess;
 typedef struct gpr_subprocess gpr_subprocess;
 
 

+ 1 - 1
include/grpc/support/sync.h

@@ -312,4 +312,4 @@ gpr_intptr gpr_stats_read(const gpr_stats_counter *c);
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_SYNC_H */
+#endif /* GRPC_SUPPORT_SYNC_H */

+ 4 - 10
include/grpc/support/sync_generic.h

@@ -38,24 +38,18 @@
 #include <grpc/support/atm.h>
 #include <grpc/support/atm.h>
 
 
 /* gpr_event */
 /* gpr_event */
-typedef struct {
-  gpr_atm state;
-} gpr_event;
+typedef struct { gpr_atm state; } gpr_event;
 
 
 #define GPR_EVENT_INIT \
 #define GPR_EVENT_INIT \
   { 0 }
   { 0 }
 
 
 /* gpr_refcount */
 /* gpr_refcount */
-typedef struct {
-  gpr_atm count;
-} gpr_refcount;
+typedef struct { gpr_atm count; } gpr_refcount;
 
 
 /* gpr_stats_counter */
 /* gpr_stats_counter */
-typedef struct {
-  gpr_atm value;
-} gpr_stats_counter;
+typedef struct { gpr_atm value; } gpr_stats_counter;
 
 
 #define GPR_STATS_INIT \
 #define GPR_STATS_INIT \
   { 0 }
   { 0 }
 
 
-#endif  /* GRPC_SUPPORT_SYNC_GENERIC_H */
+#endif /* GRPC_SUPPORT_SYNC_GENERIC_H */

+ 1 - 1
include/grpc/support/sync_posix.h

@@ -44,4 +44,4 @@ typedef pthread_once_t gpr_once;
 
 
 #define GPR_ONCE_INIT PTHREAD_ONCE_INIT
 #define GPR_ONCE_INIT PTHREAD_ONCE_INIT
 
 
-#endif  /* GRPC_SUPPORT_SYNC_POSIX_H */
+#endif /* GRPC_SUPPORT_SYNC_POSIX_H */

+ 1 - 1
include/grpc/support/sync_win32.h

@@ -46,4 +46,4 @@ typedef CONDITION_VARIABLE gpr_cv;
 typedef INIT_ONCE gpr_once;
 typedef INIT_ONCE gpr_once;
 #define GPR_ONCE_INIT INIT_ONCE_STATIC_INIT
 #define GPR_ONCE_INIT INIT_ONCE_STATIC_INIT
 
 
-#endif  /* GRPC_SUPPORT_SYNC_WIN32_H */
+#endif /* GRPC_SUPPORT_SYNC_WIN32_H */

+ 1 - 1
include/grpc/support/thd.h

@@ -88,4 +88,4 @@ void gpr_thd_join(gpr_thd_id t);
 }
 }
 #endif
 #endif
 
 
-#endif  /* GRPC_SUPPORT_THD_H */
+#endif /* GRPC_SUPPORT_THD_H */

+ 2 - 1
include/grpc/support/time.h

@@ -84,7 +84,8 @@ void gpr_time_init(void);
 gpr_timespec gpr_now(gpr_clock_type clock);
 gpr_timespec gpr_now(gpr_clock_type clock);
 
 
 /* Convert a timespec from one clock to another */
 /* Convert a timespec from one clock to another */
-gpr_timespec gpr_convert_clock_type(gpr_timespec t, gpr_clock_type target_clock);
+gpr_timespec gpr_convert_clock_type(gpr_timespec t,
+                                    gpr_clock_type target_clock);
 
 
 /* Return -ve, 0, or +ve according to whether a < b, a == b, or a > b
 /* Return -ve, 0, or +ve according to whether a < b, a == b, or a > b
    respectively.  */
    respectively.  */

+ 2 - 2
include/grpc/support/tls.h

@@ -47,7 +47,7 @@
      GPR_TLS_DECL(foo);
      GPR_TLS_DECL(foo);
    Thread locals always have static scope.
    Thread locals always have static scope.
 
 
-   Initializing a thread local (must be done at library initialization 
+   Initializing a thread local (must be done at library initialization
    time):
    time):
      gpr_tls_init(&foo);
      gpr_tls_init(&foo);
 
 
@@ -58,7 +58,7 @@
      gpr_tls_set(&foo, new_value);
      gpr_tls_set(&foo, new_value);
 
 
    Accessing a thread local:
    Accessing a thread local:
-     current_value = gpr_tls_get(&foo, value); 
+     current_value = gpr_tls_get(&foo, value);
 
 
    ALL functions here may be implemented as macros. */
    ALL functions here may be implemented as macros. */
 
 

+ 7 - 3
include/grpc/support/tls_gcc.h

@@ -42,10 +42,14 @@ struct gpr_gcc_thread_local {
 };
 };
 
 
 #define GPR_TLS_DECL(name) \
 #define GPR_TLS_DECL(name) \
-    static __thread struct gpr_gcc_thread_local name = {0}
+  static __thread struct gpr_gcc_thread_local name = {0}
 
 
-#define gpr_tls_init(tls) do {} while (0)
-#define gpr_tls_destroy(tls) do {} while (0)
+#define gpr_tls_init(tls) \
+  do {                    \
+  } while (0)
+#define gpr_tls_destroy(tls) \
+  do {                       \
+  } while (0)
 #define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value))
 #define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value))
 #define gpr_tls_get(tls) ((tls)->value)
 #define gpr_tls_get(tls) ((tls)->value)
 
 

+ 7 - 3
include/grpc/support/tls_msvc.h

@@ -42,10 +42,14 @@ struct gpr_msvc_thread_local {
 };
 };
 
 
 #define GPR_TLS_DECL(name) \
 #define GPR_TLS_DECL(name) \
-    static __declspec(thread) struct gpr_msvc_thread_local name = {0}
+  static __declspec(thread) struct gpr_msvc_thread_local name = {0}
 
 
-#define gpr_tls_init(tls) do {} while (0)
-#define gpr_tls_destroy(tls) do {} while (0)
+#define gpr_tls_init(tls) \
+  do {                    \
+  } while (0)
+#define gpr_tls_destroy(tls) \
+  do {                       \
+  } while (0)
 #define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value))
 #define gpr_tls_set(tls, new_value) (((tls)->value) = (new_value))
 #define gpr_tls_get(tls) ((tls)->value)
 #define gpr_tls_get(tls) ((tls)->value)
 
 

+ 5 - 5
include/grpc/support/useful.h

@@ -46,10 +46,10 @@
 #define GPR_ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array)))
 #define GPR_ARRAY_SIZE(array) (sizeof(array) / sizeof(*(array)))
 
 
 #define GPR_SWAP(type, a, b) \
 #define GPR_SWAP(type, a, b) \
-  do {                   \
-    type x = a;          \
-    a = b;               \
-    b = x;               \
+  do {                       \
+    type x = a;              \
+    a = b;                   \
+    b = x;                   \
   } while (0)
   } while (0)
 
 
 /** Set the \a n-th bit of \a i (a mutable pointer). */
 /** Set the \a n-th bit of \a i (a mutable pointer). */
@@ -72,4 +72,4 @@
     0x0f0f0f0f) %                                \
     0x0f0f0f0f) %                                \
    255)
    255)
 
 
-#endif  /* GRPC_SUPPORT_USEFUL_H */
+#endif /* GRPC_SUPPORT_USEFUL_H */

+ 1 - 1
src/core/channel/census_filter.h

@@ -41,4 +41,4 @@
 extern const grpc_channel_filter grpc_client_census_filter;
 extern const grpc_channel_filter grpc_client_census_filter;
 extern const grpc_channel_filter grpc_server_census_filter;
 extern const grpc_channel_filter grpc_server_census_filter;
 
 
-#endif  /* GRPC_INTERNAL_CORE_CHANNEL_CENSUS_FILTER_H */
+#endif /* GRPC_INTERNAL_CORE_CHANNEL_CENSUS_FILTER_H */

+ 23 - 15
src/core/channel/client_channel.c

@@ -84,8 +84,10 @@ typedef struct {
   grpc_pollset_set pollset_set;
   grpc_pollset_set pollset_set;
 } channel_data;
 } channel_data;
 
 
-/** We create one watcher for each new lb_policy that is returned from a resolver,
-    to watch for state changes from the lb_policy. When a state change is seen, we
+/** We create one watcher for each new lb_policy that is returned from a
+   resolver,
+    to watch for state changes from the lb_policy. When a state change is seen,
+   we
     update the channel, and create a new watcher */
     update the channel, and create a new watcher */
 typedef struct {
 typedef struct {
   channel_data *chand;
   channel_data *chand;
@@ -380,7 +382,8 @@ static void perform_transport_stream_op(grpc_call_element *elem,
           if (lb_policy) {
           if (lb_policy) {
             grpc_transport_stream_op *op = &calld->waiting_op;
             grpc_transport_stream_op *op = &calld->waiting_op;
             grpc_pollset *bind_pollset = op->bind_pollset;
             grpc_pollset *bind_pollset = op->bind_pollset;
-            grpc_metadata_batch *initial_metadata = &op->send_ops->ops[0].data.metadata;
+            grpc_metadata_batch *initial_metadata =
+                &op->send_ops->ops[0].data.metadata;
             GRPC_LB_POLICY_REF(lb_policy, "pick");
             GRPC_LB_POLICY_REF(lb_policy, "pick");
             gpr_mu_unlock(&chand->mu_config);
             gpr_mu_unlock(&chand->mu_config);
             calld->state = CALL_WAITING_FOR_PICK;
             calld->state = CALL_WAITING_FOR_PICK;
@@ -388,13 +391,14 @@ static void perform_transport_stream_op(grpc_call_element *elem,
             GPR_ASSERT(op->bind_pollset);
             GPR_ASSERT(op->bind_pollset);
             GPR_ASSERT(op->send_ops);
             GPR_ASSERT(op->send_ops);
             GPR_ASSERT(op->send_ops->nops >= 1);
             GPR_ASSERT(op->send_ops->nops >= 1);
-            GPR_ASSERT(
-                op->send_ops->ops[0].type == GRPC_OP_METADATA);
+            GPR_ASSERT(op->send_ops->ops[0].type == GRPC_OP_METADATA);
             gpr_mu_unlock(&calld->mu_state);
             gpr_mu_unlock(&calld->mu_state);
 
 
-            grpc_iomgr_closure_init(&calld->async_setup_task, picked_target, calld);
+            grpc_iomgr_closure_init(&calld->async_setup_task, picked_target,
+                                    calld);
             grpc_lb_policy_pick(lb_policy, bind_pollset, initial_metadata,
             grpc_lb_policy_pick(lb_policy, bind_pollset, initial_metadata,
-                                &calld->picked_channel, &calld->async_setup_task);
+                                &calld->picked_channel,
+                                &calld->async_setup_task);
 
 
             GRPC_LB_POLICY_UNREF(lb_policy, "pick");
             GRPC_LB_POLICY_UNREF(lb_policy, "pick");
           } else if (chand->resolver != NULL) {
           } else if (chand->resolver != NULL) {
@@ -430,7 +434,8 @@ static void cc_start_transport_stream_op(grpc_call_element *elem,
   perform_transport_stream_op(elem, op, 0);
   perform_transport_stream_op(elem, op, 0);
 }
 }
 
 
-static void watch_lb_policy(channel_data *chand, grpc_lb_policy *lb_policy, grpc_connectivity_state current_state);
+static void watch_lb_policy(channel_data *chand, grpc_lb_policy *lb_policy,
+                            grpc_connectivity_state current_state);
 
 
 static void on_lb_policy_state_changed(void *arg, int iomgr_success) {
 static void on_lb_policy_state_changed(void *arg, int iomgr_success) {
   lb_policy_connectivity_watcher *w = arg;
   lb_policy_connectivity_watcher *w = arg;
@@ -450,7 +455,8 @@ static void on_lb_policy_state_changed(void *arg, int iomgr_success) {
   gpr_free(w);
   gpr_free(w);
 }
 }
 
 
-static void watch_lb_policy(channel_data *chand, grpc_lb_policy *lb_policy, grpc_connectivity_state current_state) {
+static void watch_lb_policy(channel_data *chand, grpc_lb_policy *lb_policy,
+                            grpc_connectivity_state current_state) {
   lb_policy_connectivity_watcher *w = gpr_malloc(sizeof(*w));
   lb_policy_connectivity_watcher *w = gpr_malloc(sizeof(*w));
   GRPC_CHANNEL_INTERNAL_REF(chand->master, "watch_lb_policy");
   GRPC_CHANNEL_INTERNAL_REF(chand->master, "watch_lb_policy");
 
 
@@ -499,13 +505,13 @@ static void cc_on_config_changed(void *arg, int iomgr_success) {
   if (iomgr_success && chand->resolver) {
   if (iomgr_success && chand->resolver) {
     grpc_resolver *resolver = chand->resolver;
     grpc_resolver *resolver = chand->resolver;
     GRPC_RESOLVER_REF(resolver, "channel-next");
     GRPC_RESOLVER_REF(resolver, "channel-next");
+    grpc_connectivity_state_set(&chand->state_tracker, state,
+                                "new_lb+resolver");
     gpr_mu_unlock(&chand->mu_config);
     gpr_mu_unlock(&chand->mu_config);
     GRPC_CHANNEL_INTERNAL_REF(chand->master, "resolver");
     GRPC_CHANNEL_INTERNAL_REF(chand->master, "resolver");
     grpc_resolver_next(resolver, &chand->incoming_configuration,
     grpc_resolver_next(resolver, &chand->incoming_configuration,
                        &chand->on_config_changed);
                        &chand->on_config_changed);
     GRPC_RESOLVER_UNREF(resolver, "channel-next");
     GRPC_RESOLVER_UNREF(resolver, "channel-next");
-    grpc_connectivity_state_set(&chand->state_tracker, state,
-                                "new_lb+resolver");
     if (lb_policy != NULL) {
     if (lb_policy != NULL) {
       watch_lb_policy(chand, lb_policy, state);
       watch_lb_policy(chand, lb_policy, state);
     }
     }
@@ -663,7 +669,8 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
   grpc_iomgr_closure_init(&chand->on_config_changed, cc_on_config_changed,
   grpc_iomgr_closure_init(&chand->on_config_changed, cc_on_config_changed,
                           chand);
                           chand);
 
 
-  grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE, "client_channel");
+  grpc_connectivity_state_init(&chand->state_tracker, GRPC_CHANNEL_IDLE,
+                               "client_channel");
 }
 }
 
 
 /* Destructor for channel_data */
 /* Destructor for channel_data */
@@ -747,19 +754,20 @@ void grpc_client_channel_watch_connectivity_state(
   gpr_mu_unlock(&chand->mu_config);
   gpr_mu_unlock(&chand->mu_config);
 }
 }
 
 
-grpc_pollset_set *grpc_client_channel_get_connecting_pollset_set(grpc_channel_element *elem) {
+grpc_pollset_set *grpc_client_channel_get_connecting_pollset_set(
+    grpc_channel_element *elem) {
   channel_data *chand = elem->channel_data;
   channel_data *chand = elem->channel_data;
   return &chand->pollset_set;
   return &chand->pollset_set;
 }
 }
 
 
 void grpc_client_channel_add_interested_party(grpc_channel_element *elem,
 void grpc_client_channel_add_interested_party(grpc_channel_element *elem,
-                                          grpc_pollset *pollset) {
+                                              grpc_pollset *pollset) {
   channel_data *chand = elem->channel_data;
   channel_data *chand = elem->channel_data;
   grpc_pollset_set_add_pollset(&chand->pollset_set, pollset);
   grpc_pollset_set_add_pollset(&chand->pollset_set, pollset);
 }
 }
 
 
 void grpc_client_channel_del_interested_party(grpc_channel_element *elem,
 void grpc_client_channel_del_interested_party(grpc_channel_element *elem,
-                                          grpc_pollset *pollset) {
+                                              grpc_pollset *pollset) {
   channel_data *chand = elem->channel_data;
   channel_data *chand = elem->channel_data;
   grpc_pollset_set_del_pollset(&chand->pollset_set, pollset);
   grpc_pollset_set_del_pollset(&chand->pollset_set, pollset);
 }
 }

+ 4 - 3
src/core/channel/client_channel.h

@@ -59,11 +59,12 @@ void grpc_client_channel_watch_connectivity_state(
     grpc_channel_element *elem, grpc_connectivity_state *state,
     grpc_channel_element *elem, grpc_connectivity_state *state,
     grpc_iomgr_closure *on_complete);
     grpc_iomgr_closure *on_complete);
 
 
-grpc_pollset_set *grpc_client_channel_get_connecting_pollset_set(grpc_channel_element *elem);
+grpc_pollset_set *grpc_client_channel_get_connecting_pollset_set(
+    grpc_channel_element *elem);
 
 
 void grpc_client_channel_add_interested_party(grpc_channel_element *channel,
 void grpc_client_channel_add_interested_party(grpc_channel_element *channel,
-                                          grpc_pollset *pollset);
+                                              grpc_pollset *pollset);
 void grpc_client_channel_del_interested_party(grpc_channel_element *channel,
 void grpc_client_channel_del_interested_party(grpc_channel_element *channel,
-                                          grpc_pollset *pollset);
+                                              grpc_pollset *pollset);
 
 
 #endif /* GRPC_INTERNAL_CORE_CHANNEL_CLIENT_CHANNEL_H */
 #endif /* GRPC_INTERNAL_CORE_CHANNEL_CLIENT_CHANNEL_H */

+ 46 - 11
src/core/channel/compress_filter.c

@@ -35,22 +35,25 @@
 #include <string.h>
 #include <string.h>
 
 
 #include <grpc/compression.h>
 #include <grpc/compression.h>
+#include <grpc/support/alloc.h>
 #include <grpc/support/log.h>
 #include <grpc/support/log.h>
 #include <grpc/support/slice_buffer.h>
 #include <grpc/support/slice_buffer.h>
 
 
 #include "src/core/channel/compress_filter.h"
 #include "src/core/channel/compress_filter.h"
 #include "src/core/channel/channel_args.h"
 #include "src/core/channel/channel_args.h"
 #include "src/core/compression/message_compress.h"
 #include "src/core/compression/message_compress.h"
+#include "src/core/support/string.h"
 
 
 typedef struct call_data {
 typedef struct call_data {
   gpr_slice_buffer slices; /**< Buffers up input slices to be compressed */
   gpr_slice_buffer slices; /**< Buffers up input slices to be compressed */
   grpc_linked_mdelem compression_algorithm_storage;
   grpc_linked_mdelem compression_algorithm_storage;
+  grpc_linked_mdelem accept_encoding_storage;
   int remaining_slice_bytes; /**< Input data to be read, as per BEGIN_MESSAGE */
   int remaining_slice_bytes; /**< Input data to be read, as per BEGIN_MESSAGE */
   int written_initial_metadata; /**< Already processed initial md? */
   int written_initial_metadata; /**< Already processed initial md? */
   /** Compression algorithm we'll try to use. It may be given by incoming
   /** Compression algorithm we'll try to use. It may be given by incoming
    * metadata, or by the channel's default compression settings. */
    * metadata, or by the channel's default compression settings. */
   grpc_compression_algorithm compression_algorithm;
   grpc_compression_algorithm compression_algorithm;
-   /** If true, contents of \a compression_algorithm are authoritative */
+  /** If true, contents of \a compression_algorithm are authoritative */
   int has_compression_algorithm;
   int has_compression_algorithm;
 } call_data;
 } call_data;
 
 
@@ -59,8 +62,12 @@ typedef struct channel_data {
   grpc_mdstr *mdstr_request_compression_algorithm_key;
   grpc_mdstr *mdstr_request_compression_algorithm_key;
   /** Metadata key for the outgoing (used) compression algorithm */
   /** Metadata key for the outgoing (used) compression algorithm */
   grpc_mdstr *mdstr_outgoing_compression_algorithm_key;
   grpc_mdstr *mdstr_outgoing_compression_algorithm_key;
+  /** Metadata key for the accepted encodings */
+  grpc_mdstr *mdstr_compression_capabilities_key;
   /** Precomputed metadata elements for all available compression algorithms */
   /** Precomputed metadata elements for all available compression algorithms */
   grpc_mdelem *mdelem_compression_algorithms[GRPC_COMPRESS_ALGORITHMS_COUNT];
   grpc_mdelem *mdelem_compression_algorithms[GRPC_COMPRESS_ALGORITHMS_COUNT];
+  /** Precomputed metadata elements for the accepted encodings */
+  grpc_mdelem *mdelem_accept_encoding;
   /** The default, channel-level, compression algorithm */
   /** The default, channel-level, compression algorithm */
   grpc_compression_algorithm default_compression_algorithm;
   grpc_compression_algorithm default_compression_algorithm;
 } channel_data;
 } channel_data;
@@ -71,7 +78,7 @@ typedef struct channel_data {
  *
  *
  * Returns 1 if the data was actually compress and 0 otherwise. */
  * Returns 1 if the data was actually compress and 0 otherwise. */
 static int compress_send_sb(grpc_compression_algorithm algorithm,
 static int compress_send_sb(grpc_compression_algorithm algorithm,
-                             gpr_slice_buffer *slices) {
+                            gpr_slice_buffer *slices) {
   int did_compress;
   int did_compress;
   gpr_slice_buffer tmp;
   gpr_slice_buffer tmp;
   gpr_slice_buffer_init(&tmp);
   gpr_slice_buffer_init(&tmp);
@@ -86,14 +93,14 @@ static int compress_send_sb(grpc_compression_algorithm algorithm,
 /** For each \a md element from the incoming metadata, filter out the entry for
 /** For each \a md element from the incoming metadata, filter out the entry for
  * "grpc-encoding", using its value to populate the call data's
  * "grpc-encoding", using its value to populate the call data's
  * compression_algorithm field. */
  * compression_algorithm field. */
-static grpc_mdelem* compression_md_filter(void *user_data, grpc_mdelem *md) {
+static grpc_mdelem *compression_md_filter(void *user_data, grpc_mdelem *md) {
   grpc_call_element *elem = user_data;
   grpc_call_element *elem = user_data;
   call_data *calld = elem->call_data;
   call_data *calld = elem->call_data;
   channel_data *channeld = elem->channel_data;
   channel_data *channeld = elem->channel_data;
 
 
   if (md->key == channeld->mdstr_request_compression_algorithm_key) {
   if (md->key == channeld->mdstr_request_compression_algorithm_key) {
     const char *md_c_str = grpc_mdstr_as_c_string(md->value);
     const char *md_c_str = grpc_mdstr_as_c_string(md->value);
-    if (!grpc_compression_algorithm_parse(md_c_str,
+    if (!grpc_compression_algorithm_parse(md_c_str, strlen(md_c_str),
                                           &calld->compression_algorithm)) {
                                           &calld->compression_algorithm)) {
       gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s'. Ignoring.",
       gpr_log(GPR_ERROR, "Invalid compression algorithm: '%s'. Ignoring.",
               md_c_str);
               md_c_str);
@@ -108,10 +115,10 @@ static grpc_mdelem* compression_md_filter(void *user_data, grpc_mdelem *md) {
 
 
 static int skip_compression(channel_data *channeld, call_data *calld) {
 static int skip_compression(channel_data *channeld, call_data *calld) {
   if (calld->has_compression_algorithm) {
   if (calld->has_compression_algorithm) {
-     if (calld->compression_algorithm == GRPC_COMPRESS_NONE) {
-       return 1;
-     }
-     return 0;  /* we have an actual call-specific algorithm */
+    if (calld->compression_algorithm == GRPC_COMPRESS_NONE) {
+      return 1;
+    }
+    return 0; /* we have an actual call-specific algorithm */
   }
   }
   /* no per-call compression override */
   /* no per-call compression override */
   return channeld->default_compression_algorithm == GRPC_COMPRESS_NONE;
   return channeld->default_compression_algorithm == GRPC_COMPRESS_NONE;
@@ -184,7 +191,7 @@ static void process_send_ops(grpc_call_element *elem,
          * given by GRPC_OP_BEGIN_MESSAGE) */
          * given by GRPC_OP_BEGIN_MESSAGE) */
         calld->remaining_slice_bytes = sop->data.begin_message.length;
         calld->remaining_slice_bytes = sop->data.begin_message.length;
         if (sop->data.begin_message.flags & GRPC_WRITE_NO_COMPRESS) {
         if (sop->data.begin_message.flags & GRPC_WRITE_NO_COMPRESS) {
-          calld->has_compression_algorithm = 1;  /* GPR_TRUE */
+          calld->has_compression_algorithm = 1; /* GPR_TRUE */
           calld->compression_algorithm = GRPC_COMPRESS_NONE;
           calld->compression_algorithm = GRPC_COMPRESS_NONE;
         }
         }
         break;
         break;
@@ -202,10 +209,17 @@ static void process_send_ops(grpc_call_element *elem,
                 channeld->default_compression_algorithm;
                 channeld->default_compression_algorithm;
             calld->has_compression_algorithm = 1; /* GPR_TRUE */
             calld->has_compression_algorithm = 1; /* GPR_TRUE */
           }
           }
+          /* hint compression algorithm */
           grpc_metadata_batch_add_tail(
           grpc_metadata_batch_add_tail(
               &(sop->data.metadata), &calld->compression_algorithm_storage,
               &(sop->data.metadata), &calld->compression_algorithm_storage,
               GRPC_MDELEM_REF(channeld->mdelem_compression_algorithms
               GRPC_MDELEM_REF(channeld->mdelem_compression_algorithms
                                   [calld->compression_algorithm]));
                                   [calld->compression_algorithm]));
+
+          /* convey supported compression algorithms */
+          grpc_metadata_batch_add_tail(
+              &(sop->data.metadata), &calld->accept_encoding_storage,
+              GRPC_MDELEM_REF(channeld->mdelem_accept_encoding));
+
           calld->written_initial_metadata = 1; /* GPR_TRUE */
           calld->written_initial_metadata = 1; /* GPR_TRUE */
         }
         }
         break;
         break;
@@ -279,6 +293,9 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
                               int is_first, int is_last) {
                               int is_first, int is_last) {
   channel_data *channeld = elem->channel_data;
   channel_data *channeld = elem->channel_data;
   grpc_compression_algorithm algo_idx;
   grpc_compression_algorithm algo_idx;
+  const char *supported_algorithms_names[GRPC_COMPRESS_ALGORITHMS_COUNT - 1];
+  char *accept_encoding_str;
+  size_t accept_encoding_str_len;
 
 
   channeld->default_compression_algorithm =
   channeld->default_compression_algorithm =
       grpc_channel_args_get_compression_algorithm(args);
       grpc_channel_args_get_compression_algorithm(args);
@@ -289,6 +306,9 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
   channeld->mdstr_outgoing_compression_algorithm_key =
   channeld->mdstr_outgoing_compression_algorithm_key =
       grpc_mdstr_from_string(mdctx, "grpc-encoding", 0);
       grpc_mdstr_from_string(mdctx, "grpc-encoding", 0);
 
 
+  channeld->mdstr_compression_capabilities_key =
+      grpc_mdstr_from_string(mdctx, "grpc-accept-encoding", 0);
+
   for (algo_idx = 0; algo_idx < GRPC_COMPRESS_ALGORITHMS_COUNT; ++algo_idx) {
   for (algo_idx = 0; algo_idx < GRPC_COMPRESS_ALGORITHMS_COUNT; ++algo_idx) {
     char *algorithm_name;
     char *algorithm_name;
     GPR_ASSERT(grpc_compression_algorithm_name(algo_idx, &algorithm_name) != 0);
     GPR_ASSERT(grpc_compression_algorithm_name(algo_idx, &algorithm_name) != 0);
@@ -297,8 +317,22 @@ static void init_channel_elem(grpc_channel_element *elem, grpc_channel *master,
             mdctx,
             mdctx,
             GRPC_MDSTR_REF(channeld->mdstr_outgoing_compression_algorithm_key),
             GRPC_MDSTR_REF(channeld->mdstr_outgoing_compression_algorithm_key),
             grpc_mdstr_from_string(mdctx, algorithm_name, 0));
             grpc_mdstr_from_string(mdctx, algorithm_name, 0));
+    if (algo_idx > 0) {
+      supported_algorithms_names[algo_idx - 1] = algorithm_name;
+    }
   }
   }
 
 
+  /* TODO(dgq): gpr_strjoin_sep could be made to work with statically allocated
+   * arrays, as to avoid the heap allocs */
+  accept_encoding_str = gpr_strjoin_sep(
+      supported_algorithms_names, GPR_ARRAY_SIZE(supported_algorithms_names),
+      ", ", &accept_encoding_str_len);
+
+  channeld->mdelem_accept_encoding = grpc_mdelem_from_metadata_strings(
+      mdctx, GRPC_MDSTR_REF(channeld->mdstr_compression_capabilities_key),
+      grpc_mdstr_from_string(mdctx, accept_encoding_str, 0));
+  gpr_free(accept_encoding_str);
+
   GPR_ASSERT(!is_last);
   GPR_ASSERT(!is_last);
 }
 }
 
 
@@ -309,10 +343,11 @@ static void destroy_channel_elem(grpc_channel_element *elem) {
 
 
   GRPC_MDSTR_UNREF(channeld->mdstr_request_compression_algorithm_key);
   GRPC_MDSTR_UNREF(channeld->mdstr_request_compression_algorithm_key);
   GRPC_MDSTR_UNREF(channeld->mdstr_outgoing_compression_algorithm_key);
   GRPC_MDSTR_UNREF(channeld->mdstr_outgoing_compression_algorithm_key);
-  for (algo_idx = 0; algo_idx < GRPC_COMPRESS_ALGORITHMS_COUNT;
-       ++algo_idx) {
+  GRPC_MDSTR_UNREF(channeld->mdstr_compression_capabilities_key);
+  for (algo_idx = 0; algo_idx < GRPC_COMPRESS_ALGORITHMS_COUNT; ++algo_idx) {
     GRPC_MDELEM_UNREF(channeld->mdelem_compression_algorithms[algo_idx]);
     GRPC_MDELEM_UNREF(channeld->mdelem_compression_algorithms[algo_idx]);
   }
   }
+  GRPC_MDELEM_UNREF(channeld->mdelem_accept_encoding);
 }
 }
 
 
 const grpc_channel_filter grpc_compress_filter = {
 const grpc_channel_filter grpc_compress_filter = {

+ 1 - 1
src/core/channel/compress_filter.h

@@ -62,4 +62,4 @@
 
 
 extern const grpc_channel_filter grpc_compress_filter;
 extern const grpc_channel_filter grpc_compress_filter;
 
 
-#endif  /* GRPC_INTERNAL_CORE_CHANNEL_COMPRESS_FILTER_H */
+#endif /* GRPC_INTERNAL_CORE_CHANNEL_COMPRESS_FILTER_H */

+ 1 - 1
src/core/channel/http_client_filter.h

@@ -41,4 +41,4 @@ extern const grpc_channel_filter grpc_http_client_filter;
 
 
 #define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme"
 #define GRPC_ARG_HTTP2_SCHEME "grpc.http2_scheme"
 
 
-#endif  /* GRPC_INTERNAL_CORE_CHANNEL_HTTP_CLIENT_FILTER_H */
+#endif /* GRPC_INTERNAL_CORE_CHANNEL_HTTP_CLIENT_FILTER_H */

+ 1 - 1
src/core/channel/http_server_filter.h

@@ -39,4 +39,4 @@
 /* Processes metadata on the client side for HTTP2 transports */
 /* Processes metadata on the client side for HTTP2 transports */
 extern const grpc_channel_filter grpc_http_server_filter;
 extern const grpc_channel_filter grpc_http_server_filter;
 
 
-#endif  /* GRPC_INTERNAL_CORE_CHANNEL_HTTP_SERVER_FILTER_H */
+#endif /* GRPC_INTERNAL_CORE_CHANNEL_HTTP_SERVER_FILTER_H */

+ 1 - 1
src/core/channel/noop_filter.h

@@ -41,4 +41,4 @@
    customize for their own filters */
    customize for their own filters */
 extern const grpc_channel_filter grpc_no_op_filter;
 extern const grpc_channel_filter grpc_no_op_filter;
 
 
-#endif  /* GRPC_INTERNAL_CORE_CHANNEL_NOOP_FILTER_H */
+#endif /* GRPC_INTERNAL_CORE_CHANNEL_NOOP_FILTER_H */

+ 2 - 1
src/core/client_config/resolvers/dns_resolver.c

@@ -219,7 +219,8 @@ static grpc_resolver *dns_create(
   default_host_arg.type = GRPC_ARG_STRING;
   default_host_arg.type = GRPC_ARG_STRING;
   default_host_arg.key = GRPC_ARG_DEFAULT_AUTHORITY;
   default_host_arg.key = GRPC_ARG_DEFAULT_AUTHORITY;
   default_host_arg.value.string = host;
   default_host_arg.value.string = host;
-  subchannel_factory = grpc_subchannel_factory_add_channel_arg(subchannel_factory, &default_host_arg);
+  subchannel_factory = grpc_subchannel_factory_add_channel_arg(
+      subchannel_factory, &default_host_arg);
 
 
   gpr_free(host);
   gpr_free(host);
   gpr_free(port);
   gpr_free(port);

+ 4 - 4
src/core/client_config/resolvers/zookeeper_resolver.c

@@ -142,7 +142,7 @@ static void zookeeper_next(grpc_resolver *resolver,
   gpr_mu_unlock(&r->mu);
   gpr_mu_unlock(&r->mu);
 }
 }
 
 
-/** Zookeeper global watcher for connection management 
+/** Zookeeper global watcher for connection management
     TODO: better connection management besides logs */
     TODO: better connection management besides logs */
 static void zookeeper_global_watcher(zhandle_t *zookeeper_handle, int type,
 static void zookeeper_global_watcher(zhandle_t *zookeeper_handle, int type,
                                      int state, const char *path,
                                      int state, const char *path,
@@ -172,7 +172,7 @@ static void zookeeper_watcher(zhandle_t *zookeeper_handle, int type, int state,
   }
   }
 }
 }
 
 
-/** Callback function after getting all resolved addresses  
+/** Callback function after getting all resolved addresses
     Creates a subchannel for each address */
     Creates a subchannel for each address */
 static void zookeeper_on_resolved(void *arg,
 static void zookeeper_on_resolved(void *arg,
                                   grpc_resolved_addresses *addresses) {
                                   grpc_resolved_addresses *addresses) {
@@ -249,7 +249,7 @@ static char *zookeeper_parse_address(const char *value, int value_len) {
   grpc_json *cur;
   grpc_json *cur;
   const char *host;
   const char *host;
   const char *port;
   const char *port;
-  char* buffer;
+  char *buffer;
   char *address = NULL;
   char *address = NULL;
 
 
   buffer = gpr_malloc(value_len);
   buffer = gpr_malloc(value_len);
@@ -449,7 +449,7 @@ static grpc_resolver *zookeeper_create(
   gpr_mu_init(&r->mu);
   gpr_mu_init(&r->mu);
   grpc_resolver_init(&r->base, &zookeeper_resolver_vtable);
   grpc_resolver_init(&r->base, &zookeeper_resolver_vtable);
   r->name = gpr_strdup(path);
   r->name = gpr_strdup(path);
-  
+
   r->subchannel_factory = subchannel_factory;
   r->subchannel_factory = subchannel_factory;
   r->lb_policy_factory = lb_policy_factory;
   r->lb_policy_factory = lb_policy_factory;
   grpc_subchannel_factory_ref(subchannel_factory);
   grpc_subchannel_factory_ref(subchannel_factory);

+ 2 - 0
src/core/client_config/subchannel.h

@@ -91,8 +91,10 @@ void grpc_subchannel_notify_on_state_change(grpc_subchannel *channel,
                                             grpc_connectivity_state *state,
                                             grpc_connectivity_state *state,
                                             grpc_iomgr_closure *notify);
                                             grpc_iomgr_closure *notify);
 
 
+/** express interest in \a channel's activities through \a pollset. */
 void grpc_subchannel_add_interested_party(grpc_subchannel *channel,
 void grpc_subchannel_add_interested_party(grpc_subchannel *channel,
                                           grpc_pollset *pollset);
                                           grpc_pollset *pollset);
+/** stop following \a channel's activity through \a pollset. */
 void grpc_subchannel_del_interested_party(grpc_subchannel *channel,
 void grpc_subchannel_del_interested_party(grpc_subchannel *channel,
                                           grpc_pollset *pollset);
                                           grpc_pollset *pollset);
 
 

+ 5 - 5
src/core/client_config/subchannel_factory_decorators/add_channel_arg.c

@@ -35,9 +35,9 @@
 #include "src/core/client_config/subchannel_factory_decorators/merge_channel_args.h"
 #include "src/core/client_config/subchannel_factory_decorators/merge_channel_args.h"
 
 
 grpc_subchannel_factory *grpc_subchannel_factory_add_channel_arg(
 grpc_subchannel_factory *grpc_subchannel_factory_add_channel_arg(
-		grpc_subchannel_factory *input, const grpc_arg *arg) {
-	grpc_channel_args args;
-	args.num_args = 1;
-	args.args = (grpc_arg *)arg;
-	return grpc_subchannel_factory_merge_channel_args(input, &args);
+    grpc_subchannel_factory *input, const grpc_arg *arg) {
+  grpc_channel_args args;
+  args.num_args = 1;
+  args.args = (grpc_arg *)arg;
+  return grpc_subchannel_factory_merge_channel_args(input, &args);
 }
 }

+ 3 - 2
src/core/client_config/subchannel_factory_decorators/add_channel_arg.h

@@ -40,6 +40,7 @@
     channel_args by adding a new argument; ownership of input, arg is retained
     channel_args by adding a new argument; ownership of input, arg is retained
     by the caller. */
     by the caller. */
 grpc_subchannel_factory *grpc_subchannel_factory_add_channel_arg(
 grpc_subchannel_factory *grpc_subchannel_factory_add_channel_arg(
-		grpc_subchannel_factory *input, const grpc_arg *arg);
+    grpc_subchannel_factory *input, const grpc_arg *arg);
 
 
-#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_FACTORY_DECORATORS_ADD_CHANNEL_ARG_H */
+#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_FACTORY_DECORATORS_ADD_CHANNEL_ARG_H \
+          */

+ 2 - 2
src/core/client_config/subchannel_factory_decorators/merge_channel_args.c

@@ -50,7 +50,7 @@ static void merge_args_factory_ref(grpc_subchannel_factory *scf) {
 static void merge_args_factory_unref(grpc_subchannel_factory *scf) {
 static void merge_args_factory_unref(grpc_subchannel_factory *scf) {
   merge_args_factory *f = (merge_args_factory *)scf;
   merge_args_factory *f = (merge_args_factory *)scf;
   if (gpr_unref(&f->refs)) {
   if (gpr_unref(&f->refs)) {
-  	grpc_subchannel_factory_unref(f->wrapped);
+    grpc_subchannel_factory_unref(f->wrapped);
     grpc_channel_args_destroy(f->merge_args);
     grpc_channel_args_destroy(f->merge_args);
     gpr_free(f);
     gpr_free(f);
   }
   }
@@ -73,7 +73,7 @@ static const grpc_subchannel_factory_vtable merge_args_factory_vtable = {
     merge_args_factory_create_subchannel};
     merge_args_factory_create_subchannel};
 
 
 grpc_subchannel_factory *grpc_subchannel_factory_merge_channel_args(
 grpc_subchannel_factory *grpc_subchannel_factory_merge_channel_args(
-		grpc_subchannel_factory *input, const grpc_channel_args *args) {
+    grpc_subchannel_factory *input, const grpc_channel_args *args) {
   merge_args_factory *f = gpr_malloc(sizeof(*f));
   merge_args_factory *f = gpr_malloc(sizeof(*f));
   f->base.vtable = &merge_args_factory_vtable;
   f->base.vtable = &merge_args_factory_vtable;
   gpr_ref_init(&f->refs, 1);
   gpr_ref_init(&f->refs, 1);

+ 3 - 2
src/core/client_config/subchannel_factory_decorators/merge_channel_args.h

@@ -40,6 +40,7 @@
     channel_args by adding a new argument; ownership of input, args is retained
     channel_args by adding a new argument; ownership of input, args is retained
     by the caller. */
     by the caller. */
 grpc_subchannel_factory *grpc_subchannel_factory_merge_channel_args(
 grpc_subchannel_factory *grpc_subchannel_factory_merge_channel_args(
-		grpc_subchannel_factory *input, const grpc_channel_args *args);
+    grpc_subchannel_factory *input, const grpc_channel_args *args);
 
 
-#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_FACTORY_DECORATORS_MERGE_CHANNEL_ARGS_H */
+#endif /* GRPC_INTERNAL_CORE_CLIENT_CONFIG_SUBCHANNEL_FACTORY_DECORATORS_MERGE_CHANNEL_ARGS_H \
+          */

+ 11 - 4
src/core/compression/algorithm.c

@@ -35,13 +35,20 @@
 #include <string.h>
 #include <string.h>
 #include <grpc/compression.h>
 #include <grpc/compression.h>
 
 
-int grpc_compression_algorithm_parse(const char* name,
+int grpc_compression_algorithm_parse(const char *name, size_t name_length,
                                      grpc_compression_algorithm *algorithm) {
                                      grpc_compression_algorithm *algorithm) {
-  if (strcmp(name, "identity") == 0) {
+  /* we use strncmp not only because it's safer (even though in this case it
+   * doesn't matter, given that we are comparing against string literals, but
+   * because this way we needn't have "name" nil-terminated (useful for slice
+   * data, for example) */
+  if (name_length == 0) {
+    return 0;
+  }
+  if (strncmp(name, "identity", name_length) == 0) {
     *algorithm = GRPC_COMPRESS_NONE;
     *algorithm = GRPC_COMPRESS_NONE;
-  } else if (strcmp(name, "gzip") == 0) {
+  } else if (strncmp(name, "gzip", name_length) == 0) {
     *algorithm = GRPC_COMPRESS_GZIP;
     *algorithm = GRPC_COMPRESS_GZIP;
-  } else if (strcmp(name, "deflate") == 0) {
+  } else if (strncmp(name, "deflate", name_length) == 0) {
     *algorithm = GRPC_COMPRESS_DEFLATE;
     *algorithm = GRPC_COMPRESS_DEFLATE;
   } else {
   } else {
     return 0;
     return 0;

+ 4 - 4
src/core/debug/trace.c

@@ -61,8 +61,8 @@ static void add(const char *beg, const char *end, char ***ss, size_t *ns) {
   size_t np = n + 1;
   size_t np = n + 1;
   char *s = gpr_malloc(end - beg + 1);
   char *s = gpr_malloc(end - beg + 1);
   memcpy(s, beg, end - beg);
   memcpy(s, beg, end - beg);
-  s[end-beg] = 0;
-  *ss = gpr_realloc(*ss, sizeof(char**) * np);
+  s[end - beg] = 0;
+  *ss = gpr_realloc(*ss, sizeof(char **) * np);
   (*ss)[n] = s;
   (*ss)[n] = s;
   *ns = np;
   *ns = np;
 }
 }
@@ -73,7 +73,7 @@ static void split(const char *s, char ***ss, size_t *ns) {
     add(s, s + strlen(s), ss, ns);
     add(s, s + strlen(s), ss, ns);
   } else {
   } else {
     add(s, c, ss, ns);
     add(s, c, ss, ns);
-    split(c+1, ss, ns);
+    split(c + 1, ss, ns);
   }
   }
 }
 }
 
 
@@ -125,7 +125,7 @@ int grpc_tracer_set_enabled(const char *name, int enabled) {
     }
     }
     if (!found) {
     if (!found) {
       gpr_log(GPR_ERROR, "Unknown trace var: '%s'", name);
       gpr_log(GPR_ERROR, "Unknown trace var: '%s'", name);
-      return 0;  /* early return */
+      return 0; /* early return */
     }
     }
   }
   }
   return 1;
   return 1;

+ 1 - 1
src/core/debug/trace.h

@@ -40,4 +40,4 @@ void grpc_register_tracer(const char *name, int *flag);
 void grpc_tracer_init(const char *env_var_name);
 void grpc_tracer_init(const char *env_var_name);
 void grpc_tracer_shutdown(void);
 void grpc_tracer_shutdown(void);
 
 
-#endif  /* GRPC_INTERNAL_CORE_DEBUG_TRACE_H */
+#endif /* GRPC_INTERNAL_CORE_DEBUG_TRACE_H */

+ 4 - 2
src/core/httpcli/format_request.c

@@ -43,7 +43,8 @@
 #include <grpc/support/string_util.h>
 #include <grpc/support/string_util.h>
 #include <grpc/support/useful.h>
 #include <grpc/support/useful.h>
 
 
-static void fill_common_header(const grpc_httpcli_request *request, gpr_strvec *buf) {
+static void fill_common_header(const grpc_httpcli_request *request,
+                               gpr_strvec *buf) {
   size_t i;
   size_t i;
   gpr_strvec_add(buf, gpr_strdup(request->path));
   gpr_strvec_add(buf, gpr_strdup(request->path));
   gpr_strvec_add(buf, gpr_strdup(" HTTP/1.0\r\n"));
   gpr_strvec_add(buf, gpr_strdup(" HTTP/1.0\r\n"));
@@ -52,7 +53,8 @@ static void fill_common_header(const grpc_httpcli_request *request, gpr_strvec *
   gpr_strvec_add(buf, gpr_strdup(request->host));
   gpr_strvec_add(buf, gpr_strdup(request->host));
   gpr_strvec_add(buf, gpr_strdup("\r\n"));
   gpr_strvec_add(buf, gpr_strdup("\r\n"));
   gpr_strvec_add(buf, gpr_strdup("Connection: close\r\n"));
   gpr_strvec_add(buf, gpr_strdup("Connection: close\r\n"));
-  gpr_strvec_add(buf, gpr_strdup("User-Agent: "GRPC_HTTPCLI_USER_AGENT"\r\n"));
+  gpr_strvec_add(buf,
+                 gpr_strdup("User-Agent: " GRPC_HTTPCLI_USER_AGENT "\r\n"));
   /* user supplied headers */
   /* user supplied headers */
   for (i = 0; i < request->hdr_count; i++) {
   for (i = 0; i < request->hdr_count; i++) {
     gpr_strvec_add(buf, gpr_strdup(request->hdrs[i].key));
     gpr_strvec_add(buf, gpr_strdup(request->hdrs[i].key));

+ 1 - 1
src/core/httpcli/format_request.h

@@ -42,4 +42,4 @@ gpr_slice grpc_httpcli_format_post_request(const grpc_httpcli_request *request,
                                            const char *body_bytes,
                                            const char *body_bytes,
                                            size_t body_size);
                                            size_t body_size);
 
 
-#endif  /* GRPC_INTERNAL_CORE_HTTPCLI_FORMAT_REQUEST_H */
+#endif /* GRPC_INTERNAL_CORE_HTTPCLI_FORMAT_REQUEST_H */

+ 1 - 1
src/core/httpcli/parser.h

@@ -61,4 +61,4 @@ void grpc_httpcli_parser_destroy(grpc_httpcli_parser *parser);
 int grpc_httpcli_parser_parse(grpc_httpcli_parser *parser, gpr_slice slice);
 int grpc_httpcli_parser_parse(grpc_httpcli_parser *parser, gpr_slice slice);
 int grpc_httpcli_parser_eof(grpc_httpcli_parser *parser);
 int grpc_httpcli_parser_eof(grpc_httpcli_parser *parser);
 
 
-#endif  /* GRPC_INTERNAL_CORE_HTTPCLI_PARSER_H */
+#endif /* GRPC_INTERNAL_CORE_HTTPCLI_PARSER_H */

+ 2 - 3
src/core/iomgr/alarm.c

@@ -105,8 +105,7 @@ void grpc_alarm_list_init(gpr_timespec now) {
 
 
 void grpc_alarm_list_shutdown(void) {
 void grpc_alarm_list_shutdown(void) {
   int i;
   int i;
-  while (run_some_expired_alarms(NULL, gpr_inf_future(g_clock_type), NULL,
-                                 0))
+  while (run_some_expired_alarms(NULL, gpr_inf_future(g_clock_type), NULL, 0))
     ;
     ;
   for (i = 0; i < NUM_SHARDS; i++) {
   for (i = 0; i < NUM_SHARDS; i++) {
     shard_type *shard = &g_shards[i];
     shard_type *shard = &g_shards[i];
@@ -362,7 +361,7 @@ static int run_some_expired_alarms(gpr_mu *drop_mu, gpr_timespec now,
 int grpc_alarm_check(gpr_mu *drop_mu, gpr_timespec now, gpr_timespec *next) {
 int grpc_alarm_check(gpr_mu *drop_mu, gpr_timespec now, gpr_timespec *next) {
   GPR_ASSERT(now.clock_type == g_clock_type);
   GPR_ASSERT(now.clock_type == g_clock_type);
   return run_some_expired_alarms(
   return run_some_expired_alarms(
-      drop_mu, now, next, 
+      drop_mu, now, next,
       gpr_time_cmp(now, gpr_inf_future(now.clock_type)) != 0);
       gpr_time_cmp(now, gpr_inf_future(now.clock_type)) != 0);
 }
 }
 
 

+ 1 - 1
src/core/iomgr/alarm.h

@@ -86,4 +86,4 @@ void grpc_alarm_init(grpc_alarm *alarm, gpr_timespec deadline,
    Requires:  cancel() must happen after add() on a given alarm */
    Requires:  cancel() must happen after add() on a given alarm */
 void grpc_alarm_cancel(grpc_alarm *alarm);
 void grpc_alarm_cancel(grpc_alarm *alarm);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_ALARM_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_ALARM_H */

+ 5 - 5
src/core/iomgr/alarm_heap.c

@@ -66,11 +66,11 @@ static void adjust_downwards(grpc_alarm **first, int i, int length,
     int next_i;
     int next_i;
     if (left_child >= length) break;
     if (left_child >= length) break;
     right_child = left_child + 1;
     right_child = left_child + 1;
-    next_i =
-        right_child < length && gpr_time_cmp(first[left_child]->deadline,
-                                             first[right_child]->deadline) < 0
-            ? right_child
-            : left_child;
+    next_i = right_child < length &&
+                     gpr_time_cmp(first[left_child]->deadline,
+                                  first[right_child]->deadline) < 0
+                 ? right_child
+                 : left_child;
     if (gpr_time_cmp(t->deadline, first[next_i]->deadline) >= 0) break;
     if (gpr_time_cmp(t->deadline, first[next_i]->deadline) >= 0) break;
     first[i] = first[next_i];
     first[i] = first[next_i];
     first[i]->heap_index = i;
     first[i]->heap_index = i;

+ 1 - 1
src/core/iomgr/alarm_heap.h

@@ -54,4 +54,4 @@ void grpc_alarm_heap_pop(grpc_alarm_heap *heap);
 
 
 int grpc_alarm_heap_is_empty(grpc_alarm_heap *heap);
 int grpc_alarm_heap_is_empty(grpc_alarm_heap *heap);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_ALARM_HEAP_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_ALARM_HEAP_H */

+ 1 - 1
src/core/iomgr/alarm_internal.h

@@ -59,4 +59,4 @@ gpr_timespec grpc_alarm_list_next_timeout(void);
 
 
 void grpc_kick_poller(void);
 void grpc_kick_poller(void);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_ALARM_INTERNAL_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_ALARM_INTERNAL_H */

+ 2 - 1
src/core/iomgr/endpoint.c

@@ -50,7 +50,8 @@ void grpc_endpoint_add_to_pollset(grpc_endpoint *ep, grpc_pollset *pollset) {
   ep->vtable->add_to_pollset(ep, pollset);
   ep->vtable->add_to_pollset(ep, pollset);
 }
 }
 
 
-void grpc_endpoint_add_to_pollset_set(grpc_endpoint *ep, grpc_pollset_set *pollset_set) {
+void grpc_endpoint_add_to_pollset_set(grpc_endpoint *ep,
+                                      grpc_pollset_set *pollset_set) {
   ep->vtable->add_to_pollset_set(ep, pollset_set);
   ep->vtable->add_to_pollset_set(ep, pollset_set);
 }
 }
 
 

+ 3 - 2
src/core/iomgr/endpoint.h

@@ -103,10 +103,11 @@ void grpc_endpoint_destroy(grpc_endpoint *ep);
 /* Add an endpoint to a pollset, so that when the pollset is polled, events from
 /* Add an endpoint to a pollset, so that when the pollset is polled, events from
    this endpoint are considered */
    this endpoint are considered */
 void grpc_endpoint_add_to_pollset(grpc_endpoint *ep, grpc_pollset *pollset);
 void grpc_endpoint_add_to_pollset(grpc_endpoint *ep, grpc_pollset *pollset);
-void grpc_endpoint_add_to_pollset_set(grpc_endpoint *ep, grpc_pollset_set *pollset_set);
+void grpc_endpoint_add_to_pollset_set(grpc_endpoint *ep,
+                                      grpc_pollset_set *pollset_set);
 
 
 struct grpc_endpoint {
 struct grpc_endpoint {
   const grpc_endpoint_vtable *vtable;
   const grpc_endpoint_vtable *vtable;
 };
 };
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_ENDPOINT_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_ENDPOINT_H */

+ 1 - 1
src/core/iomgr/endpoint_pair.h

@@ -44,4 +44,4 @@ typedef struct {
 grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char *name,
 grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char *name,
                                                    size_t read_slice_size);
                                                    size_t read_slice_size);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_ENDPOINT_PAIR_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_ENDPOINT_PAIR_H */

+ 13 - 7
src/core/iomgr/endpoint_pair_windows.c

@@ -52,21 +52,26 @@ static void create_sockets(SOCKET sv[2]) {
   SOCKADDR_IN addr;
   SOCKADDR_IN addr;
   int addr_len = sizeof(addr);
   int addr_len = sizeof(addr);
 
 
-  lst_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
+  lst_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0,
+                       WSA_FLAG_OVERLAPPED);
   GPR_ASSERT(lst_sock != INVALID_SOCKET);
   GPR_ASSERT(lst_sock != INVALID_SOCKET);
 
 
   memset(&addr, 0, sizeof(addr));
   memset(&addr, 0, sizeof(addr));
   addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
   addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
   addr.sin_family = AF_INET;
   addr.sin_family = AF_INET;
-  GPR_ASSERT(bind(lst_sock, (struct sockaddr*)&addr, sizeof(addr)) != SOCKET_ERROR);
+  GPR_ASSERT(bind(lst_sock, (struct sockaddr *)&addr, sizeof(addr)) !=
+             SOCKET_ERROR);
   GPR_ASSERT(listen(lst_sock, SOMAXCONN) != SOCKET_ERROR);
   GPR_ASSERT(listen(lst_sock, SOMAXCONN) != SOCKET_ERROR);
-  GPR_ASSERT(getsockname(lst_sock, (struct sockaddr*)&addr, &addr_len) != SOCKET_ERROR);
+  GPR_ASSERT(getsockname(lst_sock, (struct sockaddr *)&addr, &addr_len) !=
+             SOCKET_ERROR);
 
 
-  cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED);
+  cli_sock = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0,
+                       WSA_FLAG_OVERLAPPED);
   GPR_ASSERT(cli_sock != INVALID_SOCKET);
   GPR_ASSERT(cli_sock != INVALID_SOCKET);
 
 
-  GPR_ASSERT(WSAConnect(cli_sock, (struct sockaddr*)&addr, addr_len, NULL, NULL, NULL, NULL) == 0);
-  svr_sock = accept(lst_sock, (struct sockaddr*)&addr, &addr_len);
+  GPR_ASSERT(WSAConnect(cli_sock, (struct sockaddr *)&addr, addr_len, NULL,
+                        NULL, NULL, NULL) == 0);
+  svr_sock = accept(lst_sock, (struct sockaddr *)&addr, &addr_len);
   GPR_ASSERT(svr_sock != INVALID_SOCKET);
   GPR_ASSERT(svr_sock != INVALID_SOCKET);
 
 
   closesocket(lst_sock);
   closesocket(lst_sock);
@@ -77,7 +82,8 @@ static void create_sockets(SOCKET sv[2]) {
   sv[0] = svr_sock;
   sv[0] = svr_sock;
 }
 }
 
 
-grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char *name, size_t read_slice_size) {
+grpc_endpoint_pair grpc_iomgr_create_endpoint_pair(const char *name,
+                                                   size_t read_slice_size) {
   SOCKET sv[2];
   SOCKET sv[2];
   grpc_endpoint_pair p;
   grpc_endpoint_pair p;
   create_sockets(sv);
   create_sockets(sv);

+ 16 - 19
src/core/iomgr/iocp_windows.c

@@ -65,18 +65,17 @@ static void do_iocp_work() {
   LPOVERLAPPED overlapped;
   LPOVERLAPPED overlapped;
   grpc_winsocket *socket;
   grpc_winsocket *socket;
   grpc_winsocket_callback_info *info;
   grpc_winsocket_callback_info *info;
-  void(*f)(void *, int) = NULL;
+  void (*f)(void *, int) = NULL;
   void *opaque = NULL;
   void *opaque = NULL;
-  success = GetQueuedCompletionStatus(g_iocp, &bytes,
-                                      &completion_key, &overlapped,
-                                      INFINITE);
+  success = GetQueuedCompletionStatus(g_iocp, &bytes, &completion_key,
+                                      &overlapped, INFINITE);
   /* success = 0 and overlapped = NULL means the deadline got attained.
   /* success = 0 and overlapped = NULL means the deadline got attained.
      Which is impossible. since our wait time is +inf */
      Which is impossible. since our wait time is +inf */
   GPR_ASSERT(success || overlapped);
   GPR_ASSERT(success || overlapped);
   GPR_ASSERT(completion_key && overlapped);
   GPR_ASSERT(completion_key && overlapped);
   if (overlapped == &g_iocp_custom_overlap) {
   if (overlapped == &g_iocp_custom_overlap) {
     gpr_atm_full_fetch_add(&g_custom_events, -1);
     gpr_atm_full_fetch_add(&g_custom_events, -1);
-    if (completion_key == (ULONG_PTR) &g_iocp_kick_token) {
+    if (completion_key == (ULONG_PTR)&g_iocp_kick_token) {
       /* We were awoken from a kick. */
       /* We were awoken from a kick. */
       return;
       return;
     }
     }
@@ -84,7 +83,7 @@ static void do_iocp_work() {
     abort();
     abort();
   }
   }
 
 
-  socket = (grpc_winsocket*) completion_key;
+  socket = (grpc_winsocket *)completion_key;
   if (overlapped == &socket->write_info.overlapped) {
   if (overlapped == &socket->write_info.overlapped) {
     info = &socket->write_info;
     info = &socket->write_info;
   } else if (overlapped == &socket->read_info.overlapped) {
   } else if (overlapped == &socket->read_info.overlapped) {
@@ -121,8 +120,7 @@ static void do_iocp_work() {
 }
 }
 
 
 static void iocp_loop(void *p) {
 static void iocp_loop(void *p) {
-  while (gpr_atm_acq_load(&g_orphans) ||
-         gpr_atm_acq_load(&g_custom_events) ||
+  while (gpr_atm_acq_load(&g_orphans) || gpr_atm_acq_load(&g_custom_events) ||
          !gpr_event_get(&g_shutdown_iocp)) {
          !gpr_event_get(&g_shutdown_iocp)) {
     grpc_maybe_call_delayed_callbacks(NULL, 1);
     grpc_maybe_call_delayed_callbacks(NULL, 1);
     do_iocp_work();
     do_iocp_work();
@@ -134,8 +132,8 @@ static void iocp_loop(void *p) {
 void grpc_iocp_init(void) {
 void grpc_iocp_init(void) {
   gpr_thd_id id;
   gpr_thd_id id;
 
 
-  g_iocp = CreateIoCompletionPort(INVALID_HANDLE_VALUE,
-                                  NULL, (ULONG_PTR)NULL, 0);
+  g_iocp =
+      CreateIoCompletionPort(INVALID_HANDLE_VALUE, NULL, (ULONG_PTR)NULL, 0);
   GPR_ASSERT(g_iocp);
   GPR_ASSERT(g_iocp);
 
 
   gpr_event_init(&g_iocp_done);
   gpr_event_init(&g_iocp_done);
@@ -147,8 +145,7 @@ void grpc_iocp_kick(void) {
   BOOL success;
   BOOL success;
 
 
   gpr_atm_full_fetch_add(&g_custom_events, 1);
   gpr_atm_full_fetch_add(&g_custom_events, 1);
-  success = PostQueuedCompletionStatus(g_iocp, 0,
-                                       (ULONG_PTR) &g_iocp_kick_token,
+  success = PostQueuedCompletionStatus(g_iocp, 0, (ULONG_PTR)&g_iocp_kick_token,
                                        &g_iocp_custom_overlap);
                                        &g_iocp_custom_overlap);
   GPR_ASSERT(success);
   GPR_ASSERT(success);
 }
 }
@@ -165,8 +162,8 @@ void grpc_iocp_shutdown(void) {
 void grpc_iocp_add_socket(grpc_winsocket *socket) {
 void grpc_iocp_add_socket(grpc_winsocket *socket) {
   HANDLE ret;
   HANDLE ret;
   if (socket->added_to_iocp) return;
   if (socket->added_to_iocp) return;
-  ret = CreateIoCompletionPort((HANDLE)socket->socket,
-                               g_iocp, (gpr_uintptr) socket, 0);
+  ret = CreateIoCompletionPort((HANDLE)socket->socket, g_iocp,
+                               (gpr_uintptr)socket, 0);
   if (!ret) {
   if (!ret) {
     char *utf8_message = gpr_format_message(WSAGetLastError());
     char *utf8_message = gpr_format_message(WSAGetLastError());
     gpr_log(GPR_ERROR, "Unable to add socket to iocp: %s", utf8_message);
     gpr_log(GPR_ERROR, "Unable to add socket to iocp: %s", utf8_message);
@@ -189,7 +186,7 @@ void grpc_iocp_socket_orphan(grpc_winsocket *socket) {
    the callback now.
    the callback now.
    -) The IOCP hasn't completed yet, and we're queuing it for later. */
    -) The IOCP hasn't completed yet, and we're queuing it for later. */
 static void socket_notify_on_iocp(grpc_winsocket *socket,
 static void socket_notify_on_iocp(grpc_winsocket *socket,
-                                  void(*cb)(void *, int), void *opaque,
+                                  void (*cb)(void *, int), void *opaque,
                                   grpc_winsocket_callback_info *info) {
                                   grpc_winsocket_callback_info *info) {
   int run_now = 0;
   int run_now = 0;
   GPR_ASSERT(!info->cb);
   GPR_ASSERT(!info->cb);
@@ -206,13 +203,13 @@ static void socket_notify_on_iocp(grpc_winsocket *socket,
 }
 }
 
 
 void grpc_socket_notify_on_write(grpc_winsocket *socket,
 void grpc_socket_notify_on_write(grpc_winsocket *socket,
-                                 void(*cb)(void *, int), void *opaque) {
+                                 void (*cb)(void *, int), void *opaque) {
   socket_notify_on_iocp(socket, cb, opaque, &socket->write_info);
   socket_notify_on_iocp(socket, cb, opaque, &socket->write_info);
 }
 }
 
 
-void grpc_socket_notify_on_read(grpc_winsocket *socket,
-                                void(*cb)(void *, int), void *opaque) {
+void grpc_socket_notify_on_read(grpc_winsocket *socket, void (*cb)(void *, int),
+                                void *opaque) {
   socket_notify_on_iocp(socket, cb, opaque, &socket->read_info);
   socket_notify_on_iocp(socket, cb, opaque, &socket->read_info);
 }
 }
 
 
-#endif  /* GPR_WINSOCK_SOCKET */
+#endif /* GPR_WINSOCK_SOCKET */

+ 5 - 5
src/core/iomgr/iocp_windows.h

@@ -44,10 +44,10 @@ void grpc_iocp_shutdown(void);
 void grpc_iocp_add_socket(grpc_winsocket *);
 void grpc_iocp_add_socket(grpc_winsocket *);
 void grpc_iocp_socket_orphan(grpc_winsocket *);
 void grpc_iocp_socket_orphan(grpc_winsocket *);
 
 
-void grpc_socket_notify_on_write(grpc_winsocket *, void(*cb)(void *, int success),
-                                 void *opaque);
+void grpc_socket_notify_on_write(grpc_winsocket *,
+                                 void (*cb)(void *, int success), void *opaque);
 
 
-void grpc_socket_notify_on_read(grpc_winsocket *, void(*cb)(void *, int success),
-                                void *opaque);
+void grpc_socket_notify_on_read(grpc_winsocket *,
+                                void (*cb)(void *, int success), void *opaque);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_IOCP_WINDOWS_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_IOCP_WINDOWS_H */

+ 1 - 1
src/core/iomgr/iomgr.h

@@ -77,4 +77,4 @@ void grpc_iomgr_add_callback(grpc_iomgr_closure *closure);
     argument. */
     argument. */
 void grpc_iomgr_add_delayed_callback(grpc_iomgr_closure *iocb, int success);
 void grpc_iomgr_add_delayed_callback(grpc_iomgr_closure *iocb, int success);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_IOMGR_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_IOMGR_H */

+ 1 - 1
src/core/iomgr/iomgr_internal.h

@@ -52,4 +52,4 @@ void grpc_iomgr_unregister_object(grpc_iomgr_object *obj);
 void grpc_iomgr_platform_init(void);
 void grpc_iomgr_platform_init(void);
 void grpc_iomgr_platform_shutdown(void);
 void grpc_iomgr_platform_shutdown(void);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_IOMGR_INTERNAL_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_IOMGR_INTERNAL_H */

+ 1 - 1
src/core/iomgr/iomgr_posix.c

@@ -51,4 +51,4 @@ void grpc_iomgr_platform_shutdown(void) {
   grpc_fd_global_shutdown();
   grpc_fd_global_shutdown();
 }
 }
 
 
-#endif  /* GRPC_POSIX_SOCKET */
+#endif /* GRPC_POSIX_SOCKET */

+ 1 - 1
src/core/iomgr/iomgr_posix.h

@@ -39,4 +39,4 @@
 void grpc_pollset_global_init(void);
 void grpc_pollset_global_init(void);
 void grpc_pollset_global_shutdown(void);
 void grpc_pollset_global_shutdown(void);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_IOMGR_POSIX_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_IOMGR_POSIX_H */

+ 1 - 1
src/core/iomgr/iomgr_windows.c

@@ -68,4 +68,4 @@ void grpc_iomgr_platform_shutdown(void) {
   winsock_shutdown();
   winsock_shutdown();
 }
 }
 
 
-#endif  /* GRPC_WINSOCK_SOCKET */
+#endif /* GRPC_WINSOCK_SOCKET */

+ 1 - 2
src/core/iomgr/pollset_multipoller_with_epoll.c

@@ -234,8 +234,7 @@ static void multipoll_with_epoll_pollset_destroy(grpc_pollset *pollset) {
 }
 }
 
 
 static const grpc_pollset_vtable multipoll_with_epoll_pollset = {
 static const grpc_pollset_vtable multipoll_with_epoll_pollset = {
-    multipoll_with_epoll_pollset_add_fd,
-    multipoll_with_epoll_pollset_del_fd,
+    multipoll_with_epoll_pollset_add_fd, multipoll_with_epoll_pollset_del_fd,
     multipoll_with_epoll_pollset_maybe_work,
     multipoll_with_epoll_pollset_maybe_work,
     multipoll_with_epoll_pollset_finish_shutdown,
     multipoll_with_epoll_pollset_finish_shutdown,
     multipoll_with_epoll_pollset_destroy};
     multipoll_with_epoll_pollset_destroy};

+ 2 - 3
src/core/iomgr/pollset_multipoller_with_poll_posix.c

@@ -74,7 +74,7 @@ static void multipoll_with_poll_pollset_add_fd(grpc_pollset *pollset,
   }
   }
   h->fds[h->fd_count++] = fd;
   h->fds[h->fd_count++] = fd;
   GRPC_FD_REF(fd, "multipoller");
   GRPC_FD_REF(fd, "multipoller");
-exit:  
+exit:
   if (and_unlock_pollset) {
   if (and_unlock_pollset) {
     gpr_mu_unlock(&pollset->mu);
     gpr_mu_unlock(&pollset->mu);
   }
   }
@@ -202,8 +202,7 @@ static void multipoll_with_poll_pollset_destroy(grpc_pollset *pollset) {
 }
 }
 
 
 static const grpc_pollset_vtable multipoll_with_poll_pollset = {
 static const grpc_pollset_vtable multipoll_with_poll_pollset = {
-    multipoll_with_poll_pollset_add_fd,
-    multipoll_with_poll_pollset_del_fd,
+    multipoll_with_poll_pollset_add_fd, multipoll_with_poll_pollset_del_fd,
     multipoll_with_poll_pollset_maybe_work,
     multipoll_with_poll_pollset_maybe_work,
     multipoll_with_poll_pollset_finish_shutdown,
     multipoll_with_poll_pollset_finish_shutdown,
     multipoll_with_poll_pollset_destroy};
     multipoll_with_poll_pollset_destroy};

+ 8 - 8
src/core/iomgr/pollset_posix.c

@@ -140,10 +140,10 @@ void grpc_pollset_init(grpc_pollset *pollset) {
 void grpc_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) {
 void grpc_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) {
   gpr_mu_lock(&pollset->mu);
   gpr_mu_lock(&pollset->mu);
   pollset->vtable->add_fd(pollset, fd, 1);
   pollset->vtable->add_fd(pollset, fd, 1);
-  /* the following (enabled only in debug) will reacquire and then release
-     our lock - meaning that if the unlocking flag passed to del_fd above is
-     not respected, the code will deadlock (in a way that we have a chance of
-     debugging) */
+/* the following (enabled only in debug) will reacquire and then release
+   our lock - meaning that if the unlocking flag passed to del_fd above is
+   not respected, the code will deadlock (in a way that we have a chance of
+   debugging) */
 #ifndef NDEBUG
 #ifndef NDEBUG
   gpr_mu_lock(&pollset->mu);
   gpr_mu_lock(&pollset->mu);
   gpr_mu_unlock(&pollset->mu);
   gpr_mu_unlock(&pollset->mu);
@@ -153,10 +153,10 @@ void grpc_pollset_add_fd(grpc_pollset *pollset, grpc_fd *fd) {
 void grpc_pollset_del_fd(grpc_pollset *pollset, grpc_fd *fd) {
 void grpc_pollset_del_fd(grpc_pollset *pollset, grpc_fd *fd) {
   gpr_mu_lock(&pollset->mu);
   gpr_mu_lock(&pollset->mu);
   pollset->vtable->del_fd(pollset, fd, 1);
   pollset->vtable->del_fd(pollset, fd, 1);
-  /* the following (enabled only in debug) will reacquire and then release
-     our lock - meaning that if the unlocking flag passed to del_fd above is
-     not respected, the code will deadlock (in a way that we have a chance of
-     debugging) */
+/* the following (enabled only in debug) will reacquire and then release
+   our lock - meaning that if the unlocking flag passed to del_fd above is
+   not respected, the code will deadlock (in a way that we have a chance of
+   debugging) */
 #ifndef NDEBUG
 #ifndef NDEBUG
   gpr_mu_lock(&pollset->mu);
   gpr_mu_lock(&pollset->mu);
   gpr_mu_unlock(&pollset->mu);
   gpr_mu_unlock(&pollset->mu);

+ 2 - 1
src/core/iomgr/pollset_posix.h

@@ -102,7 +102,8 @@ void grpc_kick_drain(grpc_pollset *p);
    - longer than a millisecond polls are rounded up to the next nearest
    - longer than a millisecond polls are rounded up to the next nearest
      millisecond to avoid spinning
      millisecond to avoid spinning
    - infinite timeouts are converted to -1 */
    - infinite timeouts are converted to -1 */
-int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline, gpr_timespec now);
+int grpc_poll_deadline_to_millis_timeout(gpr_timespec deadline,
+                                         gpr_timespec now);
 
 
 /* turn a pollset into a multipoller: platform specific */
 /* turn a pollset into a multipoller: platform specific */
 typedef void (*grpc_platform_become_multipoller_type)(grpc_pollset *pollset,
 typedef void (*grpc_platform_become_multipoller_type)(grpc_pollset *pollset,

+ 5 - 5
src/core/iomgr/pollset_windows.c

@@ -56,8 +56,7 @@ static grpc_pollset_worker *pop_front_worker(grpc_pollset *p) {
     grpc_pollset_worker *w = p->root_worker.next;
     grpc_pollset_worker *w = p->root_worker.next;
     remove_worker(p, w);
     remove_worker(p, w);
     return w;
     return w;
-  }
-  else {
+  } else {
     return NULL;
     return NULL;
   }
   }
 }
 }
@@ -100,7 +99,8 @@ void grpc_pollset_destroy(grpc_pollset *pollset) {
   gpr_mu_destroy(&pollset->mu);
   gpr_mu_destroy(&pollset->mu);
 }
 }
 
 
-int grpc_pollset_work(grpc_pollset *pollset, grpc_pollset_worker *worker, gpr_timespec deadline) {
+int grpc_pollset_work(grpc_pollset *pollset, grpc_pollset_worker *worker,
+                      gpr_timespec deadline) {
   gpr_timespec now;
   gpr_timespec now;
   int added_worker = 0;
   int added_worker = 0;
   now = gpr_now(GPR_CLOCK_MONOTONIC);
   now = gpr_now(GPR_CLOCK_MONOTONIC);
@@ -134,8 +134,8 @@ void grpc_pollset_kick(grpc_pollset *p, grpc_pollset_worker *specific_worker) {
   if (specific_worker != NULL) {
   if (specific_worker != NULL) {
     if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) {
     if (specific_worker == GRPC_POLLSET_KICK_BROADCAST) {
       for (specific_worker = p->root_worker.next;
       for (specific_worker = p->root_worker.next;
-        specific_worker != &p->root_worker;
-        specific_worker = specific_worker->next) {
+           specific_worker != &p->root_worker;
+           specific_worker = specific_worker->next) {
         gpr_cv_signal(&specific_worker->cv);
         gpr_cv_signal(&specific_worker->cv);
       }
       }
       p->kicked_without_pollers = 1;
       p->kicked_without_pollers = 1;

+ 1 - 1
src/core/iomgr/resolve_address.h

@@ -66,4 +66,4 @@ void grpc_resolved_addresses_destroy(grpc_resolved_addresses *addresses);
 grpc_resolved_addresses *grpc_blocking_resolve_address(
 grpc_resolved_addresses *grpc_blocking_resolve_address(
     const char *addr, const char *default_port);
     const char *addr, const char *default_port);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_RESOLVE_ADDRESS_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_RESOLVE_ADDRESS_H */

+ 1 - 4
src/core/iomgr/resolve_address_posix.c

@@ -105,10 +105,7 @@ grpc_resolved_addresses *grpc_blocking_resolve_address(
   s = getaddrinfo(host, port, &hints, &result);
   s = getaddrinfo(host, port, &hints, &result);
   if (s != 0) {
   if (s != 0) {
     /* Retry if well-known service name is recognized */
     /* Retry if well-known service name is recognized */
-    char *svc[][2] = {
-      {"http", "80"},
-      {"https", "443"}
-    };
+    char *svc[][2] = {{"http", "80"}, {"https", "443"}};
     int i;
     int i;
     for (i = 0; i < (int)(sizeof(svc) / sizeof(svc[0])); i++) {
     for (i = 0; i < (int)(sizeof(svc) / sizeof(svc[0])); i++) {
       if (strcmp(port, svc[i][0]) == 0) {
       if (strcmp(port, svc[i][0]) == 0) {

+ 1 - 1
src/core/iomgr/sockaddr.h

@@ -44,4 +44,4 @@
 #include "src/core/iomgr/sockaddr_posix.h"
 #include "src/core/iomgr/sockaddr_posix.h"
 #endif
 #endif
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_H */

+ 1 - 1
src/core/iomgr/sockaddr_posix.h

@@ -41,4 +41,4 @@
 #include <netdb.h>
 #include <netdb.h>
 #include <unistd.h>
 #include <unistd.h>
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_POSIX_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_POSIX_H */

+ 4 - 2
src/core/iomgr/sockaddr_utils.c

@@ -206,7 +206,8 @@ int grpc_sockaddr_get_port(const struct sockaddr *addr) {
     case AF_UNIX:
     case AF_UNIX:
       return 1;
       return 1;
     default:
     default:
-      gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_get_port", addr->sa_family);
+      gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_get_port",
+              addr->sa_family);
       return 0;
       return 0;
   }
   }
 }
 }
@@ -220,7 +221,8 @@ int grpc_sockaddr_set_port(const struct sockaddr *addr, int port) {
       ((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
       ((struct sockaddr_in6 *)addr)->sin6_port = htons(port);
       return 1;
       return 1;
     default:
     default:
-      gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port", addr->sa_family);
+      gpr_log(GPR_ERROR, "Unknown socket family %d in grpc_sockaddr_set_port",
+              addr->sa_family);
       return 0;
       return 0;
   }
   }
 }
 }

+ 1 - 1
src/core/iomgr/sockaddr_utils.h

@@ -86,4 +86,4 @@ int grpc_sockaddr_to_string(char **out, const struct sockaddr *addr,
 
 
 char *grpc_sockaddr_to_uri(const struct sockaddr *addr);
 char *grpc_sockaddr_to_uri(const struct sockaddr *addr);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_UTILS_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_UTILS_H */

+ 1 - 1
src/core/iomgr/sockaddr_win32.h

@@ -43,4 +43,4 @@
 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
 const char *inet_ntop(int af, const void *src, char *dst, socklen_t size);
 #endif
 #endif
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_WIN32_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_SOCKADDR_WIN32_H */

+ 1 - 1
src/core/iomgr/socket_utils_posix.h

@@ -110,4 +110,4 @@ extern int grpc_forbid_dualstack_sockets_for_testing;
 int grpc_create_dualstack_socket(const struct sockaddr *addr, int type,
 int grpc_create_dualstack_socket(const struct sockaddr *addr, int type,
                                  int protocol, grpc_dualstack_mode *dsmode);
                                  int protocol, grpc_dualstack_mode *dsmode);
 
 
-#endif  /* GRPC_INTERNAL_CORE_IOMGR_SOCKET_UTILS_POSIX_H */
+#endif /* GRPC_INTERNAL_CORE_IOMGR_SOCKET_UTILS_POSIX_H */

+ 1 - 1
src/core/iomgr/socket_windows.c

@@ -106,4 +106,4 @@ void grpc_winsocket_destroy(grpc_winsocket *winsocket) {
   gpr_free(winsocket);
   gpr_free(winsocket);
 }
 }
 
 
-#endif  /* GPR_WINSOCK_SOCKET */
+#endif /* GPR_WINSOCK_SOCKET */

Some files were not shown because too many files changed in this diff