aboutsummaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp54
1 files changed, 53 insertions, 1 deletions
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 @@
10 10
11Bu::Client::Client( Bu::Socket *pSocket ) : 11Bu::Client::Client( Bu::Socket *pSocket ) :
12 pSocket( pSocket ), 12 pSocket( pSocket ),
13 pProto( NULL ) 13 pProto( NULL ),
14 nRBOffset( 0 )
14{ 15{
15} 16}
16 17
@@ -103,3 +104,54 @@ void Bu::Client::write( const char *pData, int nBytes )
103 sWriteBuf.append( pData, nBytes ); 104 sWriteBuf.append( pData, nBytes );
104} 105}
105 106
107void Bu::Client::write( int8_t nData )
108{
109 sWriteBuf.append( (const char *)&nData, sizeof(nData) );
110}
111
112void Bu::Client::write( int16_t nData )
113{
114 sWriteBuf.append( (const char *)&nData, sizeof(nData) );
115}
116
117void Bu::Client::write( int32_t nData )
118{
119 sWriteBuf.append( (const char *)&nData, sizeof(nData) );
120}
121
122void Bu::Client::write( int64_t nData )
123{
124 sWriteBuf.append( (const char *)&nData, sizeof(nData) );
125}
126
127void Bu::Client::read( char *pData, int nBytes )
128{
129 memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes );
130 nRBOffset += nBytes;
131 if( sReadBuf.getSize()-nRBOffset == 0 )
132 {
133 sReadBuf.clear();
134 nRBOffset = 0;
135 }
136 // This is an experimental threshold, maybe I'll make this configurable
137 // later on.
138 else if(
139 (sReadBuf.getSize() >= 1024 && nRBOffset >= sReadBuf.getSize()/2) ||
140 (nRBOffset >= sReadBuf.getSize()/4)
141 )
142 {
143 sReadBuf.trimFront( nRBOffset );
144 nRBOffset = 0;
145 }
146}
147
148long Bu::Client::getInputSize()
149{
150 return sReadBuf.getSize()-nRBOffset;
151}
152
153const Bu::Socket *Bu::Client::getSocket() const
154{
155 return pSocket;
156}
157