call.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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 <netinet/in.h> // for struct sockaddr_in
  22. #include <stdint.h> // for int32_t
  23. #include <uv.h> // for uv_buf_t
  24. struct hadoop_err;
  25. struct hrpc_response;
  26. /**
  27. * The Hadoop call.
  28. *
  29. * Note: this is an internal header which users of the RPC layer don't need to
  30. * include.
  31. */
  32. typedef void (*hrpc_raw_cb_t)(struct hrpc_response *,
  33. struct hadoop_err *, void *);
  34. /**
  35. * A Hadoop RPC call.
  36. */
  37. struct hrpc_call {
  38. /**
  39. * Pointers used to put this call into an implicit linked list.
  40. */
  41. STAILQ_ENTRY(hrpc_call) entry;
  42. /**
  43. * Remote address we're sending to.
  44. */
  45. struct sockaddr_in remote;
  46. /**
  47. * The callback to make from the reactor thread when this call completes or
  48. * hits an error.
  49. */
  50. hrpc_raw_cb_t cb;
  51. /**
  52. * The data to pass to the callback.
  53. */
  54. void *cb_data;
  55. /**
  56. * Malloc'ed payload to send.
  57. */
  58. uv_buf_t payload;
  59. /**
  60. * String describing the protocol this call is using.
  61. */
  62. const char *protocol;
  63. /**
  64. * String describing the username this call is using.
  65. */
  66. const char *username;
  67. /**
  68. * Nonzero if the call is currently active. Must be set using atomic
  69. * operations.
  70. */
  71. int active;
  72. };
  73. STAILQ_HEAD(hrpc_calls, hrpc_call);
  74. /**
  75. * Activate this call.
  76. *
  77. * @param call The call.
  78. *
  79. * @return 1 if the call was activated; 0 if it was already
  80. * active.
  81. */
  82. int hrpc_call_activate(struct hrpc_call *call);
  83. /**
  84. * Deactivate this call.
  85. *
  86. * @param call The call.
  87. */
  88. void hrpc_call_deactivate(struct hrpc_call *call);
  89. /**
  90. * Determine if the call is active.
  91. *
  92. * @param call The call.
  93. *
  94. * @return 1 if the call is active; 0 if it is not.
  95. */
  96. int hrpc_call_is_active(const struct hrpc_call *call);
  97. /**
  98. * Deliver an error message. Will free call->payload and zero all fields.
  99. *
  100. * @param call The call.
  101. * @param resp The error to pass to the callback. The callback
  102. * is responsible for freeing this error.
  103. */
  104. void hrpc_call_deliver_err(struct hrpc_call *call, struct hadoop_err *err);
  105. /**
  106. * Deliver a response. Will free call->payload and zero all fields.
  107. *
  108. * @param call The call.
  109. * @param resp Malloc'ed data to pass to the callback. The callback
  110. * is responsible for freeing this data.
  111. */
  112. void hrpc_call_deliver_resp(struct hrpc_call *call,
  113. struct hrpc_response *resp);
  114. #endif
  115. // vim: ts=4:sw=4:tw=79:et