minor changes
[anytun.git] / Sockets / ResolvSocket.h
blobff4b1a5a9823762b4c4d7367b6ee4a15d94844b6
1 /** \file ResolvSocket.h
2 ** \date 2005-03-24
3 ** \author grymse@alhem.net
4 **/
5 /*
6 Copyright (C) 2004-2007 Anders Hedstrom
8 This library is made available under the terms of the GNU GPL.
10 If you would like to use this library in a closed-source application,
11 a separate license agreement is available. For information about
12 the closed-source license agreement for the C++ sockets library,
13 please visit http://www.alhem.net/Sockets/license.html and/or
14 email license@alhem.net.
16 This program is free software; you can redistribute it and/or
17 modify it under the terms of the GNU General Public License
18 as published by the Free Software Foundation; either version 2
19 of the License, or (at your option) any later version.
21 This program is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 GNU General Public License for more details.
26 You should have received a copy of the GNU General Public License
27 along with this program; if not, write to the Free Software
28 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 #ifndef _SOCKETS_ResolvSocket_H
31 #define _SOCKETS_ResolvSocket_H
32 #include "sockets-config.h"
33 #ifdef ENABLE_RESOLVER
34 #include "TcpSocket.h"
35 #include <map>
37 #ifdef SOCKETS_NAMESPACE
38 namespace SOCKETS_NAMESPACE {
39 #endif
41 class Mutex;
43 /** Async DNS resolver socket.
44 \ingroup async */
45 class ResolvSocket : public TcpSocket
47 typedef std::map<std::string, /* type */
48 std::map<std::string, std::string> > cache_t; /* host, result */
49 typedef std::map<std::string, /* type */
50 std::map<std::string, time_t> > timeout_t; /* host, time */
52 public:
53 ResolvSocket(ISocketHandler&);
54 ResolvSocket(ISocketHandler&, Socket *parent, const std::string& host, port_t port, bool ipv6 = false);
55 ResolvSocket(ISocketHandler&, Socket *parent, ipaddr_t);
56 #ifdef ENABLE_IPV6
57 ResolvSocket(ISocketHandler&, Socket *parent, in6_addr&);
58 #endif
59 ~ResolvSocket();
61 void OnAccept() { m_bServer = true; }
62 void OnLine(const std::string& line);
63 void OnDetached();
64 void OnDelete();
66 void SetId(int x) { m_resolv_id = x; }
67 int GetId() { return m_resolv_id; }
69 void OnConnect();
71 #ifdef ENABLE_IPV6
72 void SetResolveIpv6(bool x = true) { m_resolve_ipv6 = x; }
73 #endif
75 private:
76 ResolvSocket(const ResolvSocket& s) : TcpSocket(s) {} // copy constructor
77 ResolvSocket& operator=(const ResolvSocket& ) { return *this; } // assignment operator
79 std::string m_query;
80 std::string m_data;
81 bool m_bServer;
82 Socket *m_parent;
83 int m_resolv_id;
84 std::string m_resolv_host;
85 port_t m_resolv_port;
86 ipaddr_t m_resolv_address;
87 #ifdef ENABLE_IPV6
88 bool m_resolve_ipv6;
89 in6_addr m_resolv_address6;
90 #endif
91 static cache_t m_cache;
92 static timeout_t m_cache_to;
93 static Mutex m_cache_mutex;
94 bool m_cached;
100 #ifdef SOCKETS_NAMESPACE
102 #endif
104 #endif // ENABLE_RESOLVER
105 #endif // _SOCKETS_ResolvSocket_H