Browse Source

expose shutdown()

David Rose 16 years ago
parent
commit
7ed5437e15

+ 1 - 1
panda/src/net/connectionReader.I

@@ -15,7 +15,7 @@
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::is_polling
 //     Function: ConnectionReader::is_polling
-//       Access: Public
+//       Access: Published
 //  Description: Returns true if the reader is a polling reader,
 //  Description: Returns true if the reader is a polling reader,
 //               i.e. it has no threads.
 //               i.e. it has no threads.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////

+ 36 - 35
panda/src/net/connectionReader.cxx

@@ -89,7 +89,7 @@ thread_main() {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::Constructor
 //     Function: ConnectionReader::Constructor
-//       Access: Public
+//       Access: Published
 //  Description: Creates a new ConnectionReader with the indicated
 //  Description: Creates a new ConnectionReader with the indicated
 //               number of threads to handle requests.  If num_threads
 //               number of threads to handle requests.  If num_threads
 //               is 0, the sockets will only be read by polling,
 //               is 0, the sockets will only be read by polling,
@@ -137,7 +137,7 @@ ConnectionReader(ConnectionManager *manager, int num_threads) :
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::Destructor
 //     Function: ConnectionReader::Destructor
-//       Access: Public, Virtual
+//       Access: Published, Virtual
 //  Description:
 //  Description:
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 ConnectionReader::
 ConnectionReader::
@@ -170,7 +170,7 @@ ConnectionReader::
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::add_connection
 //     Function: ConnectionReader::add_connection
-//       Access: Public
+//       Access: Published
 //  Description: Adds a new socket to the list of sockets the
 //  Description: Adds a new socket to the list of sockets the
 //               ConnectionReader will monitor.  A datagram that comes
 //               ConnectionReader will monitor.  A datagram that comes
 //               in on any of the monitored sockets will be reported.
 //               in on any of the monitored sockets will be reported.
@@ -207,7 +207,7 @@ add_connection(Connection *connection) {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::remove_connection
 //     Function: ConnectionReader::remove_connection
-//       Access: Public
+//       Access: Published
 //  Description: Removes a socket from the list of sockets being
 //  Description: Removes a socket from the list of sockets being
 //               monitored.  Returns true if the socket was correctly
 //               monitored.  Returns true if the socket was correctly
 //               removed, false if it was not on the list in the first
 //               removed, false if it was not on the list in the first
@@ -238,7 +238,7 @@ remove_connection(Connection *connection) {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::is_connection_ok
 //     Function: ConnectionReader::is_connection_ok
-//       Access: Public
+//       Access: Published
 //  Description: Returns true if the indicated connection has been
 //  Description: Returns true if the indicated connection has been
 //               added to the ConnectionReader and is being monitored
 //               added to the ConnectionReader and is being monitored
 //               properly, false if it is not known, or if there was
 //               properly, false if it is not known, or if there was
@@ -271,7 +271,7 @@ is_connection_ok(Connection *connection) {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::poll
 //     Function: ConnectionReader::poll
-//       Access: Public
+//       Access: Published
 //  Description: Explicitly polls the available sockets to see if any
 //  Description: Explicitly polls the available sockets to see if any
 //               of them have any noise.  This function does nothing
 //               of them have any noise.  This function does nothing
 //               unless this is a polling-type ConnectionReader,
 //               unless this is a polling-type ConnectionReader,
@@ -315,7 +315,7 @@ poll() {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::get_manager
 //     Function: ConnectionReader::get_manager
-//       Access: Public
+//       Access: Published
 //  Description: Returns a pointer to the ConnectionManager object
 //  Description: Returns a pointer to the ConnectionManager object
 //               that serves this ConnectionReader.
 //               that serves this ConnectionReader.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -326,7 +326,7 @@ get_manager() const {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::get_num_threads
 //     Function: ConnectionReader::get_num_threads
-//       Access: Public
+//       Access: Published
 //  Description: Returns the number of threads the ConnectionReader
 //  Description: Returns the number of threads the ConnectionReader
 //               has been created with.
 //               has been created with.
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -337,7 +337,7 @@ get_num_threads() const {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::set_raw_mode
 //     Function: ConnectionReader::set_raw_mode
-//       Access: Public
+//       Access: Published
 //  Description: Sets the ConnectionReader into raw mode (or turns off
 //  Description: Sets the ConnectionReader into raw mode (or turns off
 //               raw mode).  In raw mode, datagram headers are not
 //               raw mode).  In raw mode, datagram headers are not
 //               expected; instead, all the data available on the pipe
 //               expected; instead, all the data available on the pipe
@@ -353,7 +353,7 @@ set_raw_mode(bool mode) {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::get_raw_mode
 //     Function: ConnectionReader::get_raw_mode
-//       Access: Public
+//       Access: Published
 //  Description: Returns the current setting of the raw mode flag.
 //  Description: Returns the current setting of the raw mode flag.
 //               See set_raw_mode().
 //               See set_raw_mode().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -364,7 +364,7 @@ get_raw_mode() const {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::set_tcp_header_size
 //     Function: ConnectionReader::set_tcp_header_size
-//       Access: Public
+//       Access: Published
 //  Description: Sets the header size of TCP packets.  At the present,
 //  Description: Sets the header size of TCP packets.  At the present,
 //               legal values for this are 0, 2, or 4; this specifies
 //               legal values for this are 0, 2, or 4; this specifies
 //               the number of bytes to use encode the datagram length
 //               the number of bytes to use encode the datagram length
@@ -378,7 +378,7 @@ set_tcp_header_size(int tcp_header_size) {
 
 
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::get_tcp_header_size
 //     Function: ConnectionReader::get_tcp_header_size
-//       Access: Public
+//       Access: Published
 //  Description: Returns the current setting of TCP header size.
 //  Description: Returns the current setting of TCP header size.
 //               See set_tcp_header_size().
 //               See set_tcp_header_size().
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
@@ -387,6 +387,30 @@ get_tcp_header_size() const {
   return _tcp_header_size;
   return _tcp_header_size;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: ConnectionReader::shutdown
+//       Access: Published
+//  Description: Terminates all threads cleanly.  Normally this is
+//               only called by the destructor, but it may be called
+//               explicitly before destruction.
+////////////////////////////////////////////////////////////////////
+void ConnectionReader::
+shutdown() {
+  if (_shutdown) {
+    return;
+  }
+
+  // First, begin the shutdown.  This will tell our threads we want
+  // them to quit.
+  _shutdown = true;
+
+  // Now wait for all of our threads to terminate.
+  Threads::iterator ti;
+  for (ti = _threads.begin(); ti != _threads.end(); ++ti) {
+    (*ti)->join();
+  }
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::flush_read_connection
 //     Function: ConnectionReader::flush_read_connection
 //       Access: Protected, Virtual
 //       Access: Protected, Virtual
@@ -426,29 +450,6 @@ flush_read_connection(Connection *connection) {
   }
   }
 }
 }
 
 
-////////////////////////////////////////////////////////////////////
-//     Function: ConnectionReader::shutdown
-//       Access: Protected
-//  Description: Terminates all threads cleanly.  Normally this is
-//               only called by the destructor.
-////////////////////////////////////////////////////////////////////
-void ConnectionReader::
-shutdown() {
-  if (_shutdown) {
-    return;
-  }
-
-  // First, begin the shutdown.  This will tell our threads we want
-  // them to quit.
-  _shutdown = true;
-
-  // Now wait for all of our threads to terminate.
-  Threads::iterator ti;
-  for (ti = _threads.begin(); ti != _threads.end(); ++ti) {
-    (*ti)->join();
-  }
-}
-
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionReader::clear_manager
 //     Function: ConnectionReader::clear_manager
 //       Access: Protected
 //       Access: Protected

+ 2 - 1
panda/src/net/connectionReader.h

@@ -86,6 +86,8 @@ PUBLISHED:
   void set_tcp_header_size(int tcp_header_size);
   void set_tcp_header_size(int tcp_header_size);
   int get_tcp_header_size() const;
   int get_tcp_header_size() const;
 
 
+  void shutdown();
+
 protected:
 protected:
   virtual void flush_read_connection(Connection *connection);
   virtual void flush_read_connection(Connection *connection);
   virtual void receive_datagram(const NetDatagram &datagram)=0;
   virtual void receive_datagram(const NetDatagram &datagram)=0;
@@ -102,7 +104,6 @@ protected:
   };
   };
   typedef pvector<SocketInfo *> Sockets;
   typedef pvector<SocketInfo *> Sockets;
 
 
-  void shutdown();
   void clear_manager();
   void clear_manager();
   void finish_socket(SocketInfo *sinfo);
   void finish_socket(SocketInfo *sinfo);
 
 

+ 29 - 19
panda/src/net/connectionWriter.cxx

@@ -73,6 +73,7 @@ ConnectionWriter(ConnectionManager *manager, int num_threads) :
   _raw_mode = false;
   _raw_mode = false;
   _tcp_header_size = tcp_header_size;
   _tcp_header_size = tcp_header_size;
   _immediate = (num_threads <= 0);
   _immediate = (num_threads <= 0);
+  _shutdown = false;
 
 
   int i;
   int i;
   for (i = 0; i < num_threads; i++) {
   for (i = 0; i < num_threads; i++) {
@@ -156,6 +157,7 @@ get_current_queue_size() const {
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 bool ConnectionWriter::
 bool ConnectionWriter::
 send(const Datagram &datagram, const PT(Connection) &connection, bool block) {
 send(const Datagram &datagram, const PT(Connection) &connection, bool block) {
+  nassertr(!_shutdown, false);
   nassertr(connection != (Connection *)NULL, false);
   nassertr(connection != (Connection *)NULL, false);
   nassertr(connection->get_socket()->is_exact_type(Socket_TCP::get_class_type()), false);
   nassertr(connection->get_socket()->is_exact_type(Socket_TCP::get_class_type()), false);
 
 
@@ -196,6 +198,7 @@ send(const Datagram &datagram, const PT(Connection) &connection, bool block) {
 bool ConnectionWriter::
 bool ConnectionWriter::
 send(const Datagram &datagram, const PT(Connection) &connection,
 send(const Datagram &datagram, const PT(Connection) &connection,
      const NetAddress &address, bool block) {
      const NetAddress &address, bool block) {
+  nassertr(!_shutdown, false);
   nassertr(connection != (Connection *)NULL, false);
   nassertr(connection != (Connection *)NULL, false);
   nassertr(connection->get_socket()->is_exact_type(Socket_UDP::get_class_type()), false);
   nassertr(connection->get_socket()->is_exact_type(Socket_UDP::get_class_type()), false);
 
 
@@ -321,6 +324,32 @@ get_tcp_header_size() const {
   return _tcp_header_size;
   return _tcp_header_size;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: ConnectionWriter::shutdown
+//       Access: Published
+//  Description: Stops all the threads and cleans them up.  This is
+//               called automatically by the destructor, but it may be
+//               called explicitly before destruction.
+////////////////////////////////////////////////////////////////////
+void ConnectionWriter::
+shutdown() {
+  if (_shutdown) {
+    return;
+  }
+  _shutdown = true;
+
+  // First, shutdown the queue.  This will tell our threads they're
+  // done.
+  _queue.shutdown();
+
+  // Now wait for all threads to terminate.
+  Threads::iterator ti;
+  for (ti = _threads.begin(); ti != _threads.end(); ++ti) {
+    (*ti)->join();
+  }
+  _threads.clear();
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: ConnectionWriter::clear_manager
 //     Function: ConnectionWriter::clear_manager
 //       Access: Protected
 //       Access: Protected
@@ -357,22 +386,3 @@ thread_run(int thread_index) {
     Thread::consider_yield();
     Thread::consider_yield();
   }
   }
 }
 }
-
-////////////////////////////////////////////////////////////////////
-//     Function: ConnectionWriter::shutdown
-//       Access: Private
-//  Description: Stops all the threads and cleans them up.
-////////////////////////////////////////////////////////////////////
-void ConnectionWriter::
-shutdown() {
-  // First, shutdown the queue.  This will tell our threads they're
-  // done.
-  _queue.shutdown();
-
-  // Now wait for all threads to terminate.
-  Threads::iterator ti;
-  for (ti = _threads.begin(); ti != _threads.end(); ++ti) {
-    (*ti)->join();
-  }
-  _threads.clear();
-}

+ 3 - 1
panda/src/net/connectionWriter.h

@@ -65,13 +65,14 @@ PUBLISHED:
   void set_tcp_header_size(int tcp_header_size);
   void set_tcp_header_size(int tcp_header_size);
   int get_tcp_header_size() const;
   int get_tcp_header_size() const;
 
 
+  void shutdown();
+
 protected:
 protected:
   void clear_manager();
   void clear_manager();
 
 
 private:
 private:
   void thread_run(int thread_index);
   void thread_run(int thread_index);
   bool send_datagram(const NetDatagram &datagram);
   bool send_datagram(const NetDatagram &datagram);
-  void shutdown();
 
 
 protected:
 protected:
   ConnectionManager *_manager;
   ConnectionManager *_manager;
@@ -80,6 +81,7 @@ private:
   bool _raw_mode;
   bool _raw_mode;
   int _tcp_header_size;
   int _tcp_header_size;
   DatagramQueue _queue;
   DatagramQueue _queue;
+  bool _shutdown;
 
 
   class WriterThread : public Thread {
   class WriterThread : public Thread {
   public:
   public: