1 /** \file ResolvSocket.h
3 ** \author grymse@alhem.net
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"
37 #ifdef SOCKETS_NAMESPACE
38 namespace SOCKETS_NAMESPACE
{
43 /** Async DNS resolver socket.
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 */
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
);
57 ResolvSocket(ISocketHandler
&, Socket
*parent
, in6_addr
&);
61 void OnAccept() { m_bServer
= true; }
62 void OnLine(const std::string
& line
);
66 void SetId(int x
) { m_resolv_id
= x
; }
67 int GetId() { return m_resolv_id
; }
72 void SetResolveIpv6(bool x
= true) { m_resolve_ipv6
= x
; }
76 ResolvSocket(const ResolvSocket
& s
) : TcpSocket(s
) {} // copy constructor
77 ResolvSocket
& operator=(const ResolvSocket
& ) { return *this; } // assignment operator
84 std::string m_resolv_host
;
86 ipaddr_t m_resolv_address
;
89 in6_addr m_resolv_address6
;
91 static cache_t m_cache
;
92 static timeout_t m_cache_to
;
93 static Mutex m_cache_mutex
;
100 #ifdef SOCKETS_NAMESPACE
104 #endif // ENABLE_RESOLVER
105 #endif // _SOCKETS_ResolvSocket_H