summaryrefslogtreecommitdiff
path: root/src/tests/tcpsocket.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2011-03-30 22:33:41 +0000
committerMike Buland <eichlan@xagasoft.com>2011-03-30 22:33:41 +0000
commit4b9289cfb260f4bcecaf23a810584ef6ef8e8501 (patch)
tree79136af08c7e42ba3322f0d73e9779e4354b318a /src/tests/tcpsocket.cpp
parentc7636dc954eddfe58f7959392602fbc9072d77e7 (diff)
downloadlibbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.gz
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.bz2
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.tar.xz
libbu++-4b9289cfb260f4bcecaf23a810584ef6ef8e8501.zip
Ok, string stuff is working much, much better, a load of new unit tests have
been added, and I deleted a whole slew of stupid old tests that I don't need.
Diffstat (limited to 'src/tests/tcpsocket.cpp')
-rw-r--r--src/tests/tcpsocket.cpp73
1 files changed, 0 insertions, 73 deletions
diff --git a/src/tests/tcpsocket.cpp b/src/tests/tcpsocket.cpp
deleted file mode 100644
index 89c015c..0000000
--- a/src/tests/tcpsocket.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#include <bu/tcpsocket.h>
9#include <bu/sio.h>
10
11#include <sys/time.h>
12#include <time.h>
13
14using namespace Bu;
15
16bool isUp()
17{
18 try
19 {
20 TcpSocket s("xagasoft.com", 9898, 1 );
21
22 char buf[5];
23 buf[s.read(buf, 2, 1, 0)] = '\0';
24
25 if( !strcmp( buf, "hi" ) )
26 return true;
27 else
28 return false;
29 }
30 catch(...)
31 {
32 return false;
33 }
34}
35
36int main()
37{
38 uint32_t uUp = 0;
39 uint32_t uDown = 0;
40 uint32_t uTotal = 0;
41 struct timeval tv;
42
43 for(;;)
44 {
45 gettimeofday( &tv, NULL );
46 time_t goal = ((tv.tv_sec/5)+1)*5;
47 tv.tv_sec = goal-tv.tv_sec;
48 tv.tv_usec = 0-tv.tv_usec;
49 if( tv.tv_usec < 0 )
50 {
51 tv.tv_sec--;
52 tv.tv_usec = 1000000+tv.tv_usec;
53 }
54 select( 0, NULL, NULL, NULL, &tv );
55 gettimeofday( &tv, NULL );
56 if( isUp() )
57 {
58 uUp++;
59 sio << "status: up ";
60 }
61 else
62 {
63 uDown++;
64 sio << "status: down ";
65 }
66 uTotal++;
67
68 sio << "(up=" << (uUp*5) << "s, down=" << (uDown*5) << ") up for "
69 << uUp*100/uTotal << "% of " << uTotal*5 << "s" << sio.nl
70 << sio.flush;
71 }
72}
73