2014-05-13 18:00:26 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright 2008 The WebRTC Project Authors. All rights reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
|
|
|
|
|
2017-06-29 08:03:04 +02:00
|
|
|
#ifndef WEBRTC_RTC_BASE_NETHELPERS_H_
|
|
|
|
|
#define WEBRTC_RTC_BASE_NETHELPERS_H_
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-06-29 07:52:50 +02:00
|
|
|
#if defined(WEBRTC_POSIX)
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
#include <stddef.h>
|
|
|
|
|
#elif WEBRTC_WIN
|
|
|
|
|
#include <winsock2.h> // NOLINT
|
|
|
|
|
#endif
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-06-29 07:52:50 +02:00
|
|
|
#include <list>
|
2017-06-29 06:21:20 -07:00
|
|
|
#include <memory>
|
2017-06-29 07:52:50 +02:00
|
|
|
|
2017-06-30 05:27:14 -07:00
|
|
|
#include "webrtc/rtc_base/asyncresolverinterface.h"
|
|
|
|
|
#include "webrtc/rtc_base/refcount.h"
|
|
|
|
|
#include "webrtc/rtc_base/scoped_ref_ptr.h"
|
|
|
|
|
#include "webrtc/rtc_base/sigslot.h"
|
|
|
|
|
#include "webrtc/rtc_base/socketaddress.h"
|
|
|
|
|
#include "webrtc/rtc_base/thread_checker.h"
|
2017-06-29 07:52:50 +02:00
|
|
|
|
|
|
|
|
namespace rtc {
|
|
|
|
|
|
2017-06-29 06:21:20 -07:00
|
|
|
class Thread;
|
|
|
|
|
class TaskQueue;
|
2017-06-29 07:52:50 +02:00
|
|
|
|
2017-06-29 06:21:20 -07:00
|
|
|
// AsyncResolver will perform async DNS resolution, signaling the result on the
|
|
|
|
|
// SignalDone from AsyncResolverInterface when the operation completes.
|
|
|
|
|
// SignalDone is fired on the same thread on which the AsyncResolver was
|
|
|
|
|
// constructed.
|
|
|
|
|
class AsyncResolver : public AsyncResolverInterface {
|
2017-06-29 07:52:50 +02:00
|
|
|
public:
|
|
|
|
|
AsyncResolver();
|
|
|
|
|
~AsyncResolver() override;
|
|
|
|
|
|
|
|
|
|
void Start(const SocketAddress& addr) override;
|
|
|
|
|
bool GetResolvedAddress(int family, SocketAddress* addr) const override;
|
|
|
|
|
int GetError() const override;
|
|
|
|
|
void Destroy(bool wait) override;
|
|
|
|
|
|
|
|
|
|
const std::vector<IPAddress>& addresses() const { return addresses_; }
|
|
|
|
|
|
|
|
|
|
private:
|
2017-06-29 06:21:20 -07:00
|
|
|
void ResolveDone(int error, std::vector<IPAddress> addresses);
|
|
|
|
|
|
|
|
|
|
class Trampoline : public RefCountInterface {
|
|
|
|
|
public:
|
|
|
|
|
Trampoline(AsyncResolver* resolver) : resolver(resolver) {}
|
|
|
|
|
// Points back to the resolver, as long as it is alive. Cleared
|
|
|
|
|
// by the AsyncResolver destructor.
|
|
|
|
|
AsyncResolver* resolver;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// |state_| is non-null while resolution is pending, i.e., set
|
|
|
|
|
// non-null by Start() and cleared by ResolveDone(). The destructor
|
|
|
|
|
// clears state_->resolver (assuming |state_| is non-null), to
|
|
|
|
|
// indicate that the resolver can no longer be accessed.
|
|
|
|
|
scoped_refptr<Trampoline> state_ ACCESS_ON(construction_thread_);
|
|
|
|
|
|
|
|
|
|
Thread* const construction_thread_;
|
|
|
|
|
// Set to true when Destroy() can't delete the object immediately.
|
|
|
|
|
// Indicate that the ResolveDone method is now responsible for
|
|
|
|
|
// deletion. method should delete the object.
|
|
|
|
|
bool destroyed_ = false;
|
|
|
|
|
// Queue used only for a single task.
|
|
|
|
|
std::unique_ptr<TaskQueue> resolver_queue_;
|
2017-06-29 07:52:50 +02:00
|
|
|
SocketAddress addr_;
|
|
|
|
|
std::vector<IPAddress> addresses_;
|
2017-06-29 06:21:20 -07:00
|
|
|
int error_ = -1;
|
2017-06-29 07:52:50 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// rtc namespaced wrappers for inet_ntop and inet_pton so we can avoid
|
|
|
|
|
// the windows-native versions of these.
|
|
|
|
|
const char* inet_ntop(int af, const void *src, char* dst, socklen_t size);
|
|
|
|
|
int inet_pton(int af, const char* src, void *dst);
|
|
|
|
|
|
|
|
|
|
bool HasIPv4Enabled();
|
|
|
|
|
bool HasIPv6Enabled();
|
|
|
|
|
} // namespace rtc
|
2014-05-13 18:00:26 +00:00
|
|
|
|
2017-06-29 08:03:04 +02:00
|
|
|
#endif // WEBRTC_RTC_BASE_NETHELPERS_H_
|