summaryrefslogtreecommitdiff
path: root/examples/Reactor
diff options
context:
space:
mode:
authoralex <alex@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-03 23:04:22 +0000
committeralex <alex@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-03 23:04:22 +0000
commit0c60118bafbe74ce0a68864baeeb18d0bd640b5b (patch)
tree26cbe4846f9d4380a6bf420b924c88279bd58387 /examples/Reactor
parent8603c1bcc1b22d13981b6d082bf53343e96ed0d6 (diff)
downloadATCD-0c60118bafbe74ce0a68864baeeb18d0bd640b5b.tar.gz
Adding this file. If this test is successful, ACE_POSIX_AIOCB_PROACTOR
can be used on this platform.
Diffstat (limited to 'examples/Reactor')
-rw-r--r--examples/Reactor/Proactor/test_aiocb_ace.cpp255
1 files changed, 255 insertions, 0 deletions
diff --git a/examples/Reactor/Proactor/test_aiocb_ace.cpp b/examples/Reactor/Proactor/test_aiocb_ace.cpp
new file mode 100644
index 00000000000..c642a1db2aa
--- /dev/null
+++ b/examples/Reactor/Proactor/test_aiocb_ace.cpp
@@ -0,0 +1,255 @@
+// $Id$
+
+// ============================================================================
+//
+// = LIBRARY
+// proactor
+//
+// = FILENAME
+// test_aiocb_ace.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, using
+// ACE_ROOT/tests/Aio_Platform_Test.
+//
+// This program tests 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.
+//
+// = COMPILE and RUN
+// % make
+// % ./test_aiocb_ace
+//
+// = AUTHOR
+// Alexander Babu Arulanthu <alex@cs.wustl.edu>
+//
+// ============================================================================
+
+#include "ace/OS.h"
+#include "ace/ACE.h"
+
+class Test_Aio
+{
+public:
+ Test_Aio (void);
+ // Default constructor.
+
+ int init (void);
+ // Initting the output file and the buffer.
+
+ int do_aio (void);
+ // Doing the testing stuff.
+
+ ~Test_Aio (void);
+ // Destructor.
+private:
+ int out_fd_;
+ // Output file descriptor.
+
+ struct aiocb *aiocb_write_;
+ // For writing to the file.
+
+ struct aiocb *aiocb_read_;
+ // Reading stuff from the file.
+
+ char *buffer_write_;
+ // The buffer to be written to the out_fd.
+
+ char *buffer_read_;
+ // The buffer to be read back from the file.
+};
+
+Test_Aio::Test_Aio (void)
+ : aiocb_write_ (0),
+ aiocb_read_ (0),
+ buffer_write_ (0),
+ buffer_read_ (0)
+{
+ ACE_NEW (this->aiocb_write_,
+ struct aiocb);
+ ACE_NEW (this->aiocb_read_,
+ struct aiocb);
+}
+
+Test_Aio::~Test_Aio (void)
+{
+ delete aiocb_write_;
+ delete aiocb_read_;
+ delete buffer_write_;
+ delete buffer_read_;
+}
+
+// Init the output file and init the buffer.
+int
+Test_Aio::init (void)
+{
+ // Open the output file.
+ this->out_fd_ = ACE_OS::open ("test_aio.log",
+ O_RDWR | O_CREAT | O_TRUNC,
+ 0666);
+ if (this->out_fd_ == 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "Error: Opening file\n"),
+ -1);
+
+ // Init the buffers.
+ this->buffer_write_ = ACE::strnew ("Welcome to the world of AIO... AIO Rules !!!");
+ ACE_DEBUG ((LM_DEBUG,
+ "The buffer : %s\n",
+ this->buffer_write_));
+
+ // Allocate memory for the read buffer.
+ ACE_NEW_RETURN (this->buffer_read_,
+ char [strlen (this->buffer_write_)],
+ -1);
+
+ return 0;
+}
+
+// Set the necessary things for the AIO stuff.
+// Write the buffer asynchly.hmm Disable signals.
+// Go on aio_suspend. Wait for completion.
+// Print out the result.
+int
+Test_Aio::do_aio (void)
+{
+ // = Write to the file.
+
+ // Setup AIOCB.
+ this->aiocb_write_->aio_fildes = this->out_fd_;
+ this->aiocb_write_->aio_offset = 0;
+ this->aiocb_write_->aio_buf = this->buffer_write_;
+ this->aiocb_write_->aio_nbytes = strlen (this->buffer_write_);
+ this->aiocb_write_->aio_reqprio = 0;
+ this->aiocb_write_->aio_sigevent.sigev_notify = SIGEV_NONE;
+ //this->this->aiocb_.aio_sigevent.sigev_signo = SIGRTMAX;
+ this->aiocb_write_->aio_sigevent.sigev_value.sival_ptr =
+ (void *) this->aiocb_write_;
+
+ // Fire off the aio write.
+ if (aio_write (this->aiocb_write_) != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "aio_write"),
+ -1);
+
+ // = Read from that file.
+
+ // Setup AIOCB.
+ this->aiocb_read_->aio_fildes = this->out_fd_;
+ this->aiocb_read_->aio_offset = 0;
+ this->aiocb_read_->aio_buf = this->buffer_read_;
+ this->aiocb_read_->aio_nbytes = strlen (this->buffer_write_);
+ this->aiocb_read_->aio_reqprio = 0;
+ this->aiocb_read_->aio_sigevent.sigev_notify = SIGEV_NONE;
+ //this->this->aiocb_.aio_sigevent.sigev_signo = SIGRTMAX;
+ this->aiocb_read_->aio_sigevent.sigev_value.sival_ptr =
+ (void *) this->aiocb_read_;
+
+ // Fire off the aio write. If it doesnt get queued, carry on to get
+ // the completion for the first one.
+ if (aio_read (this->aiocb_read_) < 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "aio_read"),
+ -1);
+
+ // Wait for the completion on aio_suspend.
+ struct aiocb *list_aiocb[2];
+ list_aiocb [0] = this->aiocb_write_;
+ list_aiocb [1] = this->aiocb_read_;
+
+ // Do suspend till all the aiocbs in the list are done.
+ int done = 0;
+ int return_val = 0;
+ while (!done)
+ {
+ return_val = aio_suspend (list_aiocb,
+ 2,
+ 0);
+ ACE_DEBUG ((LM_DEBUG,
+ "Result of <aio_suspend> : %d\n",
+ return_val));
+
+ // Analyze return and error values.
+ if (aio_error (list_aiocb [0]) != EINPROGRESS)
+ {
+ if (aio_return (list_aiocb [0]) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "aio_return"),
+ -1);
+ else
+ {
+ // Successful. Store the pointer somewhere and make the
+ // entry NULL in the list.
+ this->aiocb_write_ = list_aiocb [0];
+ list_aiocb [0] = 0;
+ }
+ }
+ else
+ ACE_DEBUG ((LM_DEBUG,
+ "aio_error says aio is in progress\n"));
+
+ if (aio_error (list_aiocb [1]) != EINPROGRESS)
+ {
+ if (aio_return (list_aiocb [1]) == -1)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "%p\n",
+ "aio_return"),
+ -1);
+ else
+ {
+ // Successful. Store the pointer somewhere and make the
+ // entry NULL in the list.
+ this->aiocb_read_ = list_aiocb [1];
+ list_aiocb [1] = 0;
+ }
+ }
+ else
+ ACE_DEBUG ((LM_DEBUG,
+ "aio_error says aio is in progress\n"));
+
+ // Is it done?
+ if ((list_aiocb [0] == 0) && (list_aiocb [1] == 0))
+ done = 1;
+ }
+
+ ACE_DEBUG ((LM_DEBUG,
+ "Both the AIO operations done.\n"
+ "The buffer is : %s\n",
+ this->buffer_read_));
+
+ return 0;
+}
+
+int
+main (int argc, char **argv)
+{
+ Test_Aio test_aio;
+
+ if (test_aio.init () != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "AIOCB test failed:\n"
+ "ACE_POSIX_AIOCB_PROACTOR may not work in this platform\n"),
+ -1);
+
+ if (test_aio.do_aio () != 0)
+ ACE_ERROR_RETURN ((LM_ERROR,
+ "AIOCB test failed:\n"
+ "ACE_POSIX_AIOCB_PROACTOR may not work in this platform\n"),
+ -1);
+
+ ACE_DEBUG ((LM_DEBUG,
+ "AIOCB test successful:\n"
+ "ACE_POSIX_AIOCB_PROACTOR should work in this platform\n"));
+
+ return 0;
+}