E-MailRelay
glimits.h
Go to the documentation of this file.
1//
2// Copyright (C) 2001-2024 Graeme Walker <graeme_walker@users.sourceforge.net>
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 3 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, see <http://www.gnu.org/licenses/>.
16// ===
17///
18/// \file glimits.h
19///
20
21#ifndef G_LIMITS_H
22#define G_LIMITS_H
23
24#include "gdef.h"
25
26namespace G
27{
28 enum class Scale
29 {
30 Normal ,
31 Small
32 } ;
33 #ifdef G_SMALL
34 template <Scale N = Scale::Small> struct Limits ;
35 #else
36 template <Scale N = Scale::Normal> struct Limits ;
37 #endif
38 template <> struct Limits<Scale::Normal> ;
39 template <> struct Limits<Scale::Small> ;
40}
41
42//| \class G::Limits
43/// A set of compile-time buffer sizes. Intended to be used to
44/// reduce memory requirements in embedded environments.
45///
46template <G::Scale N>
48{
49} ;
50
51template <>
52struct G::Limits<G::Scale::Normal> /// Normal specialisation of G::Limits.
53{
54 static constexpr bool is_small = false ;
55 static constexpr int log = 1000 ; // log line limit
56 static constexpr int path_buffer = 1024 ; // getcwd() first-attempt buffer size
57 static constexpr int file_buffer = 8192 ; // read() buffer size for file copying (BUFSIZ)
58 static constexpr int net_buffer = 20000 ; // read() buffer size for network reads (>=16k is best for TLS)
59 static constexpr int net_listen_queue = 31 ; // listen(2) backlog parameter (cf. apache 511)
60 static constexpr int net_file_limit = 200000000 ; // DoS limit reading a file from the network
61 Limits() = delete ;
62} ;
63
64template <>
65struct G::Limits<G::Scale::Small> /// Small-memory specialisation of G::Limits.
66{
67 static constexpr bool is_small = true ;
68 static constexpr int log = 120 ;
69 static constexpr int path_buffer = 64 ;
70 static constexpr int file_buffer = 4096 ;
71 static constexpr int net_buffer = 4096 ;
72 static constexpr int net_listen_queue = 3 ;
73 static constexpr int net_file_limit = 10000000 ;
74 Limits() = delete ;
75} ;
76
77#endif
Low-level classes.
Definition: garg.h:36
A set of compile-time buffer sizes.
Definition: glimits.h:48