Roc Toolkit internal modules
Roc Toolkit: real-time audio streaming
resolver.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Roc Streaming authors
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
7  */
8 
9 //! @file roc_netio/target_libuv/roc_netio/resolver.h
10 //! @brief Hostname resolver.
11 
12 #ifndef ROC_NETIO_RESOLVER_H_
13 #define ROC_NETIO_RESOLVER_H_
14 
15 #include <uv.h>
16 
17 #include "roc_core/noncopyable.h"
20 
21 namespace roc {
22 namespace netio {
23 
24 //! Hostname resolver.
25 class Resolver : public core::NonCopyable<> {
26 public:
27  //! Initialize.
28  Resolver(IResolverRequestHandler& req_handler, uv_loop_t& event_loop);
29 
30  //! Initiate asynchronous resolve request.
31  //!
32  //! Should be called from event loop thread.
33  //! Resolving itself will be run on the internal libuv thread pool.
34  //!
35  //! When resolving is finished, IRequestHandler::handle_resolved() will be
36  //! called on the event loop thread.
37  //!
38  //! If there is no need for resolving or asynchronous request can't be started,
39  //! fills @p req and returns false.
41 
42 private:
43  static void getaddrinfo_cb_(uv_getaddrinfo_t* req, int status, struct addrinfo* res);
44 
45  void finish_resolving_(ResolverRequest& req, int status);
46 
47  uv_loop_t& loop_;
48 
49  IResolverRequestHandler& req_handler_;
50 };
51 
52 } // namespace netio
53 } // namespace roc
54 
55 #endif // ROC_NETIO_RESOLVER_H_
Base class for non-copyable objects.
Definition: noncopyable.h:23
Resolver request result handler interface.
Hostname resolver.
Definition: resolver.h:25
Resolver(IResolverRequestHandler &req_handler, uv_loop_t &event_loop)
Initialize.
bool async_resolve(ResolverRequest &req)
Initiate asynchronous resolve request.
Resolver request result handler interface.
Root namespace.
Non-copyable object.
Resolver request.