Panda3D
 All Classes Functions Variables Enumerations
datagramSinkNet.cxx
1 // Filename: datagramSinkNet.cxx
2 // Created by: drose (15Feb09)
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 "pandabase.h"
16 
17 #include "datagramSinkNet.h"
18 
19 ////////////////////////////////////////////////////////////////////
20 // Function: DatagramSinkNet::Constructor
21 // Access: Published
22 // Description: Creates a new DatagramSinkNet with the indicated
23 // number of threads to handle writing. Normally
24 // num_threads should be either 0 or 1 to guarantee that
25 // datagrams are delivered in the same order in which
26 // they were sent.
27 ////////////////////////////////////////////////////////////////////
29 DatagramSinkNet(ConnectionManager *manager, int num_threads) :
30  ConnectionWriter(manager, num_threads)
31 {
32 }
33 
34 ////////////////////////////////////////////////////////////////////
35 // Function: DatagramSinkNet::put_datagram
36 // Access: Published, Virtual
37 // Description: Sends the given datagram to the target. Returns true
38 // on success, false if there is an error. Blocks if
39 // necessary until the target is ready.
40 ////////////////////////////////////////////////////////////////////
42 put_datagram(const Datagram &data) {
43  if (_target == (Connection *)NULL) {
44  return false;
45  }
46  return send(data, _target, true);
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: DatagramSinkNet::is_error
51 // Access: Published, Virtual
52 // Description: Returns true if there is an error on the target
53 // connection, or if the target has never been set.
54 ////////////////////////////////////////////////////////////////////
57  return (_target == (Connection *)NULL || _target->get_socket() == (Socket_IP *)NULL);
58 }
59 
60 ////////////////////////////////////////////////////////////////////
61 // Function: DatagramSinkNet::flush
62 // Access: Public, Virtual
63 // Description: Ensures that all datagrams previously written will be
64 // visible on the stream.
65 ////////////////////////////////////////////////////////////////////
67 flush() {
68  if (_target != (Connection *)NULL) {
69  _target->flush();
70  }
71 }
Base functionality for a INET domain Socket this call should be the starting point for all other unix...
Definition: socket_ip.h:34
The primary interface to the low-level networking layer in this package.
bool send(const Datagram &datagram, const PT(Connection)&connection, bool block=false)
Enqueues a datagram for transmittal on the indicated socket.
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.
virtual bool is_error()
Returns true if there is an error on the target connection, or if the target has never been set...
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