40 set_tcp_header_size(4);
41 _writer.set_tcp_header_size(4);
44 _monitor->set_client_data(_client_data);
73 _tcp_connection = tcp_connection;
77 _udp_connection = _manager->open_UDP_connection(_udp_port);
78 while (_udp_connection.is_null()) {
81 _udp_connection = _manager->open_UDP_connection(_udp_port);
95 _client_data->_is_alive =
false;
96 _monitor->lost_connection();
99 _manager->close_connection(_tcp_connection);
100 _manager->close_connection(_udp_connection);
101 _tcp_connection.clear();
102 _udp_connection.clear();
111 dequeue_frame_data();
126 std::string PStatReader::
128 if (_hostname.empty()) {
130 if (_hostname.empty()) {
131 _hostname =
"unknown";
143 message._type = PStatServerControlMessage::T_hello;
144 message._server_hostname = get_hostname();
145 message._server_progname = _monitor->get_monitor_name();
146 message._udp_port = _udp_port;
150 _writer.
send(datagram, _tcp_connection);
159 Connection *connection = datagram.get_connection();
161 if (connection == _tcp_connection) {
163 if (message.
decode(datagram, _client_data)) {
164 handle_client_control_message(message);
166 }
else if (message._type == PStatClientControlMessage::T_datagram) {
167 handle_client_udp_data(datagram);
170 nout <<
"Got unexpected message from client.\n";
173 }
else if (connection == _udp_connection) {
174 handle_client_udp_data(datagram);
177 nout <<
"Got datagram from unexpected socket.\n";
187 switch (message._type) {
188 case PStatClientControlMessage::T_hello:
190 _client_data->set_version(message._major_version, message._minor_version);
194 if (message._major_version != server_major_version ||
195 (message._major_version == server_major_version &&
196 message._minor_version > server_minor_version)) {
197 _monitor->bad_version(message._client_hostname, message._client_progname,
198 message._major_version, message._minor_version,
199 server_major_version, server_minor_version);
202 _monitor->hello_from(message._client_hostname, message._client_progname);
207 case PStatClientControlMessage::T_define_collectors:
209 for (
int i = 0; i < (int)message._collectors.size(); i++) {
210 _client_data->add_collector(message._collectors[i]);
211 _monitor->new_collector(message._collectors[i]->_index);
216 case PStatClientControlMessage::T_define_threads:
218 for (
int i = 0; i < (int)message._names.size(); i++) {
219 int thread_index = message._first_thread_index + i;
220 std::string name = message._names[i];
221 _client_data->define_thread(thread_index, name);
222 _monitor->new_thread(thread_index);
228 nout <<
"Invalid control message received from client.\n";
237 handle_client_udp_data(
const Datagram &datagram) {
238 if (!_monitor->is_client_known()) {
248 if (_client_data->is_at_least(2, 1)) {
250 int initial_byte = source.get_uint8();
251 nassertv(initial_byte == 0);
254 if (!_queued_frame_data.
full()) {
256 data._thread_index = source.get_uint16();
257 data._frame_number = source.get_uint32();
259 data._frame_data->read_datagram(source, _client_data);
272 dequeue_frame_data() {
273 while (!_queued_frame_data.
empty()) {
274 const FrameData &data = _queued_frame_data.
front();
275 nassertv(_client_data !=
nullptr);
278 int num_levels = data._frame_data->get_num_levels();
279 for (
int i = 0; i < num_levels; i++) {
280 int collector_index = data._frame_data->get_level_collector(i);
281 if (!_client_data->get_collector_has_level(collector_index, data._thread_index)) {
283 _client_data->set_collector_has_level(collector_index, data._thread_index,
true);
284 _monitor->new_collector(collector_index);
288 _client_data->record_new_frame(data._thread_index,
291 _monitor->new_data(data._thread_index, data._frame_number);
bool full() const
Returns true if the buffer is full; if this is true, push_back() will fail.
bool empty() const
Returns true if the buffer is empty.
const Thing & front() const
Returns a reference to the first item in the queue.
void pop_front()
Removes the first item from the buffer.
void push_back(const Thing &t)
Adds an item to the end of the buffer.
get_host_name
Returns the name of this particular machine on the network, if available, or the empty string if the ...
This is an abstract base class for a family of classes that listen for activity on a socket and respo...
bool add_connection(Connection *connection)
Adds a new socket to the list of sockets the ConnectionReader will monitor.
bool send(const Datagram &datagram, const PT(Connection) &connection, bool block=false)
Enqueues a datagram for transmittal on the indicated socket.
Represents a single TCP or UDP socket for input or output.
A class to retrieve the individual data elements previously stored in a Datagram.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
A specific kind of Datagram, especially for sending across or receiving from a network.
This kind of message is sent from the client to the server on the TCP socket to establish critical co...
bool decode(const Datagram &datagram, PStatClientVersion *version)
Extracts the message from the indicated datagram.
The data associated with a particular client, but not with any one particular frame or thread: the li...
Contains the raw timing and level data for a single frame.
This is an abstract class that presents the interface to any number of different front-ends for the s...
void lost_connection()
This is called by the PStatServer when it detects that the connection has been lost.
void set_tcp_connection(Connection *tcp_connection)
This is intended to be called only once, immediately after construction, by the PStatListener that cr...
void idle()
Called each frame to do what needs to be done for the monitor's user- defined idle routines.
void close()
This will be called by the PStatClientData in response to its close() call.
PStatMonitor * get_monitor()
Returns the monitor that this reader serves.
This kind of message is sent from the server to the client on the TCP socket to establish critical co...
void encode(Datagram &datagram) const
Writes the message into the indicated datagram.
The overall manager of the network connections.
void remove_reader(Connection *connection, PStatReader *reader)
Removes the indicated reader.
void release_udp_port(int port)
Indicates that the given UDP port is once again free for use.
int get_udp_port()
Returns a new port number that will probably be free to use as a UDP port.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
int get_current_pstat_major_version()
Returns the current major version number of the PStats protocol.
int get_current_pstat_minor_version()
Returns the current minor version number of the PStats protocol.
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.