VideoTools
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
grequest.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2017 Graeme Walker
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // ===
17 ///
18 /// \file grequest.h
19 ///
20 
21 #ifndef G_REQUEST_H
22 #define G_REQUEST_H
23 
24 #include "gdef.h"
25 #include "gnet.h"
26 #include "gaddress.h"
27 #include "gwindow.h"
28 
29 namespace GNet
30 {
31  class Request ;
32  class HostRequest ;
33  class ServiceRequest ;
34 }
35 
36 /// \class GNet::Request
37 /// A base class for making asynchronous DNS requests under Windows.
38 /// \see WSAAsyncGetHostByName()
39 ///
41 {
42 protected:
43  enum { magic = 968 } ;
44  int m_magic ;
45  int m_error ;
46  HANDLE m_handle ;
47  char m_buffer[MAXGETHOSTSTRUCT] ;
48  bool m_host ;
49  bool m_done ;
50  bool m_numeric ;
51  GNet::Address m_address ;
52 
53 protected:
54  explicit Request( bool host ) ;
55  ///< Constructor. Derived class constructors
56  ///< should issue the appropriate WSAAsync..()
57  ///< request, with m_buffer[] given as the
58  ///< result buffer.
59 
60 public:
61  virtual ~Request() ;
62  ///< Virtual destructor. Cancels any
63  ///< outstanding request.
64 
65  bool valid() const ;
66  ///< Returns true if the constructor
67  ///< initiated a request properly.
68 
69  std::string reason() const ;
70  ///< Returns the failure reason if
71  ///< valid() or onMessage() returned
72  ///< false.
73 
74  bool onMessage( WPARAM wparam , LPARAM lparam ) ;
75  ///< To be called when the request has
76  ///< been completed. Returns false
77  ///< on error.
78 
79 private:
80  Request( const Request & ) ;
81  void operator=( const Request & ) ;
82  static const char *reason( bool host , int error ) ;
83 } ;
84 
85 /// \class GNet::HostRequest
86 /// A derivation of GNet::Request used for hostname lookup requests.
87 ///
88 class GNet::HostRequest : public Request
89 {
90 public:
91  HostRequest( std::string host_name , HWND hwnd , unsigned msg ) ;
92  ///< Constructor.
93 
94  Address result() const ;
95  ///< Returns the resolved address with a zero port number.
96 
97  std::string fqdn() const ;
98  ///< Returns the fully-qualified canonical hostname, if
99  ///< available.
100 
101 private:
102  bool numeric( std::string s , Address & address ) ;
103  HostRequest( const HostRequest & ) ;
104  void operator=( const HostRequest & ) ;
105 } ;
106 
107 /// \class GNet::ServiceRequest
108 /// A derivation of GNet::Request used for service (port) lookup requests.
109 ///
111 {
112 public:
113  ServiceRequest( std::string service_name , bool udp ,
114  HWND hwnd , unsigned msg ) ;
115  ///< Constructor.
116 
117  Address result() const ;
118  ///< Returns the address with a zeroed host part.
119 
120 private:
121  static const char * protocol( bool udp ) ;
122  bool numeric( std::string s , Address & address ) ;
123 } ;
124 
125 #endif
126 
Request(bool host)
Constructor.
The GNet::Address class encapsulates a TCP/UDP transport address.
Definition: gaddress.h:55
std::string reason() const
Returns the failure reason if valid() or onMessage() returned false.
A derivation of GNet::Request used for hostname lookup requests.
Definition: grequest.h:88
virtual ~Request()
Virtual destructor.
Address result() const
Returns the resolved address with a zero port number.
Address result() const
Returns the address with a zeroed host part.
bool valid() const
Returns true if the constructor initiated a request properly.
std::string fqdn() const
Returns the fully-qualified canonical hostname, if available.
bool onMessage(WPARAM wparam, LPARAM lparam)
To be called when the request has been completed.
A derivation of GNet::Request used for service (port) lookup requests.
Definition: grequest.h:110
ServiceRequest(std::string service_name, bool udp, HWND hwnd, unsigned msg)
Constructor.
HostRequest(std::string host_name, HWND hwnd, unsigned msg)
Constructor.
A base class for making asynchronous DNS requests under Windows.
Definition: grequest.h:40