aboutsummaryrefslogtreecommitdiff
path: root/src/tests/socket.cpp
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2010-10-16 03:02:11 +0000
committerMike Buland <eichlan@xagasoft.com>2010-10-16 03:02:11 +0000
commit9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5 (patch)
tree17bc9d96b13d16d79385016c087321fc1267743f /src/tests/socket.cpp
parent93c028162318a00b9bd03fc4a48383f830cc529d (diff)
downloadlibbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.gz
libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.bz2
libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.tar.xz
libbu++-9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5.zip
Many, many changes. Documentation changes, renamed the socket class to
TcpSocket, fixed many other things, and finally removed ParamProc. Anything that needs it will now have to switch to OptParser.
Diffstat (limited to 'src/tests/socket.cpp')
-rw-r--r--src/tests/socket.cpp73
1 files changed, 0 insertions, 73 deletions
diff --git a/src/tests/socket.cpp b/src/tests/socket.cpp
deleted file mode 100644
index ba4e9b9..0000000
--- a/src/tests/socket.cpp
+++ /dev/null
@@ -1,73 +0,0 @@
1/*
2 * Copyright (C) 2007-2010 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/socket.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 Socket 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