/[svn]/vendor/pxys2-2.0.0/pxyscand/src/PXIPCacheT.h
ViewVC logotype

Annotation of /vendor/pxys2-2.0.0/pxyscand/src/PXIPCacheT.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3252 - (hide annotations)
Wed Apr 2 20:41:43 2014 UTC (8 years, 3 months ago) by michael
File MIME type: text/x-csrc
File size: 2766 byte(s)
- Imported pxys2-2.0.0

1 michael 3252 // Copyright (C) 2003 Stephane Thiell
2     //
3     // This file is part of pxyscand (from pxys)
4     //
5     // This program is free software; you can redistribute it and/or
6     // modify it under the terms of the GNU General Public License
7     // as published by the Free Software Foundation; either version 2
8     // of the License, or (at your option) any later version.
9     //
10     // This program is distributed in the hope that it will be useful,
11     // but WITHOUT ANY WARRANTY; without even the implied warranty of
12     // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13     // GNU General Public License for more details.
14     //
15     // You should have received a copy of the GNU General Public License
16     // along with this program; if not, write to the Free Software
17     // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     //
19     // $Id: PXIPCacheT.h,v 1.1.1.1 2003/12/30 17:09:00 mbuna Exp $
20     //
21     #ifndef INCLUDED_PXIPCACHET_H_
22     #define INCLUDED_PXIPCACHET_H_
23    
24     // IPCache template class wrapper on pxys2/ipcache for pxyscand.
25     // To cache IPv4 or IPv6 associated with any binary info. Features basic
26     // swapin/swapout methods to save/restore to a file.
27     // mbuna, 2003-12-12
28    
29     #include <cstdio>
30     #include <ctime>
31     #include <sys/types.h>
32     #include <sys/param.h>
33     #include "ipcache.h"
34    
35     template<typename Addr>
36     class PXIPCacheT
37     {
38     public:
39     PXIPCacheT(const char *cachedir, uint32_t sig, int size, int expiredelay,
40     size_t datasize);
41     virtual ~PXIPCacheT();
42    
43     virtual time_t Get(const Addr &addr, void **oinfo);
44     virtual void Put(const Addr &addr, time_t t, const void *info);
45     virtual bool Invalidate(const Addr &addr);
46     virtual size_t GetCount();
47     virtual void Cleanup();
48    
49     virtual int SwapIn(const char *inFileName);
50     virtual int SwapOut(const char *inFileName);
51    
52     protected:
53    
54     ipcache_t mIPCache;
55     char * mCacheDir;
56     uint32_t mSig;
57     int mExpireDelay;
58     };
59    
60     template<typename Addr>
61     PXIPCacheT<Addr>::~PXIPCacheT()
62     {
63     ipcache_dispose(mIPCache);
64     peak_deallocate(mCacheDir);
65     }
66    
67     template<typename Addr>
68     inline size_t
69     PXIPCacheT<Addr>::GetCount()
70     {
71     this->Cleanup();
72     return ipcache_get_count(mIPCache);
73     }
74    
75     template<typename Addr>
76     inline void
77     PXIPCacheT<Addr>::Cleanup()
78     {
79     ipcache_cleanup(mIPCache, peak_time() - mExpireDelay);
80     }
81    
82     template<typename Addr>
83     int
84     PXIPCacheT<Addr>::SwapIn(const char *inFileName)
85     {
86     char path[MAXPATHLEN];
87     snprintf(path, sizeof(path), "%s/%s", mCacheDir, inFileName);
88     return ipcache_swapin(mIPCache, path, mSig);
89     }
90    
91     template<typename Addr>
92     int
93     PXIPCacheT<Addr>::SwapOut(const char *inFileName)
94     {
95     char path[MAXPATHLEN];
96     snprintf(path, sizeof(path), "%s/%s", mCacheDir, inFileName);
97     this->Cleanup();
98     return ipcache_swapout(mIPCache, path, mSig);
99     }
100    
101    
102     #endif // INCLUDED_PXIPCACHET_H_

svnadmin@ircd-hybrid.org
ViewVC Help
Powered by ViewVC 1.1.28