call.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /**
  2. * Licensed to the Apache Software Foundation (ASF) under one
  3. * or more contributor license agreements. See the NOTICE file
  4. * distributed with this work for additional information
  5. * regarding copyright ownership. The ASF licenses this file
  6. * to you under the Apache License, Version 2.0 (the
  7. * "License"); you may not use this file except in compliance
  8. * with the License. You may obtain a copy of the License at
  9. *
  10. * http://www.apache.org/licenses/LICENSE-2.0
  11. *
  12. * Unless required by applicable law or agreed to in writing, software
  13. * distributed under the License is distributed on an "AS IS" BASIS,
  14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  15. * See the License for the specific language governing permissions and
  16. * limitations under the License.
  17. */
  18. #ifndef HADOOP_CORE_RPC_CALL_H
  19. #define HADOOP_CORE_RPC_CALL_H
  20. #include "common/queue.h"
  21. #include "rpc/proxy.h" // for hrpc_raw_cb_t
  22. #include <netinet/in.h> // for struct sockaddr_in
  23. #include <stdint.h> // for int32_t
  24. #include <uv.h> // for uv_buf_t
  25. /**
  26. * The Hadoop call.
  27. *
  28. * Note: this is an internal header which users of the RPC layer don't need to
  29. * include.
  30. */
  31. struct hrpc_call;
  32. /**
  33. * A Hadoop RPC call.
  34. */
  35. struct hrpc_call {
  36. /**
  37. * Pointers used to put this call into an implicit linked list.
  38. */
  39. STAILQ_ENTRY(hrpc_call) entry;
  40. /**
  41. * Remote address we're sending to.
  42. */
  43. struct sockaddr_in remote;
  44. /**
  45. * The callback to make from the reactor thread when this call completes or
  46. * hits an error.
  47. */
  48. hrpc_raw_cb_t cb;
  49. /**
  50. * The data to pass to the callback.
  51. */
  52. void *cb_data;
  53. /**
  54. * Malloc'ed payload to send. Malloced.
  55. */
  56. uv_buf_t payload;
  57. /**
  58. * The Java protocol we're using. Malloced.
  59. */
  60. char *protocol;
  61. /**
  62. * Nonzero if the call is currently active. Must be set using atomic
  63. * operations.
  64. */
  65. int active;
  66. };
  67. STAILQ_HEAD(hrpc_calls, hrpc_call);
  68. /**
  69. * Activate this call.
  70. *
  71. * @param call The call.
  72. *
  73. * @return 1 if the call was activated; 0 if it was already
  74. * active.
  75. */
  76. int hrpc_call_activate(struct hrpc_call *call);
  77. /**
  78. * Deactivate this call.
  79. *
  80. * @param call The call.
  81. */
  82. void hrpc_call_deactivate(struct hrpc_call *call);
  83. /**
  84. * Determine if the call is active.
  85. *
  86. * @param call The call.
  87. *
  88. * @return 1 if the call is active; 0 if it is not.
  89. */
  90. int hrpc_call_is_active(const struct hrpc_call *call);
  91. /**
  92. * Deliver an error message. Will free call->payload and zero all fields.
  93. *
  94. * @param call The call.
  95. * @param resp The error to pass to the callback. The callback
  96. * is responsible for freeing this error.
  97. */
  98. void hrpc_call_deliver_err(struct hrpc_call *call, struct hadoop_err *err);
  99. /**
  100. * Deliver a response. Will free call->payload and zero all fields.
  101. *
  102. * @param call The call.
  103. * @param resp Malloc'ed data to pass to the callback. The callback
  104. * is responsible for freeing this data.
  105. */
  106. void hrpc_call_deliver_resp(struct hrpc_call *call,
  107. struct hrpc_response *resp);
  108. #endif
  109. // vim: ts=4:sw=4:tw=79:et