root/trunk/dep/include/sockets/ResolvSocket.h @ 2

Revision 2, 2.9 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

Line 
1/** \file ResolvSocket.h
2 **     \date  2005-03-24
3 **     \author grymse@alhem.net
4**/
5/*
6Copyright (C) 2004-2007  Anders Hedstrom
7
8This library is made available under the terms of the GNU GPL.
9
10If you would like to use this library in a closed-source application,
11a separate license agreement is available. For information about
12the closed-source license agreement for the C++ sockets library,
13please visit http://www.alhem.net/Sockets/license.html and/or
14email license@alhem.net.
15
16This program is free software; you can redistribute it and/or
17modify it under the terms of the GNU General Public License
18as published by the Free Software Foundation; either version 2
19of the License, or (at your option) any later version.
20
21This program is distributed in the hope that it will be useful,
22but WITHOUT ANY WARRANTY; without even the implied warranty of
23MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24GNU General Public License for more details.
25
26You should have received a copy of the GNU General Public License
27along with this program; if not, write to the Free Software
28Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
29*/
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>
36
37#ifdef SOCKETS_NAMESPACE
38namespace SOCKETS_NAMESPACE {
39#endif
40
41class Mutex;
42
43/** Async DNS resolver socket.
44        \ingroup async */
45class ResolvSocket : public TcpSocket
46{
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 */
51
52public:
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();
60
61        void OnAccept() { m_bServer = true; }
62        void OnLine(const std::string& line);
63        void OnDetached();
64        void OnDelete();
65
66        void SetId(int x) { m_resolv_id = x; }
67        int GetId() { return m_resolv_id; }
68
69        void OnConnect();
70
71#ifdef ENABLE_IPV6
72        void SetResolveIpv6(bool x = true) { m_resolve_ipv6 = x; }
73#endif
74
75private:
76        ResolvSocket(const ResolvSocket& s) : TcpSocket(s) {} // copy constructor
77        ResolvSocket& operator=(const ResolvSocket& ) { return *this; } // assignment operator
78
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;
95};
96
97
98
99
100#ifdef SOCKETS_NAMESPACE
101}
102#endif
103
104#endif // ENABLE_RESOLVER
105#endif // _SOCKETS_ResolvSocket_H
106
Note: See TracBrowser for help on using the browser.