Panda3D

netDatagram.h

00001 // Filename: netDatagram.h
00002 // Created by:  jns (07Feb00)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef NETDATAGRAM_H
00016 #define NETDATAGRAM_H
00017 
00018 #include "pandabase.h"
00019 
00020 #include "connection.h"
00021 #include "netAddress.h"
00022 
00023 #include "datagram.h"
00024 #include "pointerTo.h"
00025 
00026 #include <string>
00027 
00028 // This determines the size of the read buffer used to read UDP
00029 // packets.  It places a limit on the maximum receivable size of a UDP
00030 // packet (although it doesn't limit TCP packets at all).  However,
00031 // there's no real reason this can't be set arbitrarily large,
00032 // although there's not much point in making it larger than the system
00033 // MTU, which also limits the maximum size of a UDP packet.
00034 static const int maximum_udp_datagram = 1500;
00035 
00036 ////////////////////////////////////////////////////////////////////
00037 //       Class : NetDatagram
00038 // Description : A specific kind of Datagram, especially for sending
00039 //               across or receiving from a network.  It's different
00040 //               only in that it knows which Connection and/or
00041 //               NetAddress it is to be sent to or was received from.
00042 ////////////////////////////////////////////////////////////////////
00043 class EXPCL_PANDA_NET NetDatagram : public Datagram {
00044 PUBLISHED:
00045   NetDatagram();
00046   NetDatagram(const void *data, size_t size);
00047   NetDatagram(const Datagram &copy);
00048   NetDatagram(const NetDatagram &copy);
00049   void operator = (const Datagram &copy);
00050   void operator = (const NetDatagram &copy);
00051 
00052   virtual void clear();
00053 
00054   void set_connection(const PT(Connection) &connection);
00055   PT(Connection) get_connection() const;
00056 
00057   void set_address(const NetAddress &address);
00058   const NetAddress &get_address() const;
00059 
00060 public:
00061   // We need these methods to make VC++ happy when we try to
00062   // instantiate a QueuedReturn<Datagram>.  They don't do anything
00063   // useful.
00064   INLINE bool operator == (const NetDatagram &other) const;
00065   INLINE bool operator != (const NetDatagram &other) const;
00066   INLINE bool operator < (const NetDatagram &other) const;
00067 
00068 private:
00069   PT(Connection) _connection;
00070   NetAddress _address;
00071 
00072 
00073 public:
00074   static TypeHandle get_class_type() {
00075     return _type_handle;
00076   }
00077   static void init_type() {
00078     Datagram::init_type();
00079     register_type(_type_handle, "NetDatagram",
00080                   Datagram::get_class_type());
00081   }
00082   virtual TypeHandle get_type() const {
00083     return get_class_type();
00084   }
00085   virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
00086 
00087 private:
00088   static TypeHandle _type_handle;
00089 };
00090 
00091 #include "netDatagram.I"
00092 
00093 #endif
 All Classes Functions Variables Enumerations