Panda3D

config_net.cxx

00001 // Filename: config_net.cxx
00002 // Created by:  drose (25Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #include "config_net.h"
00016 
00017 #include "netDatagram.h"
00018 #include "pandaSystem.h"
00019 
00020 #include "dconfig.h"
00021 
00022 Configure(config_net);
00023 NotifyCategoryDef(net, "");
00024 
00025 ConfigureFn(config_net) {
00026   init_libnet();
00027 }
00028 
00029 
00030 
00031 
00032 // The following two maximum queue sizes are totally arbitrary and
00033 // serve only to provide sanity caps on the various queues in the net
00034 // package.  You can set them to any sane values you like.  Also see
00035 // the set_max_queue_size() methods in the various classes, which you
00036 // can change at runtime on a particular instance.
00037 
00038 int
00039 get_net_max_write_queue() {
00040   static ConfigVariableInt *net_max_write_queue = NULL;
00041 
00042   if (net_max_write_queue == (ConfigVariableInt *)NULL) {
00043     net_max_write_queue = new ConfigVariableInt
00044       ("net-max-write-queue", 10000,
00045        PRC_DESC("This limits the number of datagrams in a ConnectionWriter's "
00046                 "output queue."));
00047   }
00048 
00049   return *net_max_write_queue;
00050 }
00051 
00052 int
00053 get_net_max_response_queue() {
00054   static ConfigVariableInt *net_max_response_queue = NULL;
00055 
00056   if (net_max_response_queue == (ConfigVariableInt *)NULL) {
00057     net_max_response_queue = new ConfigVariableInt
00058       ("net-max-response-queue", 50000,
00059        PRC_DESC("This limits the number of datagrams, messages, what have you, "
00060                 "in the various QueuedConnectionReader, QueuedConnectionListener, "
00061                 "and QueuedConnectionManager classes."));
00062   }
00063 
00064   return *net_max_response_queue;
00065 }
00066 
00067 bool
00068 get_net_error_abort() {
00069   static ConfigVariableBool *net_error_abort = NULL;
00070 
00071   if (net_error_abort == (ConfigVariableBool *)NULL) {
00072     net_error_abort = new ConfigVariableBool
00073       ("net-error-abort", false);
00074   }
00075 
00076   return *net_error_abort;
00077 }
00078 
00079 double
00080 get_net_max_poll_cycle() {
00081   static ConfigVariableDouble *net_max_poll_cycle = NULL;
00082 
00083   if (net_max_poll_cycle == (ConfigVariableDouble *)NULL) {
00084     net_max_poll_cycle = new ConfigVariableDouble
00085       ("net-max-poll-cycle", 0.2,
00086        PRC_DESC("Specifies the maximum amount of time, in seconds, to "
00087                 "continue to read data within one cycle of the poll() "
00088                 "call.  If this is negative, the program will wait as "
00089                 "long as data is available to be read.  Setting this to "
00090                 "a reasonable value prevents poll() from completely "
00091                 "starving the rest of the application when data is coming "
00092                 "in faster than it can be processed."));
00093   }
00094 
00095   return *net_max_poll_cycle;
00096 }
00097 
00098 double
00099 get_net_max_block() {
00100   static ConfigVariableDouble *net_max_block = NULL;
00101 
00102   if (net_max_block == (ConfigVariableDouble *)NULL) {
00103     net_max_block = new ConfigVariableDouble
00104       ("net-max-block", 0.01,
00105        PRC_DESC("Specifies the maximum amount of time, in seconds, to "
00106                 "completely block the process during any blocking wait "
00107                 "in the net subsystem.  This is an internal timeout only, "
00108                 "and gives the net subsystem a chance to detect things "
00109                 "like explicitly-closed connections in another thread; it "
00110                 "does not affect the blocking behavior at the high "
00111                 "level.")); 
00112   }
00113 
00114   return *net_max_block;
00115 }
00116 
00117 // This function is used in the ReaderThread and WriterThread
00118 // constructors to make a simple name for each thread.
00119 string
00120 make_thread_name(const string &thread_name, int thread_index) {
00121   ostringstream stream;
00122   stream << thread_name << "_" << thread_index;
00123   return stream.str();
00124 }
00125 
00126 
00127 ConfigVariableInt net_max_read_per_epoch
00128 ("net-max-read-per-epoch", 1024,
00129  PRC_DESC("The maximum number of bytes to read from the net in a single "
00130           "thread epoch, when SIMPLE_THREADS is defined.  This is designed "
00131           "to minimize the impact of the networking layer on the other "
00132           "threads."));
00133 
00134 ConfigVariableInt net_max_write_per_epoch
00135 ("net-max-write-per-epoch", 1024,
00136  PRC_DESC("The maximum number of bytes to write to the net in a single "
00137           "thread epoch, when SIMPLE_THREADS is defined.  This is designed "
00138           "to minimize the impact of the networking layer on the other "
00139           "threads."));
00140 
00141 ConfigVariableEnum<ThreadPriority> net_thread_priority
00142 ("net-thread-priority", TP_low,
00143  PRC_DESC("The default thread priority when creating threaded readers "
00144           "or writers."));
00145 
00146 
00147 ////////////////////////////////////////////////////////////////////
00148 //     Function: init_libnet
00149 //  Description: Initializes the library.  This must be called at
00150 //               least once before any of the functions or classes in
00151 //               this library can be used.  Normally it will be
00152 //               called by the static initializers and need not be
00153 //               called explicitly, but special cases exist.
00154 ////////////////////////////////////////////////////////////////////
00155 void
00156 init_libnet() {
00157   static bool initialized = false;
00158   if (initialized) {
00159     return;
00160   }
00161   initialized = true;
00162 
00163   NetDatagram::init_type();
00164 
00165   PandaSystem *ps = PandaSystem::get_global_ptr();
00166   ps->add_system("net");
00167 }
 All Classes Functions Variables Enumerations