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