X-Git-Url: http://developer.intra2net.com/git/?p=libt2n;a=blobdiff_plain;f=test%2Ftimeout.cpp;h=509d88d73accd2657a1d13d0d000b31ec1638a09;hp=e194b85bfd17056d9bcf572219af78f6d08d3cc3;hb=19facd8558fe2e32ce843860b40631ebe03ff3cf;hpb=039e52da9b40d0e729360ff0a953dfbddf975b8a diff --git a/test/timeout.cpp b/test/timeout.cpp index e194b85..509d88d 100644 --- a/test/timeout.cpp +++ b/test/timeout.cpp @@ -1,9 +1,24 @@ -/*************************************************************************** - * Copyright (C) 2004 by Intra2net AG * - * info@intra2net.com * - * * - ***************************************************************************/ +/* +Copyright (C) 2004 by Intra2net AG +The software in this package is distributed under the GNU General +Public License version 2 (with a special exception described below). + +A copy of GNU General Public License (GPL) is included in this distribution, +in the file COPYING.GPL. + +As a special exception, if other files instantiate templates or use macros +or inline functions from this file, or you compile this file and link it +with other works to produce a work based on this file, this file +does not by itself cause the resulting work to be covered +by the GNU General Public License. + +However the source code for this file must still be made available +in accordance with section (3) of the GNU General Public License. + +This exception does not invalidate any other reasons why a work based +on this file might be covered by the GNU General Public License. +*/ #include #include #include @@ -195,7 +210,13 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -232,11 +253,18 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -274,24 +302,31 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); - // create a valid packet - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION << ';'; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; + // create a valid packet + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION << ';'; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; - packet_size_indicator psize=htonl(hello.str().size()); - std::string send_data(hello.str()); - send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator)); + packet_size_indicator psize=htonl(hello.str().size()); + std::string send_data(hello.str()); + send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator)); - ss.add_callback(new_connection,bind(&test_timeout::send_slow_raw_socket, boost::ref(*this), send_data,&ss, _1)); + ss.add_callback(new_connection,bind(&test_timeout::send_slow_raw_socket, boost::ref(*this), send_data,&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -329,19 +364,26 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION << ';'; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION << ';'; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; - ss.add_callback(new_connection,bind(&test_timeout::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + ss.add_callback(new_connection,bind(&test_timeout::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + + // max 10 sec + for (int i=0; i < 10; i++) + ss.fill_buffer(1000000); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // max 10 sec - for (int i=0; i < 10; i++) - ss.fill_buffer(1000000); // don't call atexit and stuff _exit(0); } @@ -386,34 +428,41 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); - ostringstream hello; - hello << "T2Nv" << PROTOCOL_VERSION << ';'; - int byteordercheck=1; - hello.write((char*)&byteordercheck,sizeof(byteordercheck)); - hello << ';'; + ostringstream hello; + hello << "T2Nv" << PROTOCOL_VERSION << ';'; + int byteordercheck=1; + hello.write((char*)&byteordercheck,sizeof(byteordercheck)); + hello << ';'; - ss.add_callback(new_connection,bind(&test_timeout::send_hello, boost::ref(*this), hello.str(),&ss, _1)); + ss.add_callback(new_connection,bind(&test_timeout::send_hello, boost::ref(*this), hello.str(),&ss, _1)); - // max 10 sec - for (int i=0; i < 10; i++) - { - ss.fill_buffer(1000000); + // max 10 sec + for (int i=0; i < 10; i++) + { + ss.fill_buffer(1000000); - string data; - unsigned int cid; + string data; + unsigned int cid; - if(ss.get_packet(data,cid)) - { - // create a valid packet & send - string response="abcdefghijklmnopqrstuvwxyz"; - packet_size_indicator psize=htonl(response.size()); - std::string send_data(response); - send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator)); - send_slow_raw_socket(send_data,&ss,cid); + if(ss.get_packet(data,cid)) + { + // create a valid packet & send + string response="abcdefghijklmnopqrstuvwxyz"; + packet_size_indicator psize=htonl(response.size()); + std::string send_data(response); + send_data.insert(0,(char*)&psize,sizeof(packet_size_indicator)); + send_slow_raw_socket(send_data,&ss,cid); + } } + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; } + // don't call atexit and stuff _exit(0); } @@ -458,10 +507,17 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + // bail out as soon as we get something + ss.fill_buffer(-1); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // bail out as soon as we get something - ss.fill_buffer(-1); // don't call atexit and stuff _exit(0); } @@ -508,10 +564,18 @@ class test_timeout : public TestFixture case 0: // child { - socket_server ss("./socket"); + try + { + socket_server ss("./socket"); + + // bail out as soon as we get something + ss.fill_buffer(-1); + ss.fill_buffer(-1); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } - // bail out as soon as we get something - ss.fill_buffer(-1); // don't call atexit and stuff _exit(0); } @@ -563,14 +627,20 @@ class test_timeout : public TestFixture case 0: // child { - // wait till server is up - sleep(1); + try + { + // wait till server is up + sleep(1); - socket_client_connection sc("./socket"); + socket_client_connection sc("./socket"); - // this is an evil hack to get access to real_write, don't ever do this in an app!!! - real_write_client_connection *rwc=(real_write_client_connection*)≻ - rwc->real_write(string(10000,'x')); + // this is an evil hack to get access to real_write, don't ever do this in an app!!! + real_write_client_connection *rwc=(real_write_client_connection*)≻ + rwc->real_write(string(10000,'x')); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -607,10 +677,16 @@ class test_timeout : public TestFixture case 0: // child { - socket_client_connection *sc=new socket_client_connection("./socket"); - sc->write(string(10000,'x')); - delete sc; - // socket is closed regularly + try + { + socket_client_connection *sc=new socket_client_connection("./socket"); + sc->write(string(10000,'x')); + // socket is closed regularly + delete sc; + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't run regular cleanup, otherwise cppunit stuff gets called _exit(0); @@ -654,11 +730,17 @@ class test_timeout : public TestFixture case 0: // child { - // wait till server is really up and waiting - sleep(2); + try + { + // wait till server is really up and waiting + sleep(2); - // connect with very tight timeout and only 1 retry - socket_client_connection sc("./socket",50,1); + // connect with very tight timeout and only 1 retry + socket_client_connection sc("./socket",50,1); + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't call atexit and stuff _exit(0); @@ -698,10 +780,16 @@ class test_timeout : public TestFixture case 0: // child { - socket_client_connection *sc=new socket_client_connection("./socket"); - sc->write(string(10000,'x')); - delete sc; - // socket is closed regularly + try + { + socket_client_connection *sc=new socket_client_connection("./socket"); + sc->write(string(10000,'x')); + delete sc; + // socket is closed regularly + } catch(...) + { + std::cerr << "exception in child. ignoring\n"; + } // don't run regular cleanup, otherwise cppunit stuff gets called _exit(0);