diff --git a/panda/src/net/Sources.pp b/panda/src/net/Sources.pp index 04f285ac12..99a676985a 100644 --- a/panda/src/net/Sources.pp +++ b/panda/src/net/Sources.pp @@ -95,6 +95,16 @@ #end test_bin_target +#begin test_bin_target + #define TARGET test_raw_server + #define LOCAL_LIBS net + #define OTHER_LIBS $[OTHER_LIBS] pystub + + #define SOURCES \ + test_raw_server.cxx + +#end test_bin_target + #begin test_bin_target #define TARGET test_udp #define LOCAL_LIBS net diff --git a/panda/src/net/connectionManager.cxx b/panda/src/net/connectionManager.cxx index d4956336a7..e28cbea7c9 100644 --- a/panda/src/net/connectionManager.cxx +++ b/panda/src/net/connectionManager.cxx @@ -358,6 +358,12 @@ connection_reset(const PT(Connection) &connection, PRErrorCode errcode) { net_cat.info(false) << " (os error = " << PR_GetOSError() << ").\n"; } + + // Turns out we do need to explicitly mark the connection as closed + // immediately, rather than waiting for the user to do it, since + // otherwise we'll keep trying to listen for noise on the socket and + // we'll always here a "yes" answer. + close_connection(connection); } //////////////////////////////////////////////////////////////////// diff --git a/panda/src/net/test_datagram.cxx b/panda/src/net/test_datagram.cxx index 65dac02bf8..2e7f69a113 100644 --- a/panda/src/net/test_datagram.cxx +++ b/panda/src/net/test_datagram.cxx @@ -16,16 +16,11 @@ // //////////////////////////////////////////////////////////////////// -#include -#include -#include -#include - #include "netDatagram.h" #include "datagramIterator.h" -main() -{ +int +main() { NetDatagram dg; dg.add_int8((signed char) -10); diff --git a/panda/src/net/test_raw_server.cxx b/panda/src/net/test_raw_server.cxx new file mode 100644 index 0000000000..418175d83b --- /dev/null +++ b/panda/src/net/test_raw_server.cxx @@ -0,0 +1,111 @@ +// Filename: test_raw_server.cxx +// Created by: drose (20Jan04) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved +// +// All use of this software is subject to the terms of the Panda 3d +// Software license. You should have received a copy of this license +// along with this source code; you will also find a current copy of +// the license at http://www.panda3d.org/license.txt . +// +// To contact the maintainers of this program write to +// panda3d@yahoogroups.com . +// +//////////////////////////////////////////////////////////////////// + +#include "pandabase.h" + +#include "queuedConnectionManager.h" +#include "queuedConnectionListener.h" +#include "queuedConnectionReader.h" +#include "connectionWriter.h" +#include "netAddress.h" +#include "connection.h" +#include "netDatagram.h" + +#include "pset.h" + +int +main(int argc, char *argv[]) { + if (argc != 2) { + nout << "test_raw_server port\n"; + exit(1); + } + + int port = atoi(argv[1]); + + QueuedConnectionManager cm; + PT(Connection) rendezvous = cm.open_TCP_server_rendezvous(port, 5); + + if (rendezvous.is_null()) { + nout << "Cannot grab port " << port << ".\n"; + exit(1); + } + + nout << "Listening for connections on port " << port << "\n"; + + QueuedConnectionListener listener(&cm, 0); + listener.add_connection(rendezvous); + + typedef pset< PT(Connection) > Clients; + Clients clients; + + QueuedConnectionReader reader(&cm, 0); + ConnectionWriter writer(&cm, 0); + reader.set_raw_mode(true); + writer.set_raw_mode(true); + + bool shutdown = false; + while (!shutdown) { + // Check for new clients. + while (listener.new_connection_available()) { + PT(Connection) rv; + NetAddress address; + PT(Connection) new_connection; + if (listener.get_new_connection(rv, address, new_connection)) { + nout << "Got connection from " << address << "\n"; + reader.add_connection(new_connection); + clients.insert(new_connection); + } + } + + // Check for reset clients. + while (cm.reset_connection_available()) { + PT(Connection) connection; + if (cm.get_reset_connection(connection)) { + nout << "Lost connection from " + << connection->get_address() << "\n"; + clients.erase(connection); + cm.close_connection(connection); + } + } + + // Process all available datagrams. + while (reader.data_available()) { + NetDatagram datagram; + if (reader.get_data(datagram)) { + string data = datagram.get_message(); + nout.write(data.data(), data.length()); + nout << flush; + + Clients::iterator ci; + for (ci = clients.begin(); ci != clients.end(); ++ci) { + writer.send(datagram, (*ci)); + } + } + } + + // Yield the timeslice before we poll again. + PR_Sleep(PR_MillisecondsToInterval(100)); + } + + return (0); +} + + + + +