1 |
/* |
2 |
device.C -- include the correct low-level implementation. |
3 |
Copyright (C) 2003-2005 Marc Lehmann <gvpe@schmorp.de> |
4 |
|
5 |
This file is part of GVPE. |
6 |
|
7 |
GVPE is free software; you can redistribute it and/or modify |
8 |
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 |
along with gvpe; if not, write to the Free Software |
19 |
Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 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)."), |
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 |
#if IFTYPE_tincd |
67 |
# include "device-tincd.C" |
68 |
#elif IFTYPE_native && IF_linux |
69 |
# include "device-linux.C" |
70 |
#elif IFTYPE_native && IF_cygwin |
71 |
# include "device-cygwin.C" |
72 |
#elif IFTYPE_native && IF_darwin |
73 |
# include "device-darwin.C" |
74 |
#else |
75 |
# error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
76 |
#endif |
77 |
|
78 |
|