summaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authoralex <alex@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-04-25 04:13:14 +0000
committeralex <alex@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-04-25 04:13:14 +0000
commit4c4e813d5cca0feab40bc62bd94d26fff5996204 (patch)
tree93ed27a178e2bd8d4330f76ac53fd7e308614c41 /examples
parent76b1a9d6773cf407db3af59f863c086bd633e15e (diff)
downloadATCD-4c4e813d5cca0feab40bc62bd94d26fff5996204.tar.gz
Added MT support for POSIXSIG Proactor. Updated the test files. Update
the test_aiosig_ace.cpp to use <pthread_sigmask> instead of <sigprocmask>.
Diffstat (limited to 'examples')
-rw-r--r--examples/Reactor/Proactor/Makefile5
-rw-r--r--examples/Reactor/Proactor/README56
-rw-r--r--examples/Reactor/Proactor/test_aiocb.cpp10
-rw-r--r--examples/Reactor/Proactor/test_aiosig.cpp76
-rw-r--r--examples/Reactor/Proactor/test_aiosig_ace.cpp73
-rw-r--r--examples/Reactor/Proactor/test_proactor.cpp24
-rw-r--r--examples/Reactor/Proactor/test_timeout.cpp48
7 files changed, 185 insertions, 107 deletions
diff --git a/examples/Reactor/Proactor/Makefile b/examples/Reactor/Proactor/Makefile
index 3932260c930..3a13b8c0979 100644
--- a/examples/Reactor/Proactor/Makefile
+++ b/examples/Reactor/Proactor/Makefile
@@ -8,10 +8,7 @@
# Local macros
#----------------------------------------------------------------------------
-BIN = test_proactor test_aiosig_ace
-LSRC = $(addsuffix .cpp,$(BIN))
-VLDLIBS = $(LDLIBS:%=%$(VAR))
-BUILD = $(VBIN)
+BIN = test_proactor test_aiosig_ace test_aiocb_ace test_timeout test_timeout_st test_posix_sig_proactor
#----------------------------------------------------------------------------
# Include macros and targets
diff --git a/examples/Reactor/Proactor/README b/examples/Reactor/Proactor/README
index fa873589773..6509e3efcb4 100644
--- a/examples/Reactor/Proactor/README
+++ b/examples/Reactor/Proactor/README
@@ -1,9 +1,10 @@
-This file describes the behavior of the POSIX <aio_> calls on the
-various platforms it is being tested on.
+This README file lists all the example applications for the Proactor framework.
-Test Suits:
-==========
+Test/Example Applications for Proactor:
+=========================================
+The following tests are available.
+
o $ACE_ROOT/tests/Aio_Platform_Test.cpp : Tests basic limits
pertaining to the POSIX features
@@ -16,23 +17,58 @@ o $ACE_ROOT/examples/Reactor/Proactor/test_aiosig.cpp : This is a
C++ program for testing the Signal based completion approach
that uses <sigtimedwait> for completion querying.
-o $ACE_ROOT/examples/Reactor/Proactor/test_aiosig_ace.cpp: (Same as
- test_aiosig.cpp, but uses ACE_DEBUGs instead of printf's and
- ACE_Message_Blocks instead of char*'s.
+o $ACE_ROOT/examples/Reactor/Proactor/test_aiocb_ace.cpp: Portable
+ version of test_aiocb.cpp. (Same as test_aiocb.cpp, but uses
+ ACE_DEBUGs instead of printf's and ACE_Message_Blocks instead
+ of char*'s.
+
+o $ACE_ROOT/examples/Reactor/Proactor/test_aiosig_ace.cpp: Portable
+ version of test_aiosig.cpp. (Same as test_aiosig.cpp, but uses
+ ACE_DEBUGs instead of printf's and ACE_Message_Blocks instead
+ of char*'s.
o test_proactor.cpp (with ACE_POSIX_AIOCB_Proactor) : Test for
ACE_Proactor which uses AIOCB (AIO Control Blocks) based
- completions strategy Proactor. (#define ACE_POSIX_AIOCB_PROACTOR)
+ completions strategy Proactor. (#define
+ ACE_POSIX_AIOCB_PROACTOR in the config file, but this is the
+ default option)
o test_proactor.cpp (with ACE_POSIX_SIG_Proactor) : Test for
ACE_Proactor which uses real time signal based completion
- strategy proactor. (#define ACE_POSIX_SIG_PROACTOR)
+ strategy proactor. (#define ACE_POSIX_SIG_PROACTOR in the
+ config file)
+
+o test_multiple_loops.cpp : This example application shows how
+ to write programs that combine the Proactor and Reactor event
+ loops. This is possible only on WIN32 platform.
+
+o test_timeout.cpp : Multithreaded application testing the Timers
+ mechanism of the Proactor.
+
+o test_timeout_st.cpp : Sinle threaded version of test_timeout.cpp.
Behavior of POSIX AIO of various platforms:
==========================================
+
+
+Summary:
+======
+ Sun Sun Lynx
+ 5.6 5.7
+
+test_aiocb_ace Good Good Good
+(test_aiocb)
+
+test_aiosig_ace Inconst Inconst Inconst
+
+
+Inconst.: Inconsistent execution.
+
+
+
Aio_Platform_Test:
================
@@ -142,5 +178,3 @@ Lynx g++:
TO-DO : 1. Run <gdb> and watch for <errno> and figure when
it is changing over to 77.
-
-
diff --git a/examples/Reactor/Proactor/test_aiocb.cpp b/examples/Reactor/Proactor/test_aiocb.cpp
index 3bd3ee96b3d..008121b744a 100644
--- a/examples/Reactor/Proactor/test_aiocb.cpp
+++ b/examples/Reactor/Proactor/test_aiocb.cpp
@@ -9,14 +9,8 @@
// test_aiocb.cpp
//
// = DESCRIPTION
-// This program helps you to test the <aio_*> calls on a
-// platform. Before running this test, make sure the platform can
-// support POSIX <aio_> calls. use $ACE_ROOT/tests for this.
-// This is for testing the AIOCB (AIO Control Blocks) based
-// completion approach which uses <aio_suspend> for completion
-// querying.
-// If this test is successful, ACE_POSIX_AIOCB_PROACTOR
-// can be used on this platform.
+// Checkout $ACE_ROOT/examples/Reactor/Proactor/test_aiocb_ace.cpp,
+// which is the ACE'ified version of this program.
//
// = COMPILE and RUN
// % CC -g -o test_aiocb -lrt test_aiocb.cpp
diff --git a/examples/Reactor/Proactor/test_aiosig.cpp b/examples/Reactor/Proactor/test_aiosig.cpp
index ff4c257af84..1746a10a49c 100644
--- a/examples/Reactor/Proactor/test_aiosig.cpp
+++ b/examples/Reactor/Proactor/test_aiosig.cpp
@@ -5,26 +5,11 @@
// test_aiosig.cpp
//
// = DESCRITPTION
-// This program helps you to test the <aio_*> calls on a
-// platform.
-// Before running this test, make sure the platform can
-// support POSIX <aio_> calls. use $ACE_ROOT/tests for this.
-// This is for testing the Signal based completion approach which
-// uses <sigtimedwait> for completion querying.
-// If this test is successful, ACE_POSIX_SIG_PROACTOR
-// can be used on this platform.
-// This program is a C-language version of the
-// $ACE_ROOT/examples/Reactor/Proactor/test_aiosig_ace.cpp, with
-// all the ACE calls removed.
-// This test does the following:
-// Issue two <aio_read>s.
-// Assign SIGRTMIN as the notification signal.
-// Mask these signals from delivery.
-// Receive this signal by doing <sigtimedwait>.
-// Wait for two completions (two signals)
+// Check out test_aiosig_ace.cpp, the ACE'ified version of this
+// program. This program may not be uptodate.
//
// = COMPILATION
-// CC -g -o test_aiosig -lposix4 test_aiosig.cpp
+// CC -g -o test_aiosig -lrt test_aiosig.cpp
//
// = RUN
// ./test_aiosig
@@ -60,6 +45,8 @@ int setup_signal_delivery (void);
int issue_aio_calls (void);
int query_aio_completions (void);
int test_aio_calls (void);
+int setup_signal_handler (void);
+int setup_signal_handler (int signal_number);
int
setup_signal_delivery (void)
@@ -78,31 +65,13 @@ setup_signal_delivery (void)
}
// Mask them.
- if (sigprocmask (SIG_BLOCK, &completion_signal, 0) == -1)
+ if (pthread_sigmask (SIG_BLOCK, &completion_signal, 0) == -1)
{
perror ("Error:Couldnt maks the RT completion signals\n");
return -1;
}
- // Setting up the handler(!) for these signals.
- struct sigaction reaction;
- sigemptyset (&reaction.sa_mask); // Nothing else to mask.
- reaction.sa_flags = SA_SIGINFO; // Realtime flag.
-#if defined (SA_SIGACTION)
- // Lynx says, it is better to set this bit to be portable.
- reaction.sa_flags &= SA_SIGACTION;
-#endif /* SA_SIGACTION */
- reaction.sa_sigaction = 0; // No handler.
- int sigaction_return = sigaction (SIGRTMIN,
- &reaction,
- 0);
- if (sigaction_return == -1)
- {
- perror ("Error:Proactor couldnt do sigaction for the RT SIGNAL");
- return -1;
- }
-
- return 0;
+ return setup_signal_handler (SIGRTMIN);
}
int
@@ -282,6 +251,37 @@ test_aio_calls (void)
}
int
+setup_signal_handler (int signal_number)
+{
+ // Setting up the handler(!) for these signals.
+ struct sigaction reaction;
+ sigemptyset (&reaction.sa_mask); // Nothing else to mask.
+ reaction.sa_flags = SA_SIGINFO; // Realtime flag.
+#if defined (SA_SIGACTION)
+ // Lynx says, it is better to set this bit to be portable.
+ reaction.sa_flags &= SA_SIGACTION;
+#endif /* SA_SIGACTION */
+ reaction.sa_sigaction = null_handler; // Null handler.
+ int sigaction_return = sigaction (SIGRTMIN,
+ &reaction,
+ 0);
+ if (sigaction_return == -1)
+ {
+ perror ("Error:Proactor couldnt do sigaction for the RT SIGNAL");
+ return -1;
+ }
+
+ return 0;
+}
+
+void
+null_handler (int /* signal_number */,
+ siginfo_t * /* info */,
+ void * /* context */)
+{
+}
+
+int
main (int, char *[])
{
if (test_aio_calls () == 0)
diff --git a/examples/Reactor/Proactor/test_aiosig_ace.cpp b/examples/Reactor/Proactor/test_aiosig_ace.cpp
index 09094727629..e805e9e8563 100644
--- a/examples/Reactor/Proactor/test_aiosig_ace.cpp
+++ b/examples/Reactor/Proactor/test_aiosig_ace.cpp
@@ -8,14 +8,17 @@
// This program helps you to test the <aio_*> calls on a
// platform.
// Before running this test, make sure the platform can
-// support POSIX <aio_> calls. use $ACE_ROOT/tests for this.
-// This is for testing the Signal based completion approach which
+// support POSIX <aio_> calls, using ACE_ROOT/tests/Aio_Plaform_Test.cpp
+//
+// This program tests the Signal based completion approach which
// uses <sigtimedwait> for completion querying.
// If this test is successful, ACE_POSIX_SIG_PROACTOR
// can be used on this platform.
+//
// This program is a ACE version of the
// $ACE_ROOT/examples/Reactor/Proactor/test_aiosig.cpp, with
// ACE_DEBUGs and Message_Blocks.
+//
// This test does the following:
// Issue two <aio_read>s.
// Assign SIGRTMIN as the notification signal.
@@ -49,28 +52,51 @@ static int setup_signal_delivery (void);
static int issue_aio_calls (void);
static int query_aio_completions (void);
static int test_aio_calls (void);
+static void null_handler (int signal_number, siginfo_t *info, void *context);
+static int setup_signal_handler (int signal_number);
static int
setup_signal_delivery (void)
{
- // Make the sigset_t consisting of the completion signal.
- if (sigemptyset (&completion_signal) < 0)
+ // = Mask all the signals.
+
+ sigset_t full_set;
+
+ // Get full set.
+ if (sigfillset (&full_set) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Error:(%P | %t):%p\n",
+ "sigfillset failed"),
+ -1);
+
+ // Mask them.
+ if (pthread_sigmask (SIG_SETMASK, &full_set, 0) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Error:(%P | %t):%p\n",
+ "pthread_sigmask failed"),
+ -1);
+
+ // = Make a mask with SIGRTMIN only. We use only that signal to
+ // issue <aio_>'s.
+
+ if (sigemptyset (&completion_signal) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"Error:%p:Couldnt init the RT completion signal set\n"),
-1);
if (sigaddset (&completion_signal,
- SIGRTMIN) < 0)
+ SIGRTMIN) == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"Error:%p:Couldnt init the RT completion signal set\n"),
-1);
- // Mask them.
- if (sigprocmask (SIG_BLOCK, &completion_signal, 0) < 0)
- ACE_ERROR_RETURN ((LM_ERROR,
- "Error:%p:Couldnt maks the RT completion signals\n"),
- -1);
+ // Set up signal handler for this signal.
+ return setup_signal_handler (SIGRTMIN);
+}
+static int
+setup_signal_handler (int signal_number)
+{
// Setting up the handler(!) for these signals.
struct sigaction reaction;
sigemptyset (&reaction.sa_mask); // Nothing else to mask.
@@ -79,7 +105,7 @@ setup_signal_delivery (void)
// Lynx says, it is better to set this bit to be portable.
reaction.sa_flags &= SA_SIGACTION;
#endif /* SA_SIGACTION */
- reaction.sa_sigaction = 0; // No handler.
+ reaction.sa_sigaction = null_handler; // Null handler.
int sigaction_return = sigaction (SIGRTMIN,
&reaction,
0);
@@ -90,6 +116,7 @@ setup_signal_delivery (void)
return 0;
}
+
static int
issue_aio_calls (void)
{
@@ -142,10 +169,10 @@ query_aio_completions (void)
timespec timeout;
timeout.tv_sec = ACE_INFINITE;
timeout.tv_nsec = 0;
-
+
// To get back the signal info.
siginfo_t sig_info;
-
+
// Await the RT completion signal.
int sig_return = sigtimedwait (&completion_signal,
&sig_info,
@@ -158,7 +185,7 @@ query_aio_completions (void)
if (sig_return == -1)
ACE_ERROR_RETURN ((LM_ERROR,
"Error:%p:Error waiting for RT completion signals\n"),
- 0);
+ -1);
// RT completion signals returned.
if (sig_return != SIGRTMIN)
@@ -248,18 +275,30 @@ test_aio_calls (void)
"ACE_OS::open"),
-1);
- if (setup_signal_delivery () < 0)
+ if (setup_signal_delivery () == -1)
return -1;
- if (issue_aio_calls () < 0)
+ if (issue_aio_calls () == -1)
return -1;
- if (query_aio_completions () < 0)
+ if (query_aio_completions () == -1)
return -1;
return 0;
}
+static void
+null_handler (int signal_number,
+ siginfo_t */* info */,
+ void * /* context */)
+{
+ ACE_ERROR ((LM_ERROR,
+ "Error:%s:Signal number %d\n"
+ "Mask all the RT signals for this thread",
+ "ACE_POSIX_SIG_Proactor::null_handler called",
+ signal_number));
+}
+
int
main (int, char *[])
{
diff --git a/examples/Reactor/Proactor/test_proactor.cpp b/examples/Reactor/Proactor/test_proactor.cpp
index 7d25fd9f3c4..37c93cd7f57 100644
--- a/examples/Reactor/Proactor/test_proactor.cpp
+++ b/examples/Reactor/Proactor/test_proactor.cpp
@@ -33,6 +33,10 @@
ACE_RCSID(Proactor, test_proactor, "$Id$")
+#if ((defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || (defined (ACE_HAS_AIO_CALLS)))
+ // This only works on Win32 platforms and on Unix platforms supporting
+ // POSIX aio calls.
+
static char *host = 0;
static u_short port = ACE_DEFAULT_SERVER_PORT;
static char *file = "test_proactor.cpp";
@@ -89,8 +93,8 @@ private:
};
Receiver::Receiver (void)
- : handle_ (ACE_INVALID_HANDLE),
- dump_file_ (ACE_INVALID_HANDLE)
+ : dump_file_ (ACE_INVALID_HANDLE),
+ handle_ (ACE_INVALID_HANDLE)
{
}
@@ -154,6 +158,7 @@ Receiver::open (ACE_HANDLE handle,
initial_read_size,
0,
ACE_INVALID_HANDLE,
+ 0,
0);
size_t bytes_transferred = message_block.length ();
@@ -402,14 +407,11 @@ Sender::transmit_file (void)
this->welcome_message_.length (),
this->welcome_message_.duplicate (),
this->welcome_message_.length ());
-
- // Starting position
- cerr << "Starting position: " << ACE_OS::lseek (file_handle, 0L, SEEK_CUR) << endl;
-
+
// Send it
if (tf.transmit_file (file_handle,
&this->header_and_trailer_) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Transmit_File::transmit_file"), -1);
+ ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "ACE_Asynch_Transmit_File::transmit_file"), -1);
return 0;
}
@@ -432,12 +434,9 @@ Sender::handle_transmit_file (const ACE_Asynch_Transmit_File::Result &result)
ACE_DEBUG ((LM_DEBUG, "%s = %d\n", "error", result.error ()));
ACE_DEBUG ((LM_DEBUG, "********************\n"));
- // Ending position
- cerr << "Ending position: " << ACE_OS::lseek (result.file (), 0L, SEEK_CUR) << endl;
-
// Done with file
ACE_OS::close (result.file ());
-
+
this->transmit_file_done_ = 1;
if (this->stream_write_done_)
done = 1;
@@ -581,7 +580,6 @@ parse_args (int argc, char *argv[])
int
main (int argc, char *argv[])
{
-
if (parse_args (argc, argv) == -1)
return -1;
@@ -616,3 +614,5 @@ template class ACE_Asynch_Acceptor<Receiver>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Asynch_Acceptor<Receiver>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
+
+#endif /* ACE_WIN32 && !ACE_HAS_WINCE || ACE_HAS_AIO_CALLS*/
diff --git a/examples/Reactor/Proactor/test_timeout.cpp b/examples/Reactor/Proactor/test_timeout.cpp
index 2835840a555..10318ba1273 100644
--- a/examples/Reactor/Proactor/test_timeout.cpp
+++ b/examples/Reactor/Proactor/test_timeout.cpp
@@ -12,10 +12,12 @@
//
// This example application shows how to write event loops that
// handle events for some fixed amount of time. Note that any
-// thread in the Proactor thread pool can call back the handler
+// thread in the Proactor thread pool can call back the handler. On
+// POSIX4 systems, this test works only with POSIX_SIG_Proactor,
+// which can work with multiple threads.
//
// = AUTHOR
-// Irfan Pyarali
+// Irfan Pyarali and Alexander Babu Arulanthu
//
// ============================================================================
@@ -25,30 +27,37 @@
ACE_RCSID(Proactor, test_timeout, "$Id$")
+#if ((defined (ACE_WIN32) && !defined (ACE_HAS_WINCE)) || \
+ (defined (ACE_HAS_AIO_CALLS)) && !defined (ACE_POSIX_AIOCB_PROACTOR))
+ // This only works on Win32 platforms and on Unix platforms supporting
+ // POSIX aio calls.
+
class Timeout_Handler : public ACE_Handler
+{
// = TITLE
// Generic timeout handler.
-{
public:
Timeout_Handler (void)
: start_time_ (ACE_OS::gettimeofday ())
- {
+ {
}
virtual void handle_time_out (const ACE_Time_Value &tv,
const void *arg)
- // Print out when timeouts occur.
{
+ // Print out when timeouts occur.
ACE_DEBUG ((LM_DEBUG, "(%t) %d timeout occurred for %s @ %d.\n",
++count_,
(char *) arg,
(tv - this->start_time_).sec ()));
+
// Sleep for a while
ACE_OS::sleep (4);
}
private:
ACE_Atomic_Op <ACE_Thread_Mutex, int> count_;
+ // Number of the timer event.
ACE_Time_Value start_time_;
// Starting time of the test.
@@ -57,18 +66,20 @@ private:
class Worker : public ACE_Task <ACE_NULL_SYNCH>
{
public:
- int svc (void)
- {
- // Handle events for 13 seconds.
- ACE_Time_Value run_time (13);
-
- if (ACE_Proactor::run_event_loop(run_time) == -1)
- ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "Worker::svc"), -1);
- else
+ int svc (void)
+ {
+ // Handle events for 13 seconds.
+ ACE_Time_Value run_time (13);
+
+ ACE_DEBUG ((LM_DEBUG, "(%t):Starting svc routine\n"));
+
+ if (ACE_Proactor::run_event_loop(run_time) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR, "(%t):%p.\n", "Worker::svc"), -1);
+
ACE_DEBUG ((LM_DEBUG, "(%t) work complete\n"));
-
- return 0;
- }
+
+ return 0;
+ }
};
int
@@ -93,11 +104,12 @@ main (int, char *[])
ACE_ERROR_RETURN ((LM_ERROR, "%p\n", "schedule_timer"), -1);
Worker worker;
-
+
if (worker.activate (THR_NEW_LWP, 10) == -1)
ACE_ERROR_RETURN ((LM_ERROR, "%p.\n", "main"), -1);
ACE_Thread_Manager::instance ()->wait ();
+
return 0;
}
@@ -106,3 +118,5 @@ template class ACE_Atomic_Op<ACE_Thread_Mutex, int>;
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#pragma instantiate ACE_Atomic_Op<ACE_Thread_Mutex, int>
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */
+
+#endif /* ACE_WIN32 && !ACE_HAS_WINCE || ACE_HAS_AIO_CALLS && !ACE_POSIX_AIOCB_PROACTOR*/