resolve_address.h 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /*
  2. *
  3. * Copyright 2015 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. #ifndef GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
  19. #define GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H
  20. #include <grpc/support/port_platform.h>
  21. #include <stddef.h>
  22. #include "src/core/lib/iomgr/exec_ctx.h"
  23. #include "src/core/lib/iomgr/pollset_set.h"
  24. #define GRPC_MAX_SOCKADDR_SIZE 128
  25. typedef struct {
  26. char addr[GRPC_MAX_SOCKADDR_SIZE];
  27. size_t len;
  28. } grpc_resolved_address;
  29. typedef struct {
  30. size_t naddrs;
  31. grpc_resolved_address* addrs;
  32. } grpc_resolved_addresses;
  33. typedef struct grpc_address_resolver_vtable {
  34. void (*resolve_address)(const char* addr, const char* default_port,
  35. grpc_pollset_set* interested_parties,
  36. grpc_closure* on_done,
  37. grpc_resolved_addresses** addresses);
  38. grpc_error* (*blocking_resolve_address)(const char* name,
  39. const char* default_port,
  40. grpc_resolved_addresses** addresses);
  41. } grpc_address_resolver_vtable;
  42. void grpc_set_resolver_impl(grpc_address_resolver_vtable* vtable);
  43. /* Asynchronously resolve addr. Use default_port if a port isn't designated
  44. in addr, otherwise use the port in addr. */
  45. /* TODO(ctiller): add a timeout here */
  46. void grpc_resolve_address(const char* addr, const char* default_port,
  47. grpc_pollset_set* interested_parties,
  48. grpc_closure* on_done,
  49. grpc_resolved_addresses** addresses);
  50. /* Destroy resolved addresses */
  51. void grpc_resolved_addresses_destroy(grpc_resolved_addresses* addresses);
  52. /* Resolve addr in a blocking fashion. On success,
  53. result must be freed with grpc_resolved_addresses_destroy. */
  54. grpc_error* grpc_blocking_resolve_address(const char* name,
  55. const char* default_port,
  56. grpc_resolved_addresses** addresses);
  57. #endif /* GRPC_CORE_LIB_IOMGR_RESOLVE_ADDRESS_H */