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_max_poll_cycle() {
00081   static ConfigVariableDouble *max_poll_cycle = NULL;
00082 
00083   if (max_poll_cycle == (ConfigVariableDouble *)NULL) {
00084     max_poll_cycle = new ConfigVariableDouble
00085       ("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 *max_poll_cycle;
00096 }
00097 
00098 // This function is used in the ReaderThread and WriterThread
00099 // constructors to make a simple name for each thread.
00100 string
00101 make_thread_name(const string &thread_name, int thread_index) {
00102   ostringstream stream;
00103   stream << thread_name << "_" << thread_index;
00104   return stream.str();
00105 }
00106 
00107 
00108 ConfigVariableInt net_max_read_per_epoch
00109 ("net-max-read-per-epoch", 1024,
00110  PRC_DESC("The maximum number of bytes to read from the net in a single "
00111           "thread epoch, when SIMPLE_THREADS is defined.  This is designed "
00112           "to minimize the impact of the networking layer on the other "
00113           "threads."));
00114 
00115 ConfigVariableInt net_max_write_per_epoch
00116 ("net-max-write-per-epoch", 1024,
00117  PRC_DESC("The maximum number of bytes to write to the net in a single "
00118           "thread epoch, when SIMPLE_THREADS is defined.  This is designed "
00119           "to minimize the impact of the networking layer on the other "
00120           "threads."));
00121 
00122 ConfigVariableEnum<ThreadPriority> net_thread_priority
00123 ("net-thread-priority", TP_low,
00124  PRC_DESC("The default thread priority when creating threaded readers "
00125           "or writers."));
00126 
00127 
00128 ////////////////////////////////////////////////////////////////////
00129 //     Function: init_libnet
00130 //  Description: Initializes the library.  This must be called at
00131 //               least once before any of the functions or classes in
00132 //               this library can be used.  Normally it will be
00133 //               called by the static initializers and need not be
00134 //               called explicitly, but special cases exist.
00135 ////////////////////////////////////////////////////////////////////
00136 void
00137 init_libnet() {
00138   static bool initialized = false;
00139   if (initialized) {
00140     return;
00141   }
00142   initialized = true;
00143 
00144   NetDatagram::init_type();
00145 
00146   PandaSystem *ps = PandaSystem::get_global_ptr();
00147   ps->add_system("net");
00148 }
 All Classes Functions Variables Enumerations