diff options
author | Mike Buland <eichlan@xagasoft.com> | 2009-12-16 20:10:58 +0000 |
---|---|---|
committer | Mike Buland <eichlan@xagasoft.com> | 2009-12-16 20:10:58 +0000 |
commit | f72c6e4b97afeb69d9ea4d743c0c302d647ea424 (patch) | |
tree | 48d9d94db520455324e902759e887c0d98de976a /src/tests/socket.cpp | |
parent | 5eba456f0147b12a6247cd7aa41e55d121962358 (diff) | |
download | libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.gz libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.bz2 libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.tar.xz libbu++-f72c6e4b97afeb69d9ea4d743c0c302d647ea424.zip |
The new signal/slots system is in place, and works from 0-5 parameters right
now, I'll probably add more later on...
I've also started on the replacement for ParamProc, OptParser. It should do
everything that ParamProc did, only with less code, and much better.
Diffstat (limited to 'src/tests/socket.cpp')
-rw-r--r-- | src/tests/socket.cpp | 66 |
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 | |||
7 | using namespace Bu; | ||
8 | |||
9 | bool 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 | |||
29 | int 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 | |||