Panda3D
netDatagram.h
1 // Filename: netDatagram.h
2 // Created by: jns (07Feb00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef NETDATAGRAM_H
16 #define NETDATAGRAM_H
17 
18 #include "pandabase.h"
19 
20 #include "connection.h"
21 #include "netAddress.h"
22 
23 #include "datagram.h"
24 #include "pointerTo.h"
25 
26 #include <string>
27 
28 // This determines the size of the read buffer used to read UDP
29 // packets. It places a limit on the maximum receivable size of a UDP
30 // packet (although it doesn't limit TCP packets at all). However,
31 // there's no real reason this can't be set arbitrarily large,
32 // although there's not much point in making it larger than the system
33 // MTU, which also limits the maximum size of a UDP packet.
34 static const int maximum_udp_datagram = 1500;
35 
36 ////////////////////////////////////////////////////////////////////
37 // Class : NetDatagram
38 // Description : A specific kind of Datagram, especially for sending
39 // across or receiving from a network. It's different
40 // only in that it knows which Connection and/or
41 // NetAddress it is to be sent to or was received from.
42 ////////////////////////////////////////////////////////////////////
43 class EXPCL_PANDA_NET NetDatagram : public Datagram {
44 PUBLISHED:
45  NetDatagram();
46  NetDatagram(const void *data, size_t size);
47  NetDatagram(const Datagram &copy);
48  NetDatagram(const NetDatagram &copy);
49  void operator = (const Datagram &copy);
50  void operator = (const NetDatagram &copy);
51 
52  virtual void clear();
53 
54  void set_connection(const PT(Connection) &connection);
55  PT(Connection) get_connection() const;
56 
57  void set_address(const NetAddress &address);
58  const NetAddress &get_address() const;
59 
60 public:
61  // We need these methods to make VC++ happy when we try to
62  // instantiate a QueuedReturn<Datagram>. They don't do anything
63  // useful.
64  INLINE bool operator == (const NetDatagram &other) const;
65  INLINE bool operator != (const NetDatagram &other) const;
66  INLINE bool operator < (const NetDatagram &other) const;
67 
68 private:
69  PT(Connection) _connection;
70  NetAddress _address;
71 
72 
73 public:
74  static TypeHandle get_class_type() {
75  return _type_handle;
76  }
77  static void init_type() {
78  Datagram::init_type();
79  register_type(_type_handle, "NetDatagram",
80  Datagram::get_class_type());
81  }
82  virtual TypeHandle get_type() const {
83  return get_class_type();
84  }
85  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
86 
87 private:
88  static TypeHandle _type_handle;
89 };
90 
91 #include "netDatagram.I"
92 
93 #endif
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition: netDatagram.h:43
virtual void clear()
Resets the datagram to empty, in preparation for building up a new datagram.
Definition: datagram.cxx:41
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
Represents a single TCP or UDP socket for input or output.
Definition: connection.h:32
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:43
Represents a network address to which UDP packets may be sent or to which a TCP socket may be bound...
Definition: netAddress.h:27