CppServer  1.0.4.0
C++ Server Library
tcp_resolver.h
Go to the documentation of this file.
1 
9 #ifndef CPPSERVER_ASIO_TCP_RESOLVER_H
10 #define CPPSERVER_ASIO_TCP_RESOLVER_H
11 
12 #include "service.h"
13 
14 namespace CppServer {
15 namespace Asio {
16 
18 
24 {
25 public:
27 
30  TCPResolver(const std::shared_ptr<Service>& service);
31  TCPResolver(const TCPResolver&) = delete;
32  TCPResolver(TCPResolver&&) = delete;
33  virtual ~TCPResolver() { Cancel(); }
34 
35  TCPResolver& operator=(const TCPResolver&) = delete;
37 
39  std::shared_ptr<Service>& service() noexcept { return _service; }
41  std::shared_ptr<asio::io_service>& io_service() noexcept { return _io_service; }
43  asio::io_service::strand& strand() noexcept { return _strand; }
45  asio::ip::tcp::resolver& resolver() noexcept { return _resolver; }
46 
48  virtual void Cancel() { _resolver.cancel(); }
49 
50 private:
51  // Asio service
52  std::shared_ptr<Service> _service;
53  // Asio IO service
54  std::shared_ptr<asio::io_service> _io_service;
55  // Asio service strand for serialized handler execution
56  asio::io_service::strand _strand;
57  bool _strand_required;
58  // TCP resolver
59  asio::ip::tcp::resolver _resolver;
60 };
61 
62 } // namespace Asio
63 } // namespace CppServer
64 
65 #endif // CPPSERVER_ASIO_TCP_RESOLVER_H
TCPResolver(const TCPResolver &)=delete
TCPResolver(TCPResolver &&)=delete
asio::ip::tcp::resolver & resolver() noexcept
Get the TCP resolver.
Definition: tcp_resolver.h:45
std::shared_ptr< asio::io_service > & io_service() noexcept
Get the Asio IO service.
Definition: tcp_resolver.h:41
TCPResolver & operator=(TCPResolver &&)=delete
asio::io_service::strand & strand() noexcept
Get the Asio service strand for serialized handler execution.
Definition: tcp_resolver.h:43
TCPResolver & operator=(const TCPResolver &)=delete
std::shared_ptr< Service > & service() noexcept
Get the Asio service.
Definition: tcp_resolver.h:39
TCPResolver(const std::shared_ptr< Service > &service)
Initialize resolver with a given Asio service.
virtual void Cancel()
Cancel any asynchronous operations that are waiting on the resolver.
Definition: tcp_resolver.h:48
C++ Server project definitions.
Definition: asio.h:56
Asio service definition.