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