summaryrefslogtreecommitdiff
path: root/src/tests/socket.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tests/socket.cpp')
-rw-r--r--src/tests/socket.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/src/tests/socket.cpp b/src/tests/socket.cpp
new file mode 100644
index 0000000..1cf63e4
--- /dev/null
+++ b/src/tests/socket.cpp
@@ -0,0 +1,66 @@
1#include <bu/socket.h>
2#include <bu/sio.h>
3
4#include <sys/time.h>
5#include <time.h>
6
7using namespace Bu;
8
9bool isUp()
10{
11 try
12 {
13 Socket s("xagasoft.com", 9898, 1 );
14
15 char buf[5];
16 buf[s.read(buf, 2, 1, 0)] = '\0';
17
18 if( !strcmp( buf, "hi" ) )
19 return true;
20 else
21 return false;
22 }
23 catch(...)
24 {
25 return false;
26 }
27}
28
29int main()
30{
31 uint32_t uUp = 0;
32 uint32_t uDown = 0;
33 uint32_t uTotal = 0;
34 struct timeval tv;
35
36 for(;;)
37 {
38 gettimeofday( &tv, NULL );
39 time_t goal = ((tv.tv_sec/5)+1)*5;
40 tv.tv_sec = goal-tv.tv_sec;
41 tv.tv_usec = 0-tv.tv_usec;
42 if( tv.tv_usec < 0 )
43 {
44 tv.tv_sec--;
45 tv.tv_usec = 1000000+tv.tv_usec;
46 }
47 select( 0, NULL, NULL, NULL, &tv );
48 gettimeofday( &tv, NULL );
49 if( isUp() )
50 {
51 uUp++;
52 sio << "status: up ";
53 }
54 else
55 {
56 uDown++;
57 sio << "status: down ";
58 }
59 uTotal++;
60
61 sio << "(up=" << (uUp*5) << "s, down=" << (uDown*5) << ") up for "
62 << uUp*100/uTotal << "% of " << uTotal*5 << "s" << sio.nl
63 << sio.flush;
64 }
65}
66