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