client.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. *
  3. * Copyright 2014, Google Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. #include "src/core/surface/client.h"
  34. #include "src/core/surface/call.h"
  35. #include <grpc/support/alloc.h>
  36. #include <grpc/support/log.h>
  37. #include <grpc/support/string.h>
  38. typedef struct { void *unused; } call_data;
  39. typedef struct { void *unused; } channel_data;
  40. static void call_op(grpc_call_element *elem, grpc_call_element *from_elem,
  41. grpc_call_op *op) {
  42. GRPC_CALL_LOG_OP(GPR_INFO, elem, op);
  43. switch (op->type) {
  44. case GRPC_SEND_DEADLINE:
  45. grpc_call_set_deadline(elem, op->data.deadline);
  46. grpc_call_next_op(elem, op);
  47. break;
  48. case GRPC_RECV_METADATA:
  49. grpc_call_recv_metadata(elem, op);
  50. break;
  51. case GRPC_RECV_DEADLINE:
  52. gpr_log(GPR_ERROR, "Deadline received by client (ignored)");
  53. break;
  54. case GRPC_RECV_MESSAGE:
  55. grpc_call_recv_message(elem, op->data.message, op->done_cb,
  56. op->user_data);
  57. break;
  58. case GRPC_RECV_HALF_CLOSE:
  59. grpc_call_recv_finish(elem, 0);
  60. break;
  61. case GRPC_RECV_FINISH:
  62. grpc_call_recv_finish(elem, 1);
  63. break;
  64. case GRPC_RECV_END_OF_INITIAL_METADATA:
  65. grpc_call_client_initial_metadata_complete(elem);
  66. break;
  67. default:
  68. GPR_ASSERT(op->dir == GRPC_CALL_DOWN);
  69. grpc_call_next_op(elem, op);
  70. }
  71. }
  72. static void channel_op(grpc_channel_element *elem,
  73. grpc_channel_element *from_elem, grpc_channel_op *op) {
  74. switch (op->type) {
  75. case GRPC_ACCEPT_CALL:
  76. gpr_log(GPR_ERROR, "Client cannot accept new calls");
  77. break;
  78. case GRPC_TRANSPORT_CLOSED:
  79. gpr_log(GPR_ERROR, "Transport closed");
  80. break;
  81. case GRPC_TRANSPORT_GOAWAY:
  82. gpr_slice_unref(op->data.goaway.message);
  83. break;
  84. default:
  85. GPR_ASSERT(op->dir == GRPC_CALL_DOWN);
  86. grpc_channel_next_op(elem, op);
  87. }
  88. }
  89. static void init_call_elem(grpc_call_element *elem,
  90. const void *transport_server_data) {}
  91. static void destroy_call_elem(grpc_call_element *elem) {}
  92. static void init_channel_elem(grpc_channel_element *elem,
  93. const grpc_channel_args *args, grpc_mdctx *mdctx,
  94. int is_first, int is_last) {
  95. GPR_ASSERT(is_first);
  96. GPR_ASSERT(!is_last);
  97. }
  98. static void destroy_channel_elem(grpc_channel_element *elem) {}
  99. const grpc_channel_filter grpc_client_surface_filter = {
  100. call_op, channel_op,
  101. sizeof(call_data), init_call_elem, destroy_call_elem,
  102. sizeof(channel_data), init_channel_elem, destroy_channel_elem,
  103. "client",
  104. };