CppServer  1.0.4.0
C++ Server Library
udp_resolver.h
Go to the documentation of this file.
1 
9 #ifndef CPPSERVER_ASIO_UDP_RESOLVER_H
10 #define CPPSERVER_ASIO_UDP_RESOLVER_H
11 
12 #include "service.h"
13 
14 namespace CppServer {
15 namespace Asio {
16 
18 
24 {
25 public:
27 
30  UDPResolver(const std::shared_ptr<Service>& service);
31  UDPResolver(const UDPResolver&) = delete;
32  UDPResolver(UDPResolver&&) = delete;
33  virtual ~UDPResolver() { Cancel(); }
34 
35  UDPResolver& operator=(const UDPResolver&) = 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::udp::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  // UDP resolver
59  asio::ip::udp::resolver _resolver;
60 };
61 
62 } // namespace Asio
63 } // namespace CppServer
64 
65 #endif // CPPSERVER_ASIO_UDP_RESOLVER_H
virtual void Cancel()
Cancel any asynchronous operations that are waiting on the resolver.
Definition: udp_resolver.h:48
std::shared_ptr< asio::io_service > & io_service() noexcept
Get the Asio IO service.
Definition: udp_resolver.h:41
UDPResolver(const std::shared_ptr< Service > &service)
Initialize resolver with a given Asio service.
UDPResolver & operator=(const UDPResolver &)=delete
asio::ip::udp::resolver & resolver() noexcept
Get the UDP resolver.
Definition: udp_resolver.h:45
UDPResolver & operator=(UDPResolver &&)=delete
UDPResolver(UDPResolver &&)=delete
std::shared_ptr< Service > & service() noexcept
Get the Asio service.
Definition: udp_resolver.h:39
UDPResolver(const UDPResolver &)=delete
asio::io_service::strand & strand() noexcept
Get the Asio service strand for serialized handler execution.
Definition: udp_resolver.h:43
C++ Server project definitions.
Definition: asio.h:56
Asio service definition.