00001 // Filename: queuedConnectionListener.cxx 00002 // Created by: drose (09Feb00) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #include "queuedConnectionListener.h" 00020 #include "config_net.h" 00021 00022 //////////////////////////////////////////////////////////////////// 00023 // Function: QueuedConnectionListener::Constructor 00024 // Access: Public 00025 // Description: 00026 //////////////////////////////////////////////////////////////////// 00027 QueuedConnectionListener:: 00028 QueuedConnectionListener(ConnectionManager *manager, int num_threads) : 00029 ConnectionListener(manager, num_threads) 00030 { 00031 } 00032 00033 //////////////////////////////////////////////////////////////////// 00034 // Function: QueuedConnectionListener::Destructor 00035 // Access: Public, Virtual 00036 // Description: 00037 //////////////////////////////////////////////////////////////////// 00038 QueuedConnectionListener:: 00039 ~QueuedConnectionListener() { 00040 // We call shutdown() here to guarantee that all threads are gone 00041 // before the QueuedReturn destructs. 00042 shutdown(); 00043 } 00044 00045 //////////////////////////////////////////////////////////////////// 00046 // Function: QueuedConnectionListener::new_connection_available 00047 // Access: Public 00048 // Description: Returns true if a new connection was recently 00049 // established; the connection information may then be 00050 // retrieved via get_new_connection(). 00051 //////////////////////////////////////////////////////////////////// 00052 bool QueuedConnectionListener:: 00053 new_connection_available() { 00054 poll(); 00055 return thing_available(); 00056 } 00057 00058 //////////////////////////////////////////////////////////////////// 00059 // Function: QueuedConnectionListener::get_new_connection 00060 // Access: Public 00061 // Description: If a previous call to new_connection_available() 00062 // returned true, this function will return information 00063 // about the newly established connection. 00064 // 00065 // The rendezvous parameter is the particular rendezvous 00066 // socket this new connection originally communicated 00067 // with; it is provided in case the ConnectionListener 00068 // was monitorind more than one and you care which one 00069 // it was. The address parameter is the net address of 00070 // the new client, and new_connection is the socket of 00071 // the newly established connection. 00072 // 00073 // The return value is true if a connection was 00074 // successfully returned, or false if there was, in 00075 // fact, no new connection. (This may happen if there 00076 // are multiple threads accessing the 00077 // QueuedConnectionListener). 00078 //////////////////////////////////////////////////////////////////// 00079 bool QueuedConnectionListener:: 00080 get_new_connection(PT(Connection) &rendezvous, 00081 NetAddress &address, 00082 PT(Connection) &new_connection) { 00083 ConnectionListenerData result; 00084 if (!get_thing(result)) { 00085 return false; 00086 } 00087 00088 rendezvous = result._rendezvous; 00089 address = result._address; 00090 new_connection = result._new_connection; 00091 return true; 00092 } 00093 00094 //////////////////////////////////////////////////////////////////// 00095 // Function: QueuedConnectionListener::get_new_connection 00096 // Access: Public 00097 // Description: This flavor of get_new_connection() simply returns a 00098 // new connection, assuming the user doesn't care about 00099 // the rendezvous socket that originated it or the 00100 // address it came from. 00101 //////////////////////////////////////////////////////////////////// 00102 bool QueuedConnectionListener:: 00103 get_new_connection(PT(Connection) &new_connection) { 00104 PT(Connection) rendezvous; 00105 NetAddress address; 00106 return get_new_connection(rendezvous, address, new_connection); 00107 } 00108 00109 00110 //////////////////////////////////////////////////////////////////// 00111 // Function: QueuedConnectionListener::connection_opened 00112 // Access: Protected, Virtual 00113 // Description: An internal function called by ConnectionListener() 00114 // when a new TCP connection has been established. The 00115 // QueuedConnectionListener simply queues up this fact 00116 // for later retrieval by get_new_connection(). 00117 //////////////////////////////////////////////////////////////////// 00118 void QueuedConnectionListener:: 00119 connection_opened(const PT(Connection) &rendezvous, 00120 const NetAddress &address, 00121 const PT(Connection) &new_connection) { 00122 ConnectionListenerData nc; 00123 nc._rendezvous = rendezvous; 00124 nc._address = address; 00125 nc._new_connection = new_connection; 00126 00127 if (!enqueue_thing(nc)) { 00128 net_cat.error() 00129 << "QueuedConnectionListener queue full!\n"; 00130 } 00131 }