async_resolver_interface.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*
  2. * Copyright 2013 The WebRTC Project Authors. All rights reserved.
  3. *
  4. * Use of this source code is governed by a BSD-style license
  5. * that can be found in the LICENSE file in the root of the source
  6. * tree. An additional intellectual property rights grant can be found
  7. * in the file PATENTS. All contributing project authors may
  8. * be found in the AUTHORS file in the root of the source tree.
  9. */
  10. #ifndef RTC_BASE_ASYNC_RESOLVER_INTERFACE_H_
  11. #define RTC_BASE_ASYNC_RESOLVER_INTERFACE_H_
  12. #include "rtc_base/socket_address.h"
  13. #include "rtc_base/system/rtc_export.h"
  14. #include "rtc_base/third_party/sigslot/sigslot.h"
  15. namespace rtc {
  16. // This interface defines the methods to resolve the address asynchronously.
  17. class RTC_EXPORT AsyncResolverInterface {
  18. public:
  19. AsyncResolverInterface();
  20. virtual ~AsyncResolverInterface();
  21. // Start address resolution of the hostname in |addr|.
  22. virtual void Start(const SocketAddress& addr) = 0;
  23. // Returns true iff the address from |Start| was successfully resolved.
  24. // If the address was successfully resolved, sets |addr| to a copy of the
  25. // address from |Start| with the IP address set to the top most resolved
  26. // address of |family| (|addr| will have both hostname and the resolved ip).
  27. virtual bool GetResolvedAddress(int family, SocketAddress* addr) const = 0;
  28. // Returns error from resolver.
  29. virtual int GetError() const = 0;
  30. // Delete the resolver.
  31. virtual void Destroy(bool wait) = 0;
  32. // Returns top most resolved IPv4 address if address is resolved successfully.
  33. // Otherwise returns address set in SetAddress.
  34. SocketAddress address() const {
  35. SocketAddress addr;
  36. GetResolvedAddress(AF_INET, &addr);
  37. return addr;
  38. }
  39. // This signal is fired when address resolve process is completed.
  40. sigslot::signal1<AsyncResolverInterface*> SignalDone;
  41. };
  42. } // namespace rtc
  43. #endif