libt2n: (gerd) set additional non-blocking options, not really needed but a safety...
[libt2n] / test / timeout.cpp
index 7a4e9ed..e194b85 100644 (file)
@@ -138,6 +138,7 @@ class test_timeout : public TestFixture
     CPPUNIT_TEST(CommandTimeout);
     CPPUNIT_TEST(CommandSlowResponse);
     CPPUNIT_TEST(DisconnectOnWrite);
+    CPPUNIT_TEST(WriteTwice);
     CPPUNIT_TEST(DisconnectOnRead);
     CPPUNIT_TEST(BreakAccept);
 
@@ -495,6 +496,59 @@ class test_timeout : public TestFixture
         }
     }
 
+    void WriteTwice()
+    {
+        switch(child_pid=fork())
+        {
+            case -1:
+            {
+                CPPUNIT_FAIL("fork error");
+                break;
+            }
+            case 0:
+            // child
+            {
+                socket_server ss("./socket");
+
+                // bail out as soon as we get something
+                ss.fill_buffer(-1);
+                // don't call atexit and stuff
+                _exit(0);
+            }
+
+            default:
+            // parent
+            {
+                string data;
+
+                // don't kill us on broken pipe
+                signal(SIGPIPE, SIG_IGN);
+
+                // wait till server is up
+                sleep(1);
+                socket_client_connection sc("./socket");
+
+                string errormsg;
+
+                sc.write("somedata");
+
+                sleep(1);
+
+                // server should disconnect now
+                try
+                {
+                    sc.write("other data");
+                }
+                catch(t2n_transfer_error &e)
+                { errormsg=e.what(); }
+                catch(...)
+                { throw; }
+
+                CPPUNIT_ASSERT_EQUAL(string("write() returned Broken pipe"),errormsg);
+            }
+        }
+    }
+
     void DisconnectOnRead()
     {
         pid_t pid2;