2001-10-06 14:13:28 +00:00
|
|
|
#include "COutputPacketStream.h"
|
|
|
|
|
|
|
|
//
|
|
|
|
// COuputPacketStream
|
|
|
|
//
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
COutputPacketStream::COutputPacketStream(
|
|
|
|
IOutputStream* stream,
|
|
|
|
bool adopt) :
|
|
|
|
COutputStreamFilter(stream, adopt)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
COutputPacketStream::~COutputPacketStream()
|
|
|
|
{
|
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
COutputPacketStream::close()
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
getStream()->close();
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
UInt32
|
|
|
|
COutputPacketStream::write(
|
|
|
|
const void* buffer,
|
|
|
|
UInt32 count)
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
// write the length of the payload
|
|
|
|
UInt8 length[4];
|
|
|
|
length[0] = (UInt8)((count >> 24) & 0xff);
|
|
|
|
length[1] = (UInt8)((count >> 16) & 0xff);
|
|
|
|
length[2] = (UInt8)((count >> 8) & 0xff);
|
|
|
|
length[3] = (UInt8)( count & 0xff);
|
2002-05-02 11:44:21 +00:00
|
|
|
UInt32 count2 = sizeof(length);
|
2001-10-06 14:13:28 +00:00
|
|
|
const UInt8* cbuffer = length;
|
|
|
|
while (count2 > 0) {
|
|
|
|
UInt32 n = getStream()->write(cbuffer, count2);
|
|
|
|
cbuffer += n;
|
|
|
|
count2 -= n;
|
|
|
|
}
|
|
|
|
|
|
|
|
// write the payload
|
|
|
|
count2 = count;
|
|
|
|
cbuffer = reinterpret_cast<const UInt8*>(buffer);
|
|
|
|
while (count2 > 0) {
|
|
|
|
UInt32 n = getStream()->write(cbuffer, count2);
|
|
|
|
cbuffer += n;
|
|
|
|
count2 -= n;
|
|
|
|
}
|
|
|
|
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2002-06-10 22:06:45 +00:00
|
|
|
void
|
|
|
|
COutputPacketStream::flush()
|
2001-10-06 14:13:28 +00:00
|
|
|
{
|
|
|
|
getStream()->flush();
|
|
|
|
}
|
|
|
|
|