00001 // Filename: datagramSinkNet.cxx 00002 // Created by: drose (15Feb09) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 #include "pandabase.h" 00016 00017 #include "datagramSinkNet.h" 00018 00019 //////////////////////////////////////////////////////////////////// 00020 // Function: DatagramSinkNet::Constructor 00021 // Access: Published 00022 // Description: Creates a new DatagramSinkNet with the indicated 00023 // number of threads to handle writing. Normally 00024 // num_threads should be either 0 or 1 to guarantee that 00025 // datagrams are delivered in the same order in which 00026 // they were sent. 00027 //////////////////////////////////////////////////////////////////// 00028 DatagramSinkNet:: 00029 DatagramSinkNet(ConnectionManager *manager, int num_threads) : 00030 ConnectionWriter(manager, num_threads) 00031 { 00032 } 00033 00034 //////////////////////////////////////////////////////////////////// 00035 // Function: DatagramSinkNet::put_datagram 00036 // Access: Published, Virtual 00037 // Description: Sends the given datagram to the target. Returns true 00038 // on success, false if there is an error. Blocks if 00039 // necessary until the target is ready. 00040 //////////////////////////////////////////////////////////////////// 00041 bool DatagramSinkNet:: 00042 put_datagram(const Datagram &data) { 00043 if (_target == (Connection *)NULL) { 00044 return false; 00045 } 00046 return send(data, _target, true); 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: DatagramSinkNet::is_error 00051 // Access: Published, Virtual 00052 // Description: Returns true if there is an error on the target 00053 // connection, or if the target has never been set. 00054 //////////////////////////////////////////////////////////////////// 00055 bool DatagramSinkNet:: 00056 is_error() { 00057 return (_target == (Connection *)NULL || _target->get_socket() == (Socket_IP *)NULL); 00058 } 00059 00060 //////////////////////////////////////////////////////////////////// 00061 // Function: DatagramSinkNet::flush 00062 // Access: Public, Virtual 00063 // Description: Ensures that all datagrams previously written will be 00064 // visible on the stream. 00065 //////////////////////////////////////////////////////////////////// 00066 void DatagramSinkNet:: 00067 flush() { 00068 if (_target != (Connection *)NULL) { 00069 _target->flush(); 00070 } 00071 }