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 |
pcg |
1.2 |
#if IFTYPE_tincd |
64 |
|
|
# include "device-tincd.C" |
65 |
|
|
#elif IFTYPE_native && IF_linux |
66 |
pcg |
1.1 |
# include "device-linux.C" |
67 |
pcg |
1.2 |
#elif ITYPEF_native && IF_cygwin |
68 |
pcg |
1.1 |
# include "device-cygwin.C" |
69 |
|
|
#else |
70 |
pcg |
1.2 |
# error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
71 |
pcg |
1.1 |
#endif |
72 |
|
|
|
73 |
|
|
|