Panda3D
netDatagram.cxx
1 // Filename: netDatagram.cxx
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 #include "netDatagram.h"
16 
17 TypeHandle NetDatagram::_type_handle;
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: NetDatagram::Constructor
21 // Access: Public
22 // Description: Constructs an empty datagram.
23 ////////////////////////////////////////////////////////////////////
26 }
27 
28 ////////////////////////////////////////////////////////////////////
29 // Function: NetDatagram::Constructor
30 // Access: Public
31 // Description: Constructs a datagram from an existing block of data.
32 ////////////////////////////////////////////////////////////////////
34 NetDatagram(const void *data, size_t size) :
35  Datagram(data, size) {
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: NetDatagram::Copy Constructor
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
44 NetDatagram(const Datagram &copy) :
45  Datagram(copy)
46 {
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: NetDatagram::Copy Constructor
51 // Access: Public
52 // Description:
53 ////////////////////////////////////////////////////////////////////
55 NetDatagram(const NetDatagram &copy) :
56  Datagram(copy),
57  _connection(copy._connection),
58  _address(copy._address)
59 {
60 }
61 
62 ////////////////////////////////////////////////////////////////////
63 // Function: NetDatagram::Copy Assignment Operator
64 // Access: Public
65 // Description:
66 ////////////////////////////////////////////////////////////////////
67 void NetDatagram::
68 operator = (const Datagram &copy) {
69  Datagram::operator = (copy);
70  _connection.clear();
71  _address.clear();
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function: NetDatagram::Copy Assignment Operator
76 // Access: Public
77 // Description:
78 ////////////////////////////////////////////////////////////////////
79 void NetDatagram::
80 operator = (const NetDatagram &copy) {
81  Datagram::operator = (copy);
82  _connection = copy._connection;
83  _address = copy._address;
84 }
85 
86 ////////////////////////////////////////////////////////////////////
87 // Function: NetDatagram::clear
88 // Access: Public, Virtual
89 // Description: Resets the datagram to empty, in preparation for
90 // building up a new datagram.
91 ////////////////////////////////////////////////////////////////////
92 void NetDatagram::
93 clear() {
95  _connection.clear();
96  _address.clear();
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function: NetDatagram::set_connection
101 // Access: Public
102 // Description: Specifies the socket to which the datagram should be
103 // written.
104 ////////////////////////////////////////////////////////////////////
105 void NetDatagram::
106 set_connection(const PT(Connection) &connection) {
107  _connection = connection;
108 }
109 
110 ////////////////////////////////////////////////////////////////////
111 // Function: NetDatagram::set_connection
112 // Access: Public
113 // Description: Retrieves the socket from which the datagram was
114 // read, or to which it is scheduled to be written.
115 ////////////////////////////////////////////////////////////////////
116 PT(Connection) NetDatagram::
117 get_connection() const {
118  return _connection;
119 }
120 
121 ////////////////////////////////////////////////////////////////////
122 // Function: NetDatagram::set_address
123 // Access: Public
124 // Description: Specifies the host to which the datagram should be
125 // sent.
126 ////////////////////////////////////////////////////////////////////
127 void NetDatagram::
128 set_address(const NetAddress &address) {
129  _address = address;
130 }
131 
132 ////////////////////////////////////////////////////////////////////
133 // Function: NetDatagram::set_address
134 // Access: Public
135 // Description: Retrieves the host from which the datagram was
136 // read, or to which it is scheduled to be sent.
137 ////////////////////////////////////////////////////////////////////
139 get_address() const {
140  return _address;
141 }
A specific kind of Datagram, especially for sending across or receiving from a network.
Definition: netDatagram.h:43
Datagram()
Constructs an empty datagram.
Definition: datagram.I:21
virtual void clear()
Resets the datagram to empty, in preparation for building up a new datagram.
Definition: datagram.cxx:41
void clear()
Resets the NetAddress to its initial state.
Definition: netAddress.cxx:93
virtual void clear()
Resets the datagram to empty, in preparation for building up a new datagram.
Definition: netDatagram.cxx:93
const NetAddress & get_address() const
Retrieves the host from which the datagram was read, or to which it is scheduled to be sent...
NetDatagram()
Constructs an empty datagram.
Definition: netDatagram.cxx:25
void set_connection(const PT(Connection) &connection)
Specifies the socket to which the datagram should be written.
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