Panda3D

Loading...
Searching...
No Matches
queuedConnectionListener.cxx
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file queuedConnectionListener.cxx
10 * @author drose
11 * @date 2000-02-09
12 */
13
14#include "queuedConnectionListener.h"
15#include "config_net.h"
16
17 template class QueuedReturn<ConnectionListenerData>;
18
19/**
20 *
21 */
22QueuedConnectionListener::
23QueuedConnectionListener(ConnectionManager *manager, int num_threads) :
24 ConnectionListener(manager, num_threads)
25{
26}
27
28/**
29 *
30 */
31QueuedConnectionListener::
32~QueuedConnectionListener() {
33 // We call shutdown() here to guarantee that all threads are gone before the
34 // QueuedReturn destructs.
35 shutdown();
36}
37
38/**
39 * Returns true if a new connection was recently established; the connection
40 * information may then be retrieved via get_new_connection().
41 */
42 bool QueuedConnectionListener::
43 new_connection_available() {
44 poll();
45 return thing_available();
46}
47
48/**
49 * If a previous call to new_connection_available() returned true, this
50 * function will return information about the newly established connection.
51 *
52 * The rendezvous parameter is the particular rendezvous socket this new
53 * connection originally communicated with; it is provided in case the
54 * ConnectionListener was monitorind more than one and you care which one it
55 * was. The address parameter is the net address of the new client, and
56 * new_connection is the socket of the newly established connection.
57 *
58 * The return value is true if a connection was successfully returned, or
59 * false if there was, in fact, no new connection. (This may happen if there
60 * are multiple threads accessing the QueuedConnectionListener).
61 */
62 bool QueuedConnectionListener::
63 get_new_connection(PT(Connection) &rendezvous,
64 NetAddress &address,
65 PT(Connection) &new_connection) {
66 ConnectionListenerData result;
67 if (!get_thing(result)) {
68 return false;
69 }
70
71 rendezvous = result._rendezvous;
72 address = result._address;
73 new_connection = result._new_connection;
74 return true;
75}
76
77/**
78 * This flavor of get_new_connection() simply returns a new connection,
79 * assuming the user doesn't care about the rendezvous socket that originated
80 * it or the address it came from.
81 */
82 bool QueuedConnectionListener::
83 get_new_connection(PT(Connection) &new_connection) {
84 PT(Connection) rendezvous;
85 NetAddress address;
86 return get_new_connection(rendezvous, address, new_connection);
87}
88
89
90/**
91 * An internal function called by ConnectionListener() when a new TCP
92 * connection has been established. The QueuedConnectionListener simply
93 * queues up this fact for later retrieval by get_new_connection().
94 */
95 void QueuedConnectionListener::
96connection_opened(const PT(Connection) &rendezvous,
97 const NetAddress &address,
98 const PT(Connection) &new_connection) {
99 ConnectionListenerData nc;
100 nc._rendezvous = rendezvous;
101 nc._address = address;
102 nc._new_connection = new_connection;
103
104 if (!enqueue_thing(nc)) {
105 net_cat.error()
106 << "QueuedConnectionListener queue full!\n";
107 }
108}
ConnectionListenerData
Definition queuedConnectionListener.h:26
ConnectionListener
This is a special kind of ConnectionReader that waits for activity on a rendezvous port and accepts a...
Definition connectionListener.h:31
ConnectionManager
The primary interface to the low-level networking layer in this package.
Definition connectionManager.h:41
ConnectionReader::poll
void poll()
Explicitly polls the available sockets to see if any of them have any noise.
Definition connectionReader.cxx:260
ConnectionReader::shutdown
void shutdown()
Terminates all threads cleanly.
Definition connectionReader.cxx:353
NetAddress
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound.
Definition netAddress.h:25
QueuedConnectionListener::get_new_connection
bool get_new_connection(PT(Connection) &rendezvous, NetAddress &address, PT(Connection) &new_connection)
If a previous call to new_connection_available() returned true, this function will return information...
Definition queuedConnectionListener.cxx:63
QueuedConnectionListener::new_connection_available
bool new_connection_available()
Returns true if a new connection was recently established; the connection information may then be ret...
Definition queuedConnectionListener.cxx:43
QueuedReturn
This is the implementation of a family of things that queue up their return values for later retrieva...
Definition queuedReturn.h:35
config_net.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
queuedConnectionListener.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.