From 9031e2af7dd4e65ec70890ee78a7cf600d1b2cc5 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Sat, 16 Oct 2010 03:02:11 +0000 Subject: 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. --- src/tests/socket.cpp | 73 ----------------------------------------------- src/tests/socketblock.cpp | 10 +++---- src/tests/socketbreak.cpp | 10 +++---- src/tests/tcpsocket.cpp | 73 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 83 deletions(-) delete mode 100644 src/tests/socket.cpp create mode 100644 src/tests/tcpsocket.cpp (limited to 'src/tests') 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 @@ -/* - * Copyright (C) 2007-2010 Xagasoft, All rights reserved. - * - * This file is part of the libbu++ library and is released under the - * terms of the license contained in the file LICENSE. - */ - -#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; - } -} - diff --git a/src/tests/socketblock.cpp b/src/tests/socketblock.cpp index a1ea18d..793ef96 100644 --- a/src/tests/socketblock.cpp +++ b/src/tests/socketblock.cpp @@ -6,8 +6,8 @@ */ #include "bu/ito.h" -#include "bu/socket.h" -#include "bu/serversocket.h" +#include "bu/tcpsocket.h" +#include "bu/tcpserversocket.h" #include #include @@ -21,7 +21,7 @@ public: virtual void run() { - Bu::Socket c = s.accept( 45, 0 ); + Bu::TcpSocket c = s.accept( 45, 0 ); printf("TstServer: Accetped connection.\n"); fflush( stdout ); sleep( 1 ); @@ -35,7 +35,7 @@ public: c.close(); } - Bu::ServerSocket s; + Bu::TcpServerSocket s; }; int main() @@ -45,7 +45,7 @@ int main() ts.start(); printf("main: Connecting to server.\n"); fflush( stdout ); - Bu::Socket s( "localhost", 55678 ); + Bu::TcpSocket s( "localhost", 55678 ); printf("main: Sending 4 bytes.\n"); fflush( stdout ); s.write( "aoeu", 4 ); diff --git a/src/tests/socketbreak.cpp b/src/tests/socketbreak.cpp index 8339630..7d3c71a 100644 --- a/src/tests/socketbreak.cpp +++ b/src/tests/socketbreak.cpp @@ -5,17 +5,17 @@ * terms of the license contained in the file LICENSE. */ -#include "bu/serversocket.h" -#include "bu/socket.h" +#include "bu/tcpserversocket.h" +#include "bu/tcpsocket.h" #include int main() { - Bu::ServerSocket sSrv( 9987 ); + Bu::TcpServerSocket sSrv( 9987 ); - Bu::Socket sSend("localhost", 9987 ); + Bu::TcpSocket sSend("localhost", 9987 ); - Bu::Socket sRecv( sSrv.accept() ); + Bu::TcpSocket sRecv( sSrv.accept() ); printf("Connected sockets.\n"); diff --git a/src/tests/tcpsocket.cpp b/src/tests/tcpsocket.cpp new file mode 100644 index 0000000..30dd22f --- /dev/null +++ b/src/tests/tcpsocket.cpp @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2007-2010 Xagasoft, All rights reserved. + * + * This file is part of the libbu++ library and is released under the + * terms of the license contained in the file LICENSE. + */ + +#include +#include + +#include +#include + +using namespace Bu; + +bool isUp() +{ + try + { + TcpSocket 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