ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/device.C
Revision: 1.4
Committed: Thu Oct 16 02:41:21 2003 UTC (20 years, 7 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: poll-based-iom, VPE_1_2
Changes since 1.3: +1 -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.4 Copyright (C) 2003 Marc Lehmann <pcg@goof.com>
4 pcg 1.1
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 pcg 1.2 #if IFTYPE_tincd
65     # include "device-tincd.C"
66     #elif IFTYPE_native && IF_linux
67 pcg 1.1 # include "device-linux.C"
68 pcg 1.3 #elif IFTYPE_native && IF_cygwin
69 pcg 1.1 # include "device-cygwin.C"
70     #else
71 pcg 1.2 # error No interface implementation for your IFTYPE/IFSUBTYPE combination.
72 pcg 1.1 #endif
73    
74