[complement-svn] SF.net SVN: complement: [1418] trunk/complement/explore/test/libsockios/ unit/read
Status: Pre-Alpha
Brought to you by:
complement
From: <com...@us...> - 2006-11-28 10:06:41
|
Revision: 1418 http://svn.sourceforge.net/complement/?rev=1418&view=rev Author: complement Date: 2006-11-28 02:06:40 -0800 (Tue, 28 Nov 2006) Log Message: ----------- use IPC technique that work to sync after fork (via shm segment) Modified Paths: -------------- trunk/complement/explore/test/libsockios/unit/read0_on_exec.cc Modified: trunk/complement/explore/test/libsockios/unit/read0_on_exec.cc =================================================================== --- trunk/complement/explore/test/libsockios/unit/read0_on_exec.cc 2006-11-28 10:05:20 UTC (rev 1417) +++ trunk/complement/explore/test/libsockios/unit/read0_on_exec.cc 2006-11-28 10:06:40 UTC (rev 1418) @@ -1,4 +1,4 @@ -// -*- C++ -*- Time-stamp: <06/08/21 23:48:43 ptr> +// -*- C++ -*- Time-stamp: <06/11/28 09:33:13 ptr> /* * @@ -22,6 +22,8 @@ #include <sys/types.h> #include <sys/wait.h> +#include <sys/shm.h> + using namespace std; using namespace xmt; @@ -62,7 +64,6 @@ extern xmt::Mutex pr_lock; // static __Condition<true> cndf; -static Semaphore sem( 1, true ); class ConnectionProcessor5 // dummy variant { @@ -125,6 +126,21 @@ void test_read0() { + shmid_ds ds; + int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); + if ( id == -1 ) { + cerr << "Error on shmget" << endl; + } + if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { + cerr << "Error on shmctl" << endl; + } + void *buf = shmat( id, 0, 0 ); + if ( buf == reinterpret_cast<void *>(-1) ) { + cerr << "Error on shmat" << endl; + } + + Semaphore& sem = *new( buf ) Semaphore( 1, true ); + try { // cerr << "** 1" << endl; // cndf.set( false ); @@ -166,6 +182,10 @@ srv.close(); srv.wait(); } + (&sem)->~Semaphore(); + + shmdt( buf ); + shmctl( id, IPC_RMID, &ds ); } class ConnectionProcessor6 // dummy variant @@ -177,7 +197,7 @@ void close(); }; -static Semaphore sem2( 2, false ); +static Semaphore *sem2; ConnectionProcessor6::ConnectionProcessor6( std::sockstream& s ) { @@ -187,7 +207,7 @@ BOOST_REQUIRE( s.good() ); pr_lock.unlock(); - sem2.post(); + sem2->post(); } void ConnectionProcessor6::connect( std::sockstream& s ) @@ -203,6 +223,21 @@ void test_read0_srv() { + shmid_ds ds; + int id = shmget( 5000, 1024, IPC_CREAT | IPC_EXCL | 0600 ); + if ( id == -1 ) { + cerr << "Error on shmget" << endl; + } + if ( shmctl( id, IPC_STAT, &ds ) == -1 ) { + cerr << "Error on shmctl" << endl; + } + void *buf = shmat( id, 0, 0 ); + if ( buf == reinterpret_cast<void *>(-1) ) { + cerr << "Error on shmat" << endl; + } + + sem2 = new( buf ) Semaphore( 2, true ); + sockmgr_stream_MP<ConnectionProcessor6> srv( ::port ); { @@ -213,7 +248,7 @@ BOOST_CHECK( s.good() ); - sem2.wait(); + sem2->wait(); } system( "echo > /dev/null" ); // <------ key line @@ -226,7 +261,7 @@ BOOST_CHECK( s.good() ); - sem2.wait(); + sem2->wait(); } BOOST_CHECK( srv.good() ); // server must correctly process interrupt during system call @@ -234,4 +269,9 @@ srv.close(); srv.wait(); + + sem2->~Semaphore(); + + shmdt( buf ); + shmctl( id, IPC_RMID, &ds ); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |