From f896b0e207e0b656109ef0e9f721f27ce53a836e Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Thu, 28 Jun 2007 22:47:03 +0000 Subject: Client code is better, so is the socket, you can get addresses and other cool things from it. The plugger had yet another bugfix...plugger... --- src/client.cpp | 54 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) (limited to 'src/client.cpp') diff --git a/src/client.cpp b/src/client.cpp index 0e48285..63822ba 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -10,7 +10,8 @@ Bu::Client::Client( Bu::Socket *pSocket ) : pSocket( pSocket ), - pProto( NULL ) + pProto( NULL ), + nRBOffset( 0 ) { } @@ -103,3 +104,54 @@ void Bu::Client::write( const char *pData, int nBytes ) sWriteBuf.append( pData, nBytes ); } +void Bu::Client::write( int8_t nData ) +{ + sWriteBuf.append( (const char *)&nData, sizeof(nData) ); +} + +void Bu::Client::write( int16_t nData ) +{ + sWriteBuf.append( (const char *)&nData, sizeof(nData) ); +} + +void Bu::Client::write( int32_t nData ) +{ + sWriteBuf.append( (const char *)&nData, sizeof(nData) ); +} + +void Bu::Client::write( int64_t nData ) +{ + sWriteBuf.append( (const char *)&nData, sizeof(nData) ); +} + +void Bu::Client::read( char *pData, int nBytes ) +{ + memcpy( pData, sReadBuf.getStr()+nRBOffset, 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; +} + +const Bu::Socket *Bu::Client::getSocket() const +{ + return pSocket; +} + -- cgit v1.2.3