Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/net/connectionWriter.h

Go to the documentation of this file.
00001 // Filename: connectionWriter.h
00002 // Created by:  drose (08Feb00)
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 #ifndef CONNECTIONWRITER_H
00020 #define CONNECTIONWRITER_H
00021 
00022 #include <pandabase.h>
00023 
00024 #include "datagramQueue.h"
00025 #include "connection.h"
00026 
00027 #include <pointerTo.h>
00028 
00029 #include <prthread.h>
00030 #include "pvector.h"
00031 
00032 class ConnectionManager;
00033 class NetAddress;
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //       Class : ConnectionWriter
00037 // Description : This class handles threaded delivery of datagrams to
00038 //               various TCP or UDP sockets.
00039 //
00040 //               A ConnectionWriter may define an arbitrary number of
00041 //               threads (at least one) to write its datagrams to
00042 //               sockets.  The number of threads is specified at
00043 //               construction time and cannot be changed.
00044 ////////////////////////////////////////////////////////////////////
00045 class EXPCL_PANDA ConnectionWriter {
00046 PUBLISHED:
00047   ConnectionWriter(ConnectionManager *manager, int num_threads);
00048   ~ConnectionWriter();
00049 
00050   bool send(const Datagram &datagram,
00051             const PT(Connection) &connection);
00052 
00053   bool send(const Datagram &datagram,
00054             const PT(Connection) &connection,
00055             const NetAddress &address);
00056 
00057   bool is_valid_for_udp(const Datagram &datagram) const;
00058 
00059   ConnectionManager *get_manager() const;
00060   bool is_immediate() const;
00061   int get_num_threads() const;
00062 
00063   void set_raw_mode(bool mode);
00064   bool get_raw_mode() const;
00065 
00066 protected:
00067   void clear_manager();
00068 
00069 private:
00070   static void thread_start(void *data);
00071   void thread_run();
00072   bool send_datagram(const NetDatagram &datagram);
00073 
00074 protected:
00075   ConnectionManager *_manager;
00076 
00077 private:
00078   bool _raw_mode;
00079   DatagramQueue _queue;
00080 
00081   typedef pvector<PRThread *> Threads;
00082   Threads _threads;
00083   bool _immediate;
00084 
00085 friend class ConnectionManager;
00086 };
00087 
00088 #endif
00089 
00090 

Generated on Fri May 2 00:40:34 2003 for Panda by doxygen1.3