ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/device.C
Revision: 1.5
Committed: Sat Jan 17 01:18:36 2004 UTC (20 years, 4 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: VPE_1_4, VPE_1_6, rel-1_7, VPE-1_6_1
Changes since 1.4: +1 -1 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 /*
2 device.C -- include the correct low-level implementation.
3 Copyright (C) 2003-2004 Marc Lehmann <pcg@goof.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (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
20 #include "config.h"
21
22 #include <cstring>
23 #include <cstdlib>
24
25 #include "slog.h"
26 #include "device.h"
27
28 static void *pkt_cachep[PKTCACHESIZE];
29 static int pkt_cachen = 0;
30
31 void *net_packet::operator new(size_t s)
32 {
33 if (s > sizeof (data_packet))
34 {
35 slog (L_ERR, _("FATAL: allocation for network packet larger than max supported packet size (%d > %d).\n"),
36 s, sizeof (data_packet));
37 abort ();
38 }
39
40 if (pkt_cachen)
41 return pkt_cachep[--pkt_cachen];
42 else
43 {
44 void *p = malloc (sizeof (data_packet));
45 memset (p, 0, sizeof (data_packet));
46 return p;
47 }
48 }
49
50 void net_packet::operator delete(void *p)
51 {
52 if (p)
53 {
54 if (pkt_cachen < PKTCACHESIZE)
55 {
56 memset (p, 0, sizeof (data_packet));
57 pkt_cachep[pkt_cachen++] = p;
58 }
59 else
60 free (p);
61 }
62 }
63
64 #if IFTYPE_tincd
65 # include "device-tincd.C"
66 #elif IFTYPE_native && IF_linux
67 # include "device-linux.C"
68 #elif IFTYPE_native && IF_cygwin
69 # include "device-cygwin.C"
70 #else
71 # error No interface implementation for your IFTYPE/IFSUBTYPE combination.
72 #endif
73
74