Panda3D
Loading...
Searching...
No Matches
config_net.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file config_net.cxx
10 * @author drose
11 * @date 2000-02-25
12 */
13
14#include "config_net.h"
15
16#include "netDatagram.h"
17#include "pandaSystem.h"
18
19#include "dconfig.h"
20
21#if !defined(CPPPARSER) && !defined(LINK_ALL_STATIC) && !defined(BUILDING_PANDA_NET)
22 #error Buildsystem error: BUILDING_PANDA_NET not defined
23#endif
24
25Configure(config_net);
26NotifyCategoryDef(net, "");
27
28ConfigureFn(config_net) {
30}
31
32
33
34
35// The following two maximum queue sizes are totally arbitrary and serve only
36// to provide sanity caps on the various queues in the net package. You can
37// set them to any sane values you like. Also see the set_max_queue_size()
38// methods in the various classes, which you can change at runtime on a
39// particular instance.
40
41int
42get_net_max_write_queue() {
43 static ConfigVariableInt *net_max_write_queue = nullptr;
44
45 if (net_max_write_queue == nullptr) {
46 net_max_write_queue = new ConfigVariableInt
47 ("net-max-write-queue", 10000,
48 PRC_DESC("This limits the number of datagrams in a ConnectionWriter's "
49 "output queue."));
50 }
51
52 return *net_max_write_queue;
53}
54
55int
56get_net_max_response_queue() {
57 static ConfigVariableInt *net_max_response_queue = nullptr;
58
59 if (net_max_response_queue == nullptr) {
60 net_max_response_queue = new ConfigVariableInt
61 ("net-max-response-queue", 50000,
62 PRC_DESC("This limits the number of datagrams, messages, what have you, "
63 "in the various QueuedConnectionReader, QueuedConnectionListener, "
64 "and QueuedConnectionManager classes."));
65 }
66
67 return *net_max_response_queue;
68}
69
70bool
71get_net_error_abort() {
72 static ConfigVariableBool *net_error_abort = nullptr;
73
74 if (net_error_abort == nullptr) {
75 net_error_abort = new ConfigVariableBool
76 ("net-error-abort", false);
77 }
78
79 return *net_error_abort;
80}
81
82double
83get_net_max_poll_cycle() {
84 static ConfigVariableDouble *net_max_poll_cycle = nullptr;
85
86 if (net_max_poll_cycle == nullptr) {
87 net_max_poll_cycle = new ConfigVariableDouble
88 ("net-max-poll-cycle", 0.2,
89 PRC_DESC("Specifies the maximum amount of time, in seconds, to "
90 "continue to read data within one cycle of the poll() "
91 "call. If this is negative, the program will wait as "
92 "long as data is available to be read. Setting this to "
93 "a reasonable value prevents poll() from completely "
94 "starving the rest of the application when data is coming "
95 "in faster than it can be processed."));
96 }
97
98 return *net_max_poll_cycle;
99}
100
101double
102get_net_max_block() {
103 static ConfigVariableDouble *net_max_block = nullptr;
104
105 if (net_max_block == nullptr) {
106 net_max_block = new ConfigVariableDouble
107 ("net-max-block", 0.01,
108 PRC_DESC("Specifies the maximum amount of time, in seconds, to "
109 "completely block the process during any blocking wait "
110 "in the net subsystem. This is an internal timeout only, "
111 "and gives the net subsystem a chance to detect things "
112 "like explicitly-closed connections in another thread; it "
113 "does not affect the blocking behavior at the high "
114 "level."));
115 }
116
117 return *net_max_block;
118}
119
120// This function is used in the ReaderThread and WriterThread constructors to
121// make a simple name for each thread.
122std::string
123make_thread_name(const std::string &thread_name, int thread_index) {
124 std::ostringstream stream;
125 stream << thread_name << "_" << thread_index;
126 return stream.str();
127}
128
129
130ConfigVariableInt net_max_read_per_epoch
131("net-max-read-per-epoch", 1024,
132 PRC_DESC("The maximum number of bytes to read from the net in a single "
133 "thread epoch, when SIMPLE_THREADS is defined. This is designed "
134 "to minimize the impact of the networking layer on the other "
135 "threads."));
136
137ConfigVariableInt net_max_write_per_epoch
138("net-max-write-per-epoch", 1024,
139 PRC_DESC("The maximum number of bytes to write to the net in a single "
140 "thread epoch, when SIMPLE_THREADS is defined. This is designed "
141 "to minimize the impact of the networking layer on the other "
142 "threads."));
143
144ConfigVariableEnum<ThreadPriority> net_thread_priority
145("net-thread-priority", TP_low,
146 PRC_DESC("The default thread priority when creating threaded readers "
147 "or writers."));
148
149
150/**
151 * Initializes the library. This must be called at least once before any of
152 * the functions or classes in this library can be used. Normally it will be
153 * called by the static initializers and need not be called explicitly, but
154 * special cases exist.
155 */
156void
158 static bool initialized = false;
159 if (initialized) {
160 return;
161 }
162 initialized = true;
163
164 NetDatagram::init_type();
165
167 ps->add_system("net");
168}
This is a convenience class to specialize ConfigVariable as a boolean type.
This is a convenience class to specialize ConfigVariable as a floating- point type.
This class specializes ConfigVariable as an enumerated type.
This is a convenience class to specialize ConfigVariable as an integer type.
This class is used as a namespace to group several global properties of Panda.
Definition pandaSystem.h:26
static PandaSystem * get_global_ptr()
Returns the global PandaSystem object.
void add_system(const std::string &system)
Intended for use by each subsystem to register itself at startup.
void init_libnet()
Initializes the library.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.