From f72c6e4b97afeb69d9ea4d743c0c302d647ea424 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Wed, 16 Dec 2009 20:10:58 +0000 Subject: 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. --- src/tests/socket.cpp | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 src/tests/socket.cpp (limited to 'src/tests/socket.cpp') 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 @@ +#include +#include + +#include +#include + +using namespace Bu; + +bool isUp() +{ + try + { + Socket s("xagasoft.com", 9898, 1 ); + + char buf[5]; + buf[s.read(buf, 2, 1, 0)] = '\0'; + + if( !strcmp( buf, "hi" ) ) + return true; + else + return false; + } + catch(...) + { + return false; + } +} + +int main() +{ + uint32_t uUp = 0; + uint32_t uDown = 0; + uint32_t uTotal = 0; + struct timeval tv; + + for(;;) + { + gettimeofday( &tv, NULL ); + time_t goal = ((tv.tv_sec/5)+1)*5; + tv.tv_sec = goal-tv.tv_sec; + tv.tv_usec = 0-tv.tv_usec; + if( tv.tv_usec < 0 ) + { + tv.tv_sec--; + tv.tv_usec = 1000000+tv.tv_usec; + } + select( 0, NULL, NULL, NULL, &tv ); + gettimeofday( &tv, NULL ); + if( isUp() ) + { + uUp++; + sio << "status: up "; + } + else + { + uDown++; + sio << "status: down "; + } + uTotal++; + + sio << "(up=" << (uUp*5) << "s, down=" << (uDown*5) << ") up for " + << uUp*100/uTotal << "% of " << uTotal*5 << "s" << sio.nl + << sio.flush; + } +} + -- cgit v1.2.3