Panda3D
datagramSinkNet.cxx
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 datagramSinkNet.cxx
10  * @author drose
11  * @date 2009-02-15
12  */
13 
14 #include "pandabase.h"
15 
16 #include "datagramSinkNet.h"
17 
18 /**
19  * Creates a new DatagramSinkNet with the indicated number of threads to
20  * handle writing. Normally num_threads should be either 0 or 1 to guarantee
21  * that datagrams are delivered in the same order in which they were sent.
22  */
24 DatagramSinkNet(ConnectionManager *manager, int num_threads) :
25  ConnectionWriter(manager, num_threads)
26 {
27 }
28 
29 /**
30  * Sends the given datagram to the target. Returns true on success, false if
31  * there is an error. Blocks if necessary until the target is ready.
32  */
34 put_datagram(const Datagram &data) {
35  if (_target == nullptr) {
36  return false;
37  }
38  return send(data, _target, true);
39 }
40 
41 /**
42  * Returns true if there is an error on the target connection, or if the
43  * target has never been set.
44  */
47  return (_target == nullptr || _target->get_socket() == nullptr);
48 }
49 
50 /**
51  * Ensures that all datagrams previously written will be visible on the
52  * stream.
53  */
55 flush() {
56  if (_target != nullptr) {
57  _target->flush();
58  }
59 }
bool send(const Datagram &datagram, const PT(Connection) &connection, bool block=false)
Enqueues a datagram for transmittal on the indicated socket.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
The primary interface to the low-level networking layer in this package.
virtual void flush()
Ensures that all datagrams previously written will be visible on the stream.
virtual bool put_datagram(const Datagram &data)
Sends the given datagram to the target.
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
DatagramSinkNet(ConnectionManager *manager, int num_threads)
Creates a new DatagramSinkNet with the indicated number of threads to handle writing.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual bool is_error()
Returns true if there is an error on the target connection, or if the target has never been set.
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38