libt2n: (tomj) added exception handling to every child after fork(). This is needed...
[libt2n] / test / reconnect.cpp
index 394ba25..6474b51 100644 (file)
@@ -87,30 +87,36 @@ class test_reconnect : public TestFixture
             case 0:
             // child
             {
-                socket_server ss("./socket");
-
-                time_t t0 = time(NULL);
-
-                // max 10 sec
-                while (time(NULL) < t0 + 10 )
+                try
                 {
-                    ss.fill_buffer(1000000);
+                    socket_server ss("./socket");
 
-                    string data;
-                    unsigned int cid;
+                    time_t t0 = time(NULL);
 
-                    if(ss.get_packet(data,cid))
+                    // max 10 sec
+                    while (time(NULL) < t0 + 10 )
                     {
-                        server_connection* con=ss.get_connection(cid);
+                        ss.fill_buffer(1000000);
+
+                        string data;
+                        unsigned int cid;
+
+                        if(ss.get_packet(data,cid))
+                        {
+                            server_connection* con=ss.get_connection(cid);
 
-                        if (data=="QUIT")
-                            break;
+                            if (data=="QUIT")
+                                break;
 
-                        if (data=="x")
-                            con->write(string().insert(0,100,'X'));
-                        else
-                            con->write(string().insert(0,100,'Y'));
+                            if (data=="x")
+                                con->write(string().insert(0,100,'X'));
+                            else
+                                con->write(string().insert(0,100,'Y'));
+                        }
                     }
+                } catch(...)
+                {
+                    std::cerr << "exception in child. ignoring\n";
                 }
 
                 // don't call atexit and stuff
@@ -158,30 +164,36 @@ class test_reconnect : public TestFixture
             case 0:
             // child
             {
-                socket_server ss("./socket");
-
-                time_t t0 = time(NULL);
-
-                // max 10 sec
-                while (time(NULL) < t0 + 10 )
+                try
                 {
-                    ss.fill_buffer(1000000);
+                    socket_server ss("./socket");
 
-                    string data;
-                    unsigned int cid;
+                    time_t t0 = time(NULL);
 
-                    if(ss.get_packet(data,cid))
+                    // max 10 sec
+                    while (time(NULL) < t0 + 10 )
                     {
-                        server_connection* con=ss.get_connection(cid);
+                        ss.fill_buffer(1000000);
 
-                        if (data=="QUIT")
-                            break;
+                        string data;
+                        unsigned int cid;
 
-                        if (data=="x")
-                            con->write(string().insert(0,100,'X'));
-                        else
-                            con->write(string().insert(0,100,'Y'));
+                        if(ss.get_packet(data,cid))
+                        {
+                            server_connection* con=ss.get_connection(cid);
+
+                            if (data=="QUIT")
+                                break;
+
+                            if (data=="x")
+                                con->write(string().insert(0,100,'X'));
+                            else
+                                con->write(string().insert(0,100,'Y'));
+                        }
                     }
+                } catch(...)
+                {
+                    std::cerr << "exception in child. ignoring\n";
                 }
 
                 // don't call atexit and stuff
@@ -234,28 +246,34 @@ class test_reconnect : public TestFixture
             case 0:
             // child
             {
-                socket_server ss("./socket");
-
-                time_t t0 = time(NULL);
-
-                // max 10 sec
-                while (time(NULL) < t0 + 10 )
+                try
                 {
-                    ss.fill_buffer(1000000);
+                    socket_server ss("./socket");
 
-                    string data;
-                    unsigned int cid;
+                    time_t t0 = time(NULL);
 
-                    if(ss.get_packet(data,cid))
+                    // max 10 sec
+                    while (time(NULL) < t0 + 10 )
                     {
-                        server_connection* con=ss.get_connection(cid);
+                        ss.fill_buffer(1000000);
+
+                        string data;
+                        unsigned int cid;
+
+                        if(ss.get_packet(data,cid))
+                        {
+                            server_connection* con=ss.get_connection(cid);
 
-                        if (data=="QUIT")
-                            break;
+                            if (data=="QUIT")
+                                break;
 
-                        if (data=="x")
-                            con->write(string().insert(0,100,'X'));
+                            if (data=="x")
+                                con->write(string().insert(0,100,'X'));
+                        }
                     }
+                } catch(...)
+                {
+                    std::cerr << "exception in child. ignoring\n";
                 }
 
                 // don't call atexit and stuff
@@ -302,31 +320,37 @@ class test_reconnect : public TestFixture
             case 0:
             // child
             {
-                socket_server ss("./socket");
-
-                time_t t0 = time(NULL);
-
-                // max 10 sec
-                while (time(NULL) < t0 + 10 )
+                try
                 {
-                    ss.fill_buffer(1000000);
+                    socket_server ss("./socket");
 
-                    string data;
-                    unsigned int cid;
+                    time_t t0 = time(NULL);
 
-                    if(ss.get_packet(data,cid))
+                    // max 10 sec
+                    while (time(NULL) < t0 + 10 )
                     {
-                        server_connection* con=ss.get_connection(cid);
+                        ss.fill_buffer(1000000);
 
-                        if (data=="QUIT")
-                            break;
+                        string data;
+                        unsigned int cid;
 
-                        if (data=="x")
+                        if(ss.get_packet(data,cid))
                         {
-                            for (int i=0; i<packets; i++)
-                                con->write(string().insert(0,100,'X'));
+                            server_connection* con=ss.get_connection(cid);
+
+                            if (data=="QUIT")
+                                break;
+
+                            if (data=="x")
+                            {
+                                for (int i=0; i<packets; i++)
+                                    con->write(string().insert(0,100,'X'));
+                            }
                         }
                     }
+                } catch(...)
+                {
+                    std::cerr << "exception in child. ignoring\n";
                 }
 
                 // don't call atexit and stuff
@@ -388,31 +412,37 @@ class test_reconnect : public TestFixture
             case 0:
             // child
             {
-                socket_server ss("./socket");
-
-                time_t t0 = time(NULL);
-
-                // max 10 sec
-                while (time(NULL) < t0 + 10 )
+                try
                 {
-                    ss.fill_buffer(1000000);
+                    socket_server ss("./socket");
 
-                    string data;
-                    unsigned int cid;
+                    time_t t0 = time(NULL);
 
-                    if(ss.get_packet(data,cid))
+                    // max 10 sec
+                    while (time(NULL) < t0 + 10 )
                     {
-                        server_connection* con=ss.get_connection(cid);
+                        ss.fill_buffer(1000000);
 
-                        if (data=="QUIT")
-                            break;
+                        string data;
+                        unsigned int cid;
 
-                        if (data=="x")
+                        if(ss.get_packet(data,cid))
                         {
-                            con->write(string().insert(0,100,'X'));
-                            send_raw_socket("aaaab",&ss,cid);
+                            server_connection* con=ss.get_connection(cid);
+
+                            if (data=="QUIT")
+                                break;
+
+                            if (data=="x")
+                            {
+                                con->write(string().insert(0,100,'X'));
+                                send_raw_socket("aaaab",&ss,cid);
+                            }
                         }
                     }
+                } catch(...)
+                {
+                    std::cerr << "exception in child. ignoring\n";
                 }
 
                 // don't call atexit and stuff
@@ -464,42 +494,48 @@ class test_reconnect : public TestFixture
             case 0:
             // child
             {
-                socket_server ss("./socket");
-
-                time_t t0 = time(NULL);
-
-                // max 10 sec
-                while (time(NULL) < t0 + 10 )
+                try
                 {
-                    ss.fill_buffer(1000000);
+                    socket_server ss("./socket");
 
-                    string data;
-                    unsigned int cid;
+                    time_t t0 = time(NULL);
 
-                    if(ss.get_packet(data,cid))
+                    // max 10 sec
+                    while (time(NULL) < t0 + 10 )
                     {
-                        server_connection* con=ss.get_connection(cid);
+                        ss.fill_buffer(1000000);
 
-                        if (data=="QUIT")
-                            break;
+                        string data;
+                        unsigned int cid;
 
-                        if (data=="x")
+                        if(ss.get_packet(data,cid))
                         {
-                            con->write(string().insert(0,100,'X'));
+                            server_connection* con=ss.get_connection(cid);
+
+                            if (data=="QUIT")
+                                break;
 
-                            string blob=string().insert(0,100,'Y');
+                            if (data=="x")
+                            {
+                                con->write(string().insert(0,100,'X'));
+
+                                string blob=string().insert(0,100,'Y');
 
-                            // one byte will be missing...
-                            int size=blob.size()+1;
-                            char sizetransfer[sizeof(int)+1];
-                            memcpy(sizetransfer,(void*)&size,sizeof(int));
-                            sizetransfer[sizeof(int)+1]=0;
+                                // one byte will be missing...
+                                int size=blob.size()+1;
+                                char sizetransfer[sizeof(int)+1];
+                                memcpy(sizetransfer,(void*)&size,sizeof(int));
+                                sizetransfer[sizeof(int)+1]=0;
 
-                            string packet=string(sizetransfer)+blob;
+                                string packet=string(sizetransfer)+blob;
 
-                            send_raw_socket(packet,&ss,cid);
+                                send_raw_socket(packet,&ss,cid);
+                            }
                         }
                     }
+                } catch(...)
+                {
+                    std::cerr << "exception in child. ignoring\n";
                 }
 
                 // don't call atexit and stuff