diff --git a/panda/src/express/Sources.pp b/panda/src/express/Sources.pp index b59899e6cf..dec8e3e53f 100644 --- a/panda/src/express/Sources.pp +++ b/panda/src/express/Sources.pp @@ -14,6 +14,7 @@ circBuffer.h \ config_express.h \ compress_string.h \ + copy_stream.h \ datagram.I datagram.h datagramGenerator.I \ datagramGenerator.h \ datagramIterator.I datagramIterator.h datagramSink.I datagramSink.h \ @@ -74,6 +75,7 @@ buffer.cxx checksumHashGenerator.cxx \ config_express.cxx \ compress_string.cxx \ + copy_stream.cxx \ datagram.cxx datagramGenerator.cxx \ datagramIterator.cxx \ datagramSink.cxx dcast.cxx \ @@ -125,6 +127,7 @@ circBuffer.h \ config_express.h \ compress_string.h \ + copy_stream.h \ datagram.I datagram.h datagramGenerator.I \ datagramGenerator.h \ datagramIterator.I datagramIterator.h datagramSink.I datagramSink.h \ diff --git a/panda/src/express/copy_stream.cxx b/panda/src/express/copy_stream.cxx new file mode 100755 index 0000000000..7902716258 --- /dev/null +++ b/panda/src/express/copy_stream.cxx @@ -0,0 +1,39 @@ +// Filename: copy_stream.cxx +// Created by: drose (27Aug09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#include "copy_stream.h" + +//////////////////////////////////////////////////////////////////// +// Function: copy_stream +// Access: Published +// Description: Reads the source stream from its current position to +// the end of the stream, and writes that data to the +// dest stream at its current position. Returns true on +// success, false on failure. +//////////////////////////////////////////////////////////////////// +bool +copy_stream(istream &source, ostream &dest) { + static const size_t buffer_size = 4096; + char buffer[buffer_size]; + + source.read(buffer, buffer_size); + size_t count = source.gcount(); + while (count != 0) { + dest.write(buffer, count); + source.read(buffer, buffer_size); + count = source.gcount(); + } + + return (!source.fail() || source.eof()) && (!dest.fail()); +} diff --git a/panda/src/express/copy_stream.h b/panda/src/express/copy_stream.h new file mode 100755 index 0000000000..6e2274aa4e --- /dev/null +++ b/panda/src/express/copy_stream.h @@ -0,0 +1,25 @@ +// Filename: copy_stream.h +// Created by: drose (27Aug09) +// +//////////////////////////////////////////////////////////////////// +// +// PANDA 3D SOFTWARE +// Copyright (c) Carnegie Mellon University. All rights reserved. +// +// All use of this software is subject to the terms of the revised BSD +// license. You should have received a copy of this license along +// with this source code in a file named "LICENSE." +// +//////////////////////////////////////////////////////////////////// + +#ifndef COPY_STREAM_H +#define COPY_STREAM_H + +#include "pandabase.h" + +BEGIN_PUBLISH +EXPCL_PANDAEXPRESS bool +copy_stream(istream &source, ostream &dest); +END_PUBLISH + +#endif diff --git a/panda/src/express/express_composite1.cxx b/panda/src/express/express_composite1.cxx index e92102d38d..19ac8a0c56 100644 --- a/panda/src/express/express_composite1.cxx +++ b/panda/src/express/express_composite1.cxx @@ -2,6 +2,7 @@ #include "checksumHashGenerator.cxx" #include "config_express.cxx" #include "compress_string.cxx" +#include "copy_stream.cxx" #include "datagram.cxx" #include "datagramGenerator.cxx" #include "datagramIterator.cxx"