ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/device.C
Revision: 1.12
Committed: Mon Apr 1 03:10:26 2019 UTC (5 years, 1 month ago) by root
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.11: +5 -0 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 /*
2     device.C -- include the correct low-level implementation.
3 pcg 1.10 Copyright (C) 2003-2008 Marc Lehmann <gvpe@schmorp.de>
4 pcg 1.1
5 pcg 1.6 This file is part of GVPE.
6    
7 pcg 1.10 GVPE is free software; you can redistribute it and/or modify it
8     under the terms of the GNU General Public License as published by the
9     Free Software Foundation; either version 3 of the License, or (at your
10     option) any later version.
11    
12     This program is distributed in the hope that it will be useful, but
13     WITHOUT ANY WARRANTY; without even the implied warranty of
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15     Public License for more details.
16    
17     You should have received a copy of the GNU General Public License along
18     with this program; if not, see <http://www.gnu.org/licenses/>.
19    
20     Additional permission under GNU GPL version 3 section 7
21    
22     If you modify this Program, or any covered work, by linking or
23     combining it with the OpenSSL project's OpenSSL library (or a modified
24     version of that library), containing parts covered by the terms of the
25     OpenSSL or SSLeay licenses, the licensors of this Program grant you
26     additional permission to convey the resulting work. Corresponding
27     Source for a non-source form of such a combination shall include the
28     source code for the parts of OpenSSL used as well as that of the
29     covered work.
30 pcg 1.1 */
31    
32     #include "config.h"
33    
34     #include <cstring>
35     #include <cstdlib>
36 root 1.12 #include <stdexcept>
37 pcg 1.1
38     #include "slog.h"
39     #include "device.h"
40    
41     static void *pkt_cachep[PKTCACHESIZE];
42     static int pkt_cachen = 0;
43    
44 root 1.11 void *
45     net_packet::operator new(size_t s)
46 pcg 1.1 {
47     if (s > sizeof (data_packet))
48     {
49 pcg 1.9 slog (L_ERR, _("FATAL: allocation for network packet larger than max supported packet size (%d > %d)."),
50 pcg 1.1 s, sizeof (data_packet));
51     abort ();
52     }
53    
54     if (pkt_cachen)
55     return pkt_cachep[--pkt_cachen];
56     else
57     {
58     void *p = malloc (sizeof (data_packet));
59 root 1.12
60     if (!p)
61     throw (std::bad_alloc ());
62    
63 pcg 1.1 memset (p, 0, sizeof (data_packet));
64     return p;
65     }
66     }
67    
68 root 1.11 void
69     net_packet::operator delete(void *p)
70 pcg 1.1 {
71     if (p)
72     {
73     if (pkt_cachen < PKTCACHESIZE)
74     {
75     memset (p, 0, sizeof (data_packet));
76     pkt_cachep[pkt_cachen++] = p;
77     }
78     else
79     free (p);
80     }
81     }
82    
83 pcg 1.2 #if IFTYPE_tincd
84     # include "device-tincd.C"
85     #elif IFTYPE_native && IF_linux
86 pcg 1.1 # include "device-linux.C"
87 pcg 1.3 #elif IFTYPE_native && IF_cygwin
88 pcg 1.1 # include "device-cygwin.C"
89 pcg 1.7 #elif IFTYPE_native && IF_darwin
90     # include "device-darwin.C"
91 pcg 1.1 #else
92 pcg 1.2 # error No interface implementation for your IFTYPE/IFSUBTYPE combination.
93 pcg 1.1 #endif
94    
95