aboutsummaryrefslogtreecommitdiff
path: root/src/client.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/client.cpp')
-rw-r--r--src/client.cpp96
1 files changed, 28 insertions, 68 deletions
diff --git a/src/client.cpp b/src/client.cpp
index 95008f9..88eb49d 100644
--- a/src/client.cpp
+++ b/src/client.cpp
@@ -20,7 +20,6 @@ Bu::Client::Client( Bu::Socket *pSocket, class Bu::ClientLinkFactory *pfLink ) :
20 pTopStream( pSocket ), 20 pTopStream( pSocket ),
21 pSocket( pSocket ), 21 pSocket( pSocket ),
22 pProto( NULL ), 22 pProto( NULL ),
23 nRBOffset( 0 ),
24 bWantsDisconnect( false ), 23 bWantsDisconnect( false ),
25 pfLink( pfLink ) 24 pfLink( pfLink )
26{ 25{
@@ -54,7 +53,7 @@ void Bu::Client::processInput()
54 else 53 else
55 { 54 {
56 nTotal += nRead; 55 nTotal += nRead;
57 sReadBuf.append( buf, nRead ); 56 qbRead.write( buf, nRead );
58 if( !pTopStream->canRead() ) 57 if( !pTopStream->canRead() )
59 break; 58 break;
60 } 59 }
@@ -81,13 +80,14 @@ void Bu::Client::processInput()
81 80
82void Bu::Client::processOutput() 81void Bu::Client::processOutput()
83{ 82{
84 if( sWriteBuf.getSize() > 0 ) 83 if( qbWrite.getSize() > 0 )
85 { 84 {
86 int nAmnt = (sWriteBuf.getSize()<2048)?(sWriteBuf.getSize()):(2048); 85 int nAmnt = RBS;
87 int nReal = pTopStream->write( sWriteBuf.getStr(), nAmnt ); 86 char *buf = new char[nAmnt];
87 nAmnt = qbWrite.peek( buf, nAmnt );
88 int nReal = pTopStream->write( buf, nAmnt );
89 qbWrite.seek( nReal );
88 pTopStream->flush(); 90 pTopStream->flush();
89 sWriteBuf.trimFront( nReal );
90 //sWriteBuf.clear();
91 } 91 }
92} 92}
93 93
@@ -106,7 +106,7 @@ void Bu::Client::clearProtocol()
106{ 106{
107 pProto = NULL; 107 pProto = NULL;
108} 108}
109 109/*
110Bu::FString &Bu::Client::getInput() 110Bu::FString &Bu::Client::getInput()
111{ 111{
112 return sReadBuf; 112 return sReadBuf;
@@ -116,6 +116,7 @@ Bu::FString &Bu::Client::getOutput()
116{ 116{
117 return sWriteBuf; 117 return sWriteBuf;
118} 118}
119*/
119 120
120bool Bu::Client::isOpen() 121bool Bu::Client::isOpen()
121{ 122{
@@ -125,118 +126,77 @@ bool Bu::Client::isOpen()
125 126
126void Bu::Client::write( const Bu::FString &sData ) 127void Bu::Client::write( const Bu::FString &sData )
127{ 128{
128 sWriteBuf += sData; 129 qbWrite.write( sData.getStr(), sData.getSize() );
129} 130}
130 131
131void Bu::Client::write( const void *pData, int nBytes ) 132void Bu::Client::write( const void *pData, int nBytes )
132{ 133{
133 sWriteBuf.append( (const char *)pData, nBytes ); 134 qbWrite.write( pData, nBytes );
134} 135}
135 136
136void Bu::Client::write( int8_t nData ) 137void Bu::Client::write( int8_t nData )
137{ 138{
138 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 139 qbWrite.write( (const char *)&nData, sizeof(nData) );
139} 140}
140 141
141void Bu::Client::write( int16_t nData ) 142void Bu::Client::write( int16_t nData )
142{ 143{
143 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 144 qbWrite.write( (const char *)&nData, sizeof(nData) );
144} 145}
145 146
146void Bu::Client::write( int32_t nData ) 147void Bu::Client::write( int32_t nData )
147{ 148{
148 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 149 qbWrite.write( (const char *)&nData, sizeof(nData) );
149} 150}
150 151
151void Bu::Client::write( int64_t nData ) 152void Bu::Client::write( int64_t nData )
152{ 153{
153 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 154 qbWrite.write( (const char *)&nData, sizeof(nData) );
154} 155}
155 156
156void Bu::Client::write( uint8_t nData ) 157void Bu::Client::write( uint8_t nData )
157{ 158{
158 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 159 qbWrite.write( (const char *)&nData, sizeof(nData) );
159} 160}
160 161
161void Bu::Client::write( uint16_t nData ) 162void Bu::Client::write( uint16_t nData )
162{ 163{
163 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 164 qbWrite.write( (const char *)&nData, sizeof(nData) );
164} 165}
165 166
166void Bu::Client::write( uint32_t nData ) 167void Bu::Client::write( uint32_t nData )
167{ 168{
168 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 169 qbWrite.write( (const char *)&nData, sizeof(nData) );
169} 170}
170 171
171void Bu::Client::write( uint64_t nData ) 172void Bu::Client::write( uint64_t nData )
172{ 173{
173 sWriteBuf.append( (const char *)&nData, sizeof(nData) ); 174 qbWrite.write( (const char *)&nData, sizeof(nData) );
174} 175}
175 176
176int Bu::Client::read( void *pData, int nBytes ) 177int Bu::Client::read( void *pData, int nBytes )
177{ 178{
178 if( nBytes > sReadBuf.getSize()-nRBOffset ) 179 return qbRead.read( pData, nBytes );
179 {
180 nBytes = sReadBuf.getSize()-nRBOffset;
181 if( nBytes <= 0 )
182 return 0;
183 }
184 memcpy( pData, sReadBuf.getStr()+nRBOffset, nBytes );
185 nRBOffset += nBytes;
186 if( sReadBuf.getSize()-nRBOffset == 0 )
187 {
188 sReadBuf.clear();
189 nRBOffset = 0;
190 }
191 // This is an experimental threshold, maybe I'll make this configurable
192 // later on.
193 else if(
194 (sReadBuf.getSize() >= 1024 && nRBOffset >= sReadBuf.getSize()/2) ||
195 (nRBOffset >= sReadBuf.getSize()/4)
196 )
197 {
198 sReadBuf.trimFront( nRBOffset );
199 nRBOffset = 0;
200 }
201
202 return nBytes;
203} 180}
204 181
205int Bu::Client::peek( void *pData, int nBytes, int nOffset ) 182int Bu::Client::peek( void *pData, int nBytes, int nOffset )
206{ 183{
207 if( nBytes+nOffset > sReadBuf.getSize()-nRBOffset ) 184 return qbRead.peek( pData, nBytes, nOffset );
208 {
209 nBytes = sReadBuf.getSize()-nRBOffset-nOffset;
210 if( nBytes <= 0 )
211 return 0;
212 }
213 memcpy( pData, sReadBuf.getStr()+nRBOffset+nOffset, nBytes );
214 return nBytes;
215} 185}
216 186
217void Bu::Client::seek( int nBytes ) 187void Bu::Client::seek( int nBytes )
218{ 188{
219 nRBOffset += nBytes; 189 return qbRead.seek( nBytes );
220 if( sReadBuf.getSize()-nRBOffset == 0 )
221 {
222 sReadBuf.clear();
223 nRBOffset = 0;
224 }
225 // This is an experimental threshold, maybe I'll make this configurable
226 // later on.
227 else if(
228 (sReadBuf.getSize() >= 1024 && nRBOffset >= sReadBuf.getSize()/2) ||
229 (nRBOffset >= sReadBuf.getSize()/4)
230 )
231 {
232 sReadBuf.trimFront( nRBOffset );
233 nRBOffset = 0;
234 }
235} 190}
236 191
237long Bu::Client::getInputSize() 192long Bu::Client::getInputSize()
238{ 193{
239 return sReadBuf.getSize()-nRBOffset; 194 return qbRead.getSize();
195}
196
197long Bu::Client::getOutputSize()
198{
199 return qbWrite.getSize();
240} 200}
241 201
242const Bu::Socket *Bu::Client::getSocket() const 202const Bu::Socket *Bu::Client::getSocket() const