From ec8ed8b4b44c7b039e87faaa50bb4d503393d336 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Fri, 29 Jun 2007 00:48:32 +0000 Subject: A few changes here and there, mainly related to getting the new Server system working in optimal condition... --- src/client.cpp | 35 ++++++++++++++++++++++++++++++++--- src/client.h | 11 +++++++++-- src/fstring.cpp | 2 +- src/fstring.h | 2 +- src/membuf.cpp | 11 +++++++++++ src/membuf.h | 3 +++ 6 files changed, 57 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 2f293b7..8077b3d 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -99,9 +99,9 @@ bool Bu::Client::isOpen() return pSocket->isOpen(); } -void Bu::Client::write( const char *pData, int nBytes ) +void Bu::Client::write( const void *pData, int nBytes ) { - sWriteBuf.append( pData, nBytes ); + sWriteBuf.append( (const char *)pData, nBytes ); } void Bu::Client::write( int8_t nData ) @@ -144,7 +144,7 @@ void Bu::Client::write( uint64_t nData ) sWriteBuf.append( (const char *)&nData, sizeof(nData) ); } -void Bu::Client::read( char *pData, int nBytes ) +void Bu::Client::read( void *pData, int nBytes ) { memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes ); nRBOffset += nBytes; @@ -165,6 +165,31 @@ void Bu::Client::read( char *pData, int nBytes ) } } +void Bu::Client::peek( void *pData, int nBytes ) +{ + memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes ); +} + +void Bu::Client::seek( int nBytes ) +{ + nRBOffset += nBytes; + if( sReadBuf.getSize()-nRBOffset == 0 ) + { + sReadBuf.clear(); + nRBOffset = 0; + } + // This is an experimental threshold, maybe I'll make this configurable + // later on. + else if( + (sReadBuf.getSize() >= 1024 && nRBOffset >= sReadBuf.getSize()/2) || + (nRBOffset >= sReadBuf.getSize()/4) + ) + { + sReadBuf.trimFront( nRBOffset ); + nRBOffset = 0; + } +} + long Bu::Client::getInputSize() { return sReadBuf.getSize()-nRBOffset; @@ -175,3 +200,7 @@ const Bu::Socket *Bu::Client::getSocket() const return pSocket; } +void Bu::Client::disconnect() +{ +} + diff --git a/src/client.h b/src/client.h index 1253dcd..5947521 100644 --- a/src/client.h +++ b/src/client.h @@ -24,7 +24,7 @@ namespace Bu Bu::FString &getInput(); Bu::FString &getOutput(); - void write( const char *pData, int nBytes ); + void write( const void *pData, int nBytes ); void write( int8_t nData ); void write( int16_t nData ); void write( int32_t nData ); @@ -33,7 +33,9 @@ namespace Bu void write( uint16_t nData ); void write( uint32_t nData ); void write( uint64_t nData ); - void read( char *pData, int nBytes ); + void read( void *pData, int nBytes ); + void peek( void *pData, int nBytes ); + void seek( int nBytes ); long getInputSize(); void setProtocol( Protocol *pProto ); @@ -44,6 +46,11 @@ namespace Bu const Bu::Socket *getSocket() const; + /** + *@todo Make this not suck. + */ + void disconnect(); + private: Bu::Socket *pSocket; Bu::Protocol *pProto; diff --git a/src/fstring.cpp b/src/fstring.cpp index 0b5a970..f71d6c1 100644 --- a/src/fstring.cpp +++ b/src/fstring.cpp @@ -12,7 +12,7 @@ template<> bool Bu::__cmpHashKeys( return a == b; } -std::ostream& operator<< (std::ostream &os, Bu::FString &val ) +std::basic_ostream& operator<< (std::basic_ostream &os, const Bu::FString &val ) { os.write( val.getStr(), val.getSize() ); return os; diff --git a/src/fstring.h b/src/fstring.h index 1f21b5f..f06c362 100644 --- a/src/fstring.h +++ b/src/fstring.h @@ -897,6 +897,6 @@ namespace Bu } #include -std::ostream& operator<< (std::ostream &os, Bu::FString &val ); +std::basic_ostream& operator<< (std::basic_ostream &os, const Bu::FString &val ); #endif diff --git a/src/membuf.cpp b/src/membuf.cpp index 3c394b0..45ff5bd 100644 --- a/src/membuf.cpp +++ b/src/membuf.cpp @@ -7,6 +7,12 @@ Bu::MemBuf::MemBuf() : { } +Bu::MemBuf::MemBuf( const Bu::FString &str ) : + sBuf( str ), + nPos( 0 ) +{ +} + Bu::MemBuf::~MemBuf() { } @@ -107,3 +113,8 @@ void Bu::MemBuf::setBlocking( bool bBlocking ) { } +Bu::FString &Bu::MemBuf::getString() +{ + return sBuf; +} + diff --git a/src/membuf.h b/src/membuf.h index b82f943..8f53d4b 100644 --- a/src/membuf.h +++ b/src/membuf.h @@ -15,6 +15,7 @@ namespace Bu { public: MemBuf(); + MemBuf( const Bu::FString &str ); virtual ~MemBuf(); virtual void close(); @@ -41,6 +42,8 @@ namespace Bu virtual bool isBlocking(); virtual void setBlocking( bool bBlocking=true ); + Bu::FString &getString(); + private: Bu::FString sBuf; long nPos; -- cgit v1.2.3