diff options
author | Mike Buland <eichlan@xagasoft.com> | 2006-08-25 22:44:09 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2006-08-25 22:44:09 +0000 |
commit | 5ff43b1a4abd06a47a996b817846567f8d1bc615 (patch) | |
tree | 59d13dad781bf3f285c337429128fb241007ab3d /src | |
parent | e1f398363812115611d20c0c803802c78ed65974 (diff) | |
download | libbu++-5ff43b1a4abd06a47a996b817846567f8d1bc615.tar.gz libbu++-5ff43b1a4abd06a47a996b817846567f8d1bc615.tar.bz2 libbu++-5ff43b1a4abd06a47a996b817846567f8d1bc615.tar.xz libbu++-5ff43b1a4abd06a47a996b817846567f8d1bc615.zip |
Fixed more stuff in the connection class. Yay.
Diffstat (limited to '')
-rw-r--r-- | src/connection.cpp | 36 | ||||
-rw-r--r-- | src/test/clistress/main.cpp | 6 | ||||
-rw-r--r-- | src/test/srvstress/main.cpp | 4 |
3 files changed, 38 insertions, 8 deletions
diff --git a/src/connection.cpp b/src/connection.cpp index c68c519..3b90329 100644 --- a/src/connection.cpp +++ b/src/connection.cpp | |||
@@ -6,6 +6,7 @@ | |||
6 | #include <unistd.h> | 6 | #include <unistd.h> |
7 | #include <sys/types.h> | 7 | #include <sys/types.h> |
8 | #include <sys/socket.h> | 8 | #include <sys/socket.h> |
9 | #include <sys/time.h> | ||
9 | #include <netinet/in.h> | 10 | #include <netinet/in.h> |
10 | #include <netdb.h> | 11 | #include <netdb.h> |
11 | #include <arpa/inet.h> | 12 | #include <arpa/inet.h> |
@@ -238,20 +239,21 @@ int Connection::readInput() | |||
238 | bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack ) | 239 | bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack ) |
239 | { | 240 | { |
240 | fd_set rfds; | 241 | fd_set rfds; |
241 | struct timeval tv; | 242 | struct timeval tv, start, end; |
243 | struct timezone tz; | ||
242 | int retval; | 244 | int retval; |
243 | 245 | ||
246 | gettimeofday( &start, &tz ); | ||
247 | |||
244 | FD_ZERO(&rfds); | 248 | FD_ZERO(&rfds); |
245 | FD_SET(nSocket, &rfds); | 249 | FD_SET(nSocket, &rfds); |
246 | 250 | ||
247 | tv.tv_sec = nSec; | 251 | tv.tv_sec = nSec; |
248 | tv.tv_usec = nUSec; | 252 | tv.tv_usec = nUSec; |
249 | 253 | ||
254 | //printf("Starting at %d %d\n", nSec, nUSec ); | ||
250 | retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); | 255 | retval = select( nSocket+1, &rfds, NULL, NULL, &tv ); |
251 | 256 | ||
252 | if( pnSecBack ) (*pnSecBack) = tv.tv_sec; | ||
253 | if( pnUSecBack ) (*pnUSecBack) = tv.tv_usec; | ||
254 | |||
255 | if( retval == -1 ) | 257 | if( retval == -1 ) |
256 | { | 258 | { |
257 | // Oh my god!!! some kind of horrible problem!!!! | 259 | // Oh my god!!! some kind of horrible problem!!!! |
@@ -260,7 +262,7 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack | |||
260 | } | 262 | } |
261 | else if( retval ) | 263 | else if( retval ) |
262 | { | 264 | { |
263 | printf("retval=%d, nSocket=%d,%d, sec=%d, usec=%d\n", retval, nSocket, FD_ISSET( nSocket, &rfds ), tv.tv_sec, tv.tv_usec ); | 265 | //printf("retval=%d, nSocket=%d,%d, sec=%d, usec=%d\n", retval, nSocket, FD_ISSET( nSocket, &rfds ), tv.tv_sec, tv.tv_usec ); |
264 | // None of them have data, but the connection is still active. | 266 | // None of them have data, but the connection is still active. |
265 | if( readInput() == 0 ) | 267 | if( readInput() == 0 ) |
266 | { | 268 | { |
@@ -268,10 +270,32 @@ bool Connection::readInput( int nSec, int nUSec, int *pnSecBack, int *pnUSecBack | |||
268 | throw ConnectionException( excodeConnectionClosed, "Connection closed"); | 270 | throw ConnectionException( excodeConnectionClosed, "Connection closed"); |
269 | } | 271 | } |
270 | } | 272 | } |
273 | |||
274 | gettimeofday( &end, &tz ); | ||
275 | |||
276 | int st, ust; | ||
277 | st = nSec - ( end.tv_sec - start.tv_sec ); | ||
278 | if( ( end.tv_usec - start.tv_usec ) > nUSec ) | ||
279 | { | ||
280 | (st)--; | ||
281 | ust = 1000000 - (end.tv_usec - start.tv_usec); | ||
282 | } | ||
271 | else | 283 | else |
272 | { | 284 | { |
273 | return true; | 285 | ust = nUSec - (end.tv_usec - start.tv_usec); |
274 | } | 286 | } |
287 | |||
288 | if( st < 0 ) | ||
289 | { | ||
290 | st = ust = 0; | ||
291 | } | ||
292 | |||
293 | *pnSecBack = st; | ||
294 | *pnUSecBack = ust; | ||
295 | |||
296 | //printf("New time: %d %d\n", *pnSecBack, *pnUSecBack ); | ||
297 | |||
298 | return true; | ||
275 | } | 299 | } |
276 | 300 | ||
277 | void Connection::waitForInput( int nBytesIn, int nSec, int nUSec ) | 301 | void Connection::waitForInput( int nBytesIn, int nSec, int nUSec ) |
diff --git a/src/test/clistress/main.cpp b/src/test/clistress/main.cpp index 0869945..6b0ac66 100644 --- a/src/test/clistress/main.cpp +++ b/src/test/clistress/main.cpp | |||
@@ -6,10 +6,12 @@ int main() | |||
6 | 6 | ||
7 | c.open("localhost", 4001 ); | 7 | c.open("localhost", 4001 ); |
8 | 8 | ||
9 | c.appendOutput("d"); | 9 | c.appendOutput("w"); |
10 | c.writeOutput(); | 10 | c.writeOutput(); |
11 | 11 | ||
12 | c.waitForInput( 5, 40, 0 ); | 12 | c.waitForInput( 6, 5, 0 ); |
13 | |||
14 | printf("read: %s\n", c.getInput() ); | ||
13 | 15 | ||
14 | c.close(); | 16 | c.close(); |
15 | 17 | ||
diff --git a/src/test/srvstress/main.cpp b/src/test/srvstress/main.cpp index c7795e4..7fe7657 100644 --- a/src/test/srvstress/main.cpp +++ b/src/test/srvstress/main.cpp | |||
@@ -13,6 +13,10 @@ public: | |||
13 | case 'd': | 13 | case 'd': |
14 | throw "Hello"; | 14 | throw "Hello"; |
15 | break; | 15 | break; |
16 | |||
17 | case 'w': | ||
18 | getConnection()->appendOutput("Hello"); | ||
19 | break; | ||
16 | }; | 20 | }; |
17 | 21 | ||
18 | return true; | 22 | return true; |