summaryrefslogtreecommitdiff
path: root/src/connection.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/connection.cpp')
-rw-r--r--src/connection.cpp37
1 files changed, 18 insertions, 19 deletions
diff --git a/src/connection.cpp b/src/connection.cpp
index 0e7f111..045ea17 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -196,7 +196,7 @@ bool Connection::open( const char *sAddr, int nPort )
196 return true; 196 return true;
197} 197}
198 198
199bool Connection::readInput() 199int Connection::readInput()
200{ 200{
201 char buffer[2048]; 201 char buffer[2048];
202 int nbytes; 202 int nbytes;
@@ -204,39 +204,33 @@ bool Connection::readInput()
204 204
205 for(;;) 205 for(;;)
206 { 206 {
207 memset( buffer, 0, 2048 ); 207 //memset( buffer, 0, 2048 );
208 208
209 nbytes = read( nSocket, buffer, 2048 ); 209 nbytes = read( nSocket, buffer, 2048 );
210 if (nbytes < 0) 210 if (nbytes < 0)
211 { 211 {
212 /* Read error. */ 212 /* Read error. */
213 //perror("readInput"); 213 //perror("readInput");
214 return false; 214 throw ConnectionException( excodeReadError, "Read error");
215 }
216 else if (nbytes == 0)
217 {
218 /* End-of-file. */
219 //perror("readInput");
220 return false;
221 } 215 }
222 else 216 else
223 { 217 {
224 nTotalRead += nbytes; 218 nTotalRead += nbytes;
225 appendInput( buffer, nbytes ); 219 appendInput( buffer, nbytes );
226 /* Data read. */ 220 /* Data read. */
227 if( nbytes < 2047 ) 221 if( nbytes < 2048 )
228 { 222 {
229 if( pProtocol != NULL && nTotalRead > 0 ) 223 break;
230 {
231 pProtocol->onNewData();
232 }
233
234 return true;
235 } 224 }
236 } 225 }
237 } 226 }
238 227
239 return true; 228 if( pProtocol != NULL && nTotalRead > 0 )
229 {
230 pProtocol->onNewData();
231 }
232
233 return nTotalRead;
240} 234}
241 235
242bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack ) 236bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack )
@@ -259,12 +253,17 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack
259 if( retval == -1 ) 253 if( retval == -1 )
260 { 254 {
261 // Oh my god!!! some kind of horrible problem!!!! 255 // Oh my god!!! some kind of horrible problem!!!!
256 throw ConnectionException( excodeBadReadError, "Bad Read error");
262 return false; 257 return false;
263 } 258 }
264 else if( retval ) 259 else if( retval )
265 { 260 {
266 // None of them have data, but the connection is still active. 261 // None of them have data, but the connection is still active.
267 return readInput(); 262 if( readInput() == 0 )
263 {
264 this->close();
265 throw ConnectionException( excodeConnectionClosed, "Connection closed");
266 }
268 } 267 }
269 else 268 else
270 { 269 {
@@ -283,7 +282,7 @@ void Connection::waitForInput( int nBytesIn, int nSec, int nUSec )
283 { 282 {
284 if( nSec == 0 && nUSec == 0 ) 283 if( nSec == 0 && nUSec == 0 )
285 { 284 {
286 throw ConnectionException("Socket Timeout"); 285 throw ConnectionException( excodeSocketTimeout, "Socket Timeout");
287 } 286 }
288 readInput( nSec, nUSec, &nSec, &nUSec ); 287 readInput( nSec, nUSec, &nSec, &nUSec );
289 rlen = getInputAmnt(); 288 rlen = getInputAmnt();