瀏覽代碼

Add channel arg for server handshake timeout.

Mark D. Roth 8 年之前
父節點
當前提交
fbc3f04eab
共有 2 個文件被更改,包括 9 次插入3 次删除
  1. 3 0
      include/grpc/impl/codegen/grpc_types.h
  2. 6 3
      src/core/ext/transport/chttp2/server/chttp2_server.cc

+ 3 - 0
include/grpc/impl/codegen/grpc_types.h

@@ -240,6 +240,9 @@ typedef struct {
 /** The time between the first and second connection attempts, in ms */
 /** The time between the first and second connection attempts, in ms */
 #define GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS \
 #define GRPC_ARG_INITIAL_RECONNECT_BACKOFF_MS \
   "grpc.initial_reconnect_backoff_ms"
   "grpc.initial_reconnect_backoff_ms"
+/** The timeout used on servers for finishing handshaking on an incoming
+    connection.  Defaults to 120 seconds. */
+#define GRPC_ARG_SERVER_HANDSHAKE_TIMEOUT_MS "grpc.server_handshake_timeout_ms"
 /** This *should* be used for testing only.
 /** This *should* be used for testing only.
     The caller of the secure_channel_create functions may override the target
     The caller of the secure_channel_create functions may override the target
     name used for SSL host name checking using this channel argument which is of
     name used for SSL host name checking using this channel argument which is of

+ 6 - 3
src/core/ext/transport/chttp2/server/chttp2_server.cc

@@ -21,6 +21,7 @@
 #include <grpc/grpc.h>
 #include <grpc/grpc.h>
 
 
 #include <inttypes.h>
 #include <inttypes.h>
+#include <limits.h>
 #include <string.h>
 #include <string.h>
 
 
 #include <grpc/support/alloc.h>
 #include <grpc/support/alloc.h>
@@ -132,10 +133,12 @@ static void on_accept(grpc_exec_ctx* exec_ctx, void* arg, grpc_endpoint* tcp,
   connection_state->handshake_mgr = handshake_mgr;
   connection_state->handshake_mgr = handshake_mgr;
   grpc_handshakers_add(exec_ctx, HANDSHAKER_SERVER, state->args,
   grpc_handshakers_add(exec_ctx, HANDSHAKER_SERVER, state->args,
                        connection_state->handshake_mgr);
                        connection_state->handshake_mgr);
-  // TODO(roth): We should really get this timeout value from channel
-  // args instead of hard-coding it.
+  const grpc_arg* timeout_arg =
+      grpc_channel_args_find(state->args, GRPC_ARG_SERVER_HANDSHAKE_TIMEOUT_MS);
   const grpc_millis deadline =
   const grpc_millis deadline =
-      grpc_exec_ctx_now(exec_ctx) + 120 * GPR_MS_PER_SEC;
+      grpc_exec_ctx_now(exec_ctx) +
+      grpc_channel_arg_get_integer(timeout_arg,
+                                   {120 * GPR_MS_PER_SEC, 1, INT_MAX});
   grpc_handshake_manager_do_handshake(exec_ctx, connection_state->handshake_mgr,
   grpc_handshake_manager_do_handshake(exec_ctx, connection_state->handshake_mgr,
                                       tcp, state->args, deadline, acceptor,
                                       tcp, state->args, deadline, acceptor,
                                       on_handshake_done, connection_state);
                                       on_handshake_done, connection_state);