ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/device.C
Revision: 1.1
Committed: Sat Mar 1 15:53:03 2003 UTC (21 years, 2 months ago) by pcg
Content type: text/plain
Branch: MAIN
CVS Tags: VPE_0_9, VPE_1_0
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 pcg 1.1 /*
2     device.C -- include the correct low-level implementation.
3    
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU General Public License as published by
6     the Free Software Foundation; either version 2 of the License, or
7     (at your option) any later version.
8    
9     This program is distributed in the hope that it will be useful,
10     but WITHOUT ANY WARRANTY; without even the implied warranty of
11     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12     GNU General Public License for more details.
13    
14     You should have received a copy of the GNU General Public License
15     along with this program; if not, write to the Free Software
16     Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17     */
18    
19     #include "config.h"
20    
21     #include <cstring>
22     #include <cstdlib>
23    
24     #include "slog.h"
25     #include "device.h"
26    
27     static void *pkt_cachep[PKTCACHESIZE];
28     static int pkt_cachen = 0;
29    
30     void *net_packet::operator new(size_t s)
31     {
32     if (s > sizeof (data_packet))
33     {
34     slog (L_ERR, _("FATAL: allocation for network packet larger than max supported packet size (%d > %d).\n"),
35     s, sizeof (data_packet));
36     abort ();
37     }
38    
39     if (pkt_cachen)
40     return pkt_cachep[--pkt_cachen];
41     else
42     {
43     void *p = malloc (sizeof (data_packet));
44     memset (p, 0, sizeof (data_packet));
45     return p;
46     }
47     }
48    
49     void net_packet::operator delete(void *p)
50     {
51     if (p)
52     {
53     if (pkt_cachen < PKTCACHESIZE)
54     {
55     memset (p, 0, sizeof (data_packet));
56     pkt_cachep[pkt_cachen++] = p;
57     }
58     else
59     free (p);
60     }
61     }
62    
63     #if defined(__linux__)
64     # include "device-linux.C"
65     #elif defined(__CYGWIN__)
66     # include "device-cygwin.C"
67     #else
68     # error No device implementation for your OS.
69     #endif
70    
71