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 */
23 DatagramSinkNet::
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 */
33 bool DatagramSinkNet::
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 */
45 bool DatagramSinkNet::
46 is_error() {
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 */
54 void DatagramSinkNet::
55 flush() {
56 if (_target != nullptr) {
57 _target->flush();
58 }
59 }
ConnectionManager
The primary interface to the low-level networking layer in this package.
Definition: connectionManager.h:41
ConnectionWriter
This class handles threaded delivery of datagrams to various TCP or UDP sockets.
Definition: connectionWriter.h:35
ConnectionWriter::send
bool send(const Datagram &datagram, const PT(Connection) &connection, bool block=false)
Enqueues a datagram for transmittal on the indicated socket.
Definition: connectionWriter.cxx:143
DatagramSinkNet::flush
virtual void flush()
Ensures that all datagrams previously written will be visible on the stream.
Definition: datagramSinkNet.cxx:55
DatagramSinkNet::DatagramSinkNet
DatagramSinkNet(ConnectionManager *manager, int num_threads)
Creates a new DatagramSinkNet with the indicated number of threads to handle writing.
Definition: datagramSinkNet.cxx:24
DatagramSinkNet::is_error
virtual bool is_error()
Returns true if there is an error on the target connection, or if the target has never been set.
Definition: datagramSinkNet.cxx:46
DatagramSinkNet::put_datagram
virtual bool put_datagram(const Datagram &data)
Sends the given datagram to the target.
Definition: datagramSinkNet.cxx:34
Datagram
An ordered list of data elements, formatted in memory for transmission over a socket or writing to a ...
Definition: datagram.h:38
datagramSinkNet.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.