rpc_options.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. Copyright (c) 2020 Sogou, Inc.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. #ifndef __RPC_OPTIONS_H__
  14. #define __RPC_OPTIONS_H__
  15. #include <list>
  16. #include <string>
  17. #include <workflow/WFServer.h>
  18. #include <workflow/URIParser.h>
  19. #include "rpc_basic.h"
  20. namespace srpc {
  21. struct RPCTaskParams
  22. {
  23. int send_timeout;
  24. int receive_timeout;
  25. int watch_timeout;
  26. int keep_alive_timeout;
  27. int retry_max;
  28. int compress_type; //RPCCompressType
  29. int data_type; //RPCDataType
  30. };
  31. struct RPCClientParams
  32. {
  33. RPCTaskParams task_params;
  34. //host + port + is_ssl
  35. std::string host;
  36. unsigned short port;
  37. bool is_ssl;
  38. //or URL
  39. std::string url;
  40. int callee_timeout;
  41. std::string caller;
  42. };
  43. struct RPCServerParams : public WFServerParams
  44. {
  45. RPCServerParams() : WFServerParams(SERVER_PARAMS_DEFAULT)
  46. {
  47. this->request_size_limit = RPC_BODY_SIZE_LIMIT;
  48. }
  49. };
  50. static constexpr struct RPCTaskParams RPC_TASK_PARAMS_DEFAULT =
  51. {
  52. /* .send_timeout = */ -1,
  53. /* .receive_timeout = */ -1,
  54. /* .watch_timeout = */ 0,
  55. /* .keep_alive_timeout = */ 30 * 1000,
  56. /* .retry_max = */ 0,
  57. /* .compress_type = */ RPCCompressNone,
  58. /* .data_type = */ RPCDataUndefined
  59. };
  60. static const struct RPCClientParams RPC_CLIENT_PARAMS_DEFAULT =
  61. {
  62. /* .task_params = */ RPC_TASK_PARAMS_DEFAULT,
  63. /* .host = */ "",
  64. /* .port = */ SRPC_DEFAULT_PORT,
  65. /* .is_ssl = */ false,
  66. /* .url = */ "",
  67. /* .callee_timeout = */ -1,
  68. /* .caller = */ ""
  69. };
  70. static const RPCServerParams RPC_SERVER_PARAMS_DEFAULT;
  71. } // end namespace
  72. #endif