From 7f17eeb7fccd52b7049f9f598121130dfd1b55ae Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 21 Aug 2010 04:39:47 +0000 Subject: Client now inherits from stream. This could be cool, it could really mess\nthings up. We shall see. In other news, I'm adding a Bu::StreamStack class\nthat will let you easily manage dynamic stream/filter sets. --- src/client.cpp | 107 +++++++++++++++++++++++++++++++++++++++++----------- src/client.h | 45 +++++++++++++++------- src/streamstack.cpp | 86 +++++++++++++++++++++++++++++++++++++++++ src/streamstack.h | 47 +++++++++++++++++++++++ 4 files changed, 250 insertions(+), 35 deletions(-) create mode 100644 src/streamstack.cpp create mode 100644 src/streamstack.h (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 095dd91..789cda4 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -125,62 +125,62 @@ bool Bu::Client::isOpen() return pTopStream->isOpen(); } -void Bu::Client::write( const Bu::FString &sData ) +size_t Bu::Client::write( const Bu::FString &sData ) { - qbWrite.write( sData.getStr(), sData.getSize() ); + return qbWrite.write( sData.getStr(), sData.getSize() ); } -void Bu::Client::write( const void *pData, int nBytes ) +size_t Bu::Client::write( const void *pData, size_t nBytes ) { - qbWrite.write( pData, nBytes ); + return qbWrite.write( pData, nBytes ); } -void Bu::Client::write( int8_t nData ) +size_t Bu::Client::write( int8_t nData ) { - qbWrite.write( (const char *)&nData, sizeof(nData) ); + return qbWrite.write( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::write( int16_t nData ) +size_t Bu::Client::write( int16_t nData ) { - qbWrite.write( (const char *)&nData, sizeof(nData) ); + return qbWrite.write( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::write( int32_t nData ) +size_t Bu::Client::write( int32_t nData ) { - qbWrite.write( (const char *)&nData, sizeof(nData) ); + return qbWrite.write( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::write( int64_t nData ) +size_t Bu::Client::write( int64_t nData ) { - qbWrite.write( (const char *)&nData, sizeof(nData) ); + return qbWrite.write( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::write( uint8_t nData ) +size_t Bu::Client::write( uint8_t nData ) { - qbWrite.write( (const char *)&nData, sizeof(nData) ); + return qbWrite.write( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::write( uint16_t nData ) +size_t Bu::Client::write( uint16_t nData ) { - qbWrite.write( (const char *)&nData, sizeof(nData) ); + return qbWrite.write( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::write( uint32_t nData ) +size_t Bu::Client::write( uint32_t nData ) { - qbWrite.write( (const char *)&nData, sizeof(nData) ); + return qbWrite.write( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::write( uint64_t nData ) +size_t Bu::Client::write( uint64_t nData ) { - qbWrite.write( (const char *)&nData, sizeof(nData) ); + return qbWrite.write( (const char *)&nData, sizeof(nData) ); } -int Bu::Client::read( void *pData, int nBytes ) +size_t Bu::Client::read( void *pData, size_t nBytes ) { return qbRead.read( pData, nBytes ); } -int Bu::Client::peek( void *pData, int nBytes, int nOffset ) +size_t Bu::Client::peek( void *pData, int nBytes, int nOffset ) { return qbRead.peek( pData, nBytes, nOffset ); } @@ -237,3 +237,66 @@ void Bu::Client::tick() pProto->onTick( this ); } +long Bu::Client::tell() +{ +} + +void Bu::Client::seek( long offset ) +{ +} + +void Bu::Client::setPos( long pos ) +{ +} + +void Bu::Client::setPosEnd( long pos ) +{ +} + +bool Bu::Client::isEos() +{ + return true; +} + +void Bu::Client::flush() +{ +} + +bool Bu::Client::canRead() +{ + return qbRead.getSize() > 0; +} + +bool Bu::Client::canWrite() +{ + return true; +} + +bool Bu::Client::isReadable() +{ + return true; +} + +bool Bu::Client::isWritable() +{ + return true; +} + +bool Bu::Client::isSeekable() +{ + return false; +} + +bool Bu::Client::isBlocking() +{ + return false; +} + +void Bu::Client::setBlocking( bool bBlocking ) +{ +} + +void Bu::Client::setSize( long iSize ) +{ +} + diff --git a/src/client.h b/src/client.h index 5a933ca..105d48f 100644 --- a/src/client.h +++ b/src/client.h @@ -23,7 +23,7 @@ namespace Bu /** *@ingroup Serving */ - class Client + class Client : public Bu::Stream { public: Client( Bu::Socket *pSocket, Bu::ClientLinkFactory *pfLink ); @@ -34,18 +34,18 @@ namespace Bu //Bu::FString &getInput(); //Bu::FString &getOutput(); - void write( const Bu::FString &sData ); - void write( const void *pData, int nBytes ); - void write( int8_t nData ); - void write( int16_t nData ); - void write( int32_t nData ); - void write( int64_t nData ); - void write( uint8_t nData ); - void write( uint16_t nData ); - void write( uint32_t nData ); - void write( uint64_t nData ); - int read( void *pData, int nBytes ); - int peek( void *pData, int nBytes, int nOffset=0 ); + size_t write( const Bu::FString &sData ); + size_t write( const void *pData, size_t nBytes ); + size_t write( int8_t nData ); + size_t write( int16_t nData ); + size_t write( int32_t nData ); + size_t write( int64_t nData ); + size_t write( uint8_t nData ); + size_t write( uint16_t nData ); + size_t write( uint32_t nData ); + size_t write( uint64_t nData ); + size_t read( void *pData, size_t nBytes ); + size_t peek( void *pData, int nBytes, int nOffset=0 ); void seek( int nBytes ); long getInputSize(); long getOutputSize(); @@ -94,6 +94,25 @@ namespace Bu lFilts.prepend( pFlt ); } + /* + * These are required to qualify as a stream, I dunno how many will + * be implemented. + */ + virtual long tell(); + virtual void seek( long offset ); + virtual void setPos( long pos ); + virtual void setPosEnd( long pos ); + virtual bool isEos(); + virtual void flush(); + virtual bool canRead(); + virtual bool canWrite(); + virtual bool isReadable(); + virtual bool isWritable(); + virtual bool isSeekable(); + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); + virtual void setSize( long iSize ); + private: typedef Bu::List FilterList; FilterList lFilts; diff --git a/src/streamstack.cpp b/src/streamstack.cpp new file mode 100644 index 0000000..9e45cc4 --- /dev/null +++ b/src/streamstack.cpp @@ -0,0 +1,86 @@ +#include "bu/streamstack.h" + +Bu::StreamStack::StreamStack() +{ +} + +Bu::StreamStack::~StreamStack() +{ +} + +void Bu::StreamStack::close() +{ +} + +size_t Bu::StreamStack::read( void *pBuf, size_t nBytes ) +{ +} + +size_t Bu::StreamStack::write( const void *pBuf, size_t nBytes ) +{ +} + +size_t Bu::StreamStack::write( const Bu::FString &sBuf ) +{ +} + +long Bu::StreamStack::tell() +{ +} + +void Bu::StreamStack::seek( long offset ) +{ +} + +void Bu::StreamStack::setPos( long pos ) +{ +} + +void Bu::StreamStack::setPosEnd( long pos ) +{ +} + +bool Bu::StreamStack::isEos() +{ +} + +bool Bu::StreamStack::isOpen() +{ +} + +void Bu::StreamStack::flush() +{ +} + +bool Bu::StreamStack::canRead() +{ +} + +bool Bu::StreamStack::canWrite() +{ +} + +bool Bu::StreamStack::isReadable() +{ +} + +bool Bu::StreamStack::isWritable() +{ +} + +bool Bu::StreamStack::isSeekable() +{ +} + +bool Bu::StreamStack::isBlocking() +{ +} + +void Bu::StreamStack::setBlocking( bool bBlocking ) +{ +} + +void Bu::StreamStack::setSize( long iSize ) +{ +} + diff --git a/src/streamstack.h b/src/streamstack.h new file mode 100644 index 0000000..03d8d8f --- /dev/null +++ b/src/streamstack.h @@ -0,0 +1,47 @@ +#ifndef BU_STREAM_STACK_H +#define BU_STREAM_STACK_H + +#include "bu/stream.h" + +namespace Bu +{ + class StreamStack : public Bu::Stream + { + public: + StreamStack(); + virtual ~StreamStack(); + + + // + // Everything below here merely passes on the call to the top of the + // stream stack. + // + + virtual void close(); + virtual size_t read( void *pBuf, size_t nBytes ); + virtual size_t write( const void *pBuf, size_t nBytes ); + + virtual size_t write( const Bu::FString &sBuf ); + virtual long tell(); + virtual void seek( long offset ); + virtual void setPos( long pos ); + virtual void setPosEnd( long pos ); + virtual bool isEos(); + virtual bool isOpen(); + virtual void flush(); + virtual bool canRead(); + virtual bool canWrite(); + virtual bool isReadable(); + virtual bool isWritable(); + virtual bool isSeekable(); + virtual bool isBlocking(); + virtual void setBlocking( bool bBlocking=true ); + virtual void setSize( long iSize ); + + private: + typedef Bu::List FilterList; + FilterList lFilts; + }; +}; + +#endif -- cgit v1.2.3