1
dnl -------------------------------------------------------------------------
2
dnl aio.m4,v 1.1 2003/11/18 23:59:13 ossama Exp
6
dnl ACE M4 include file which contains ACE specific M4 macros
7
dnl that determine availablility of POSIX asynchronous IO
10
dnl -------------------------------------------------------------------------
12
dnl Copyright (C) 1998, 1999, 2002 Ossama Othman
14
dnl All Rights Reserved
16
dnl This library is free software; you can redistribute it and/or
17
dnl modify it under the current ACE distribution terms.
19
dnl This library is distributed in the hope that it will be useful,
20
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
21
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23
dnl Asynchronous IO check
24
dnl Use this macro to determine if asynchronous IO is working on a
26
dnl Usage: ACE_CHECK_ASYNCH_IO
27
AC_DEFUN([ACE_CHECK_ASYNCH_IO],
29
AC_REQUIRE([AC_PROG_CXX])
30
AC_REQUIRE([AC_PROG_CXXCPP])
33
AC_REQUIRE([ACE_CHECK_THREADS])
35
dnl In case a library with the asynchronous libraries is found but
36
dnl the asynchronous IO support is not functional then save a copy
37
dnl of the list of libraries before the asynch IO function library
38
dnl is added to the list so that we can revert the list to its
39
dnl pre-asynch-IO check state.
42
dnl Asynchronous IO library check
43
dnl Some platforms, such as Solaris puts aio_read in -lposix4, for example.
44
dnl In some cases, the thread library must be linked to in addition to the
45
dnl real-time support library. As such, make sure these checks are done
46
dnl after the thread library checks.
47
AC_SEARCH_LIBS([aio_read], [aio rt posix4],
48
[ace_has_aio_funcs=yes], [ace_has_aio_funcs=no])
50
if test "$ace_has_aio_funcs" = yes; then
51
ACE_CACHE_CHECK([for working asynchronous IO],
52
[ace_cv_feature_aio_calls],
54
AC_RUN_IFELSE([AC_LANG_SOURCE([[
55
#ifndef ACE_LACKS_UNISTD_H
59
#ifndef ACE_LACKS_SYS_TYPES_H
60
# include <sys/types.h>
75
// Default constructor.
78
// Initting the output file and the buffer.
81
// Doing the testing stuff.
87
// Output file descriptor.
89
struct aiocb *aiocb_write_;
90
// For writing to the file.
92
struct aiocb *aiocb_read_;
93
// Reading stuff from the file.
96
// The buffer to be written to the out_fd.
99
// The buffer to be read back from the file.
102
Test_Aio::Test_Aio (void)
104
aiocb_write_ (new struct aiocb),
105
aiocb_read_ (new struct aiocb),
111
Test_Aio::~Test_Aio (void)
113
if (close (this->out_fd_) != 0)
118
delete [] buffer_write_;
119
delete [] buffer_read_;
122
// Init the output file and init the buffer.
124
Test_Aio::init (void)
126
// Open the output file.
127
this->out_fd_ = open ("test_aio.log", O_RDWR | O_CREAT | O_TRUNC, 0600);
128
if (this->out_fd_ == -1)
134
unlink ("test_aio.log"); // Unlink now so we don't have to do so later.
136
const char message[] = "Welcome to the world of AIO... AIO Rules !!!";
139
this->buffer_write_ = new char [sizeof (message) + 1];
140
strcpy (this->buffer_write_, message);
141
// cout << "The buffer : " << this->buffer_write_ << endl;
142
this->buffer_read_ = new char [sizeof (message) + 1];
147
// Set the necessary things for the AIO stuff.
148
// Write the buffer asynchly.hmm Disable signals.
149
// Go on aio_suspend. Wait for completion.
150
// Print out the result.
152
Test_Aio::do_aio (void)
154
// = Write to the file.
157
this->aiocb_write_->aio_fildes = this->out_fd_;
158
this->aiocb_write_->aio_offset = 0;
159
this->aiocb_write_->aio_buf = this->buffer_write_;
160
this->aiocb_write_->aio_nbytes = strlen (this->buffer_write_);
161
this->aiocb_write_->aio_reqprio = 0;
162
this->aiocb_write_->aio_sigevent.sigev_notify = SIGEV_NONE;
163
//this->this->aiocb_.aio_sigevent.sigev_signo = SIGRTMAX;
164
this->aiocb_write_->aio_sigevent.sigev_value.sival_ptr =
165
(void *) this->aiocb_write_;
167
// Fire off the aio write.
168
if (aio_write (this->aiocb_write_) != 0)
170
perror ("aio_write");
174
// = Read from that file.
177
this->aiocb_read_->aio_fildes = this->out_fd_;
178
this->aiocb_read_->aio_offset = 0;
179
this->aiocb_read_->aio_buf = this->buffer_read_;
180
this->aiocb_read_->aio_nbytes = strlen (this->buffer_write_);
181
this->aiocb_read_->aio_reqprio = 0;
182
this->aiocb_read_->aio_sigevent.sigev_notify = SIGEV_NONE;
183
//this->this->aiocb_.aio_sigevent.sigev_signo = SIGRTMAX;
184
this->aiocb_read_->aio_sigevent.sigev_value.sival_ptr =
185
(void *) this->aiocb_read_;
187
// Fire off the aio write. If it doesnt get queued, carry on to get
188
// the completion for the first one.
189
if (aio_read (this->aiocb_read_) < 0)
192
// Wait for the completion on aio_suspend.
193
struct aiocb *list_aiocb[2];
194
list_aiocb [0] = this->aiocb_write_;
195
list_aiocb [1] = this->aiocb_read_;
197
// Do suspend till all the aiocbs in the list are done.
201
if (aio_suspend (list_aiocb, 2, 0) != 0)
203
perror ("aio_suspend");
207
// Analyze return and error values.
208
if (list_aiocb [0] != 0 && aio_error (list_aiocb [0]) != EINPROGRESS)
210
if (aio_return (list_aiocb [0]) == -1)
212
perror ("aio_return");
217
// Successful. Store the pointer somewhere and make the
218
// entry NULL in the list.
219
// @@ no need ----> this->aiocb_write_ = list_aiocb [0];
224
// cout << "AIO in progress" << endl;
226
if (list_aiocb [1] != 0 && aio_error (list_aiocb [1]) != EINPROGRESS)
228
if (aio_return (list_aiocb [1]) == -1)
230
perror ("aio_return");
235
// Successful. Store the pointer somewhere and make the
236
// entry NULL in the list.
237
// @@ no need ----> this->aiocb_read_ = list_aiocb [1];
242
// cout << "AIO in progress" << endl;
245
if ((list_aiocb [0] == 0) && (list_aiocb [1] == 0))
249
//cout << "Both the AIO operations done." << endl;
250
//cout << "The buffer is :" << this->buffer_read_ << endl;
260
if (test_aio.init () != 0)
262
//printf ("AIOCB test failed:\n"
263
// "ACE_POSIX_AIOCB_PROACTOR may not work in this platform\n");
267
if (test_aio.do_aio () != 0)
269
//printf ("AIOCB test failed:\n"
270
// "ACE_POSIX_AIOCB_PROACTOR may not work in this platform\n");
273
//printf ("AIOCB test successful:\n"
274
// "ACE_POSIX_AIOCB_PROACTOR should work in this platform\n");
278
dnl Now try another test
280
dnl Create a file for the test program to read.
281
cat > test_aiosig.txt <<EOF
283
*******************************************************
284
FOO BAR FOO BAR FOO BAR FOO BAR FOO BAR FOO BAR FOO BAR
285
*******************************************************
291
#ifndef ACE_LACKS_UNISTD_H
295
#ifndef ACE_LACKS_SYS_TYPES_H
296
# include <sys/types.h>
298
#include <sys/stat.h>
312
void null_handler (int /* signal_number */,
313
siginfo_t * /* info */,
314
void * /* context */);
316
int file_handle = -1;
317
char mb1[BUFSIZ + 1];
318
char mb2[BUFSIZ + 1];
319
aiocb aiocb1, aiocb2;
320
sigset_t completion_signal;
322
// Function prototypes.
323
int setup_signal_delivery (void);
324
int issue_aio_calls (void);
325
int query_aio_completions (void);
326
int test_aio_calls (void);
327
int setup_signal_handler (void);
328
int setup_signal_handler (int signal_number);
331
setup_signal_delivery (void)
333
// Make the sigset_t consisting of the completion signal.
334
if (sigemptyset (&completion_signal) == -1)
336
perror ("Error:Couldn't init the RT completion signal set\n");
340
if (sigaddset (&completion_signal, SIGRTMIN) == -1)
342
perror ("Error:Couldn't init the RT completion signal set\n");
347
if (pthread_sigmask (SIG_BLOCK, &completion_signal, 0) == -1)
349
perror ("Error:Couldn't make the RT completion signals\n");
353
return setup_signal_handler (SIGRTMIN);
357
issue_aio_calls (void)
360
aiocb1.aio_fildes = file_handle;
361
aiocb1.aio_offset = 0;
362
aiocb1.aio_buf = mb1;
363
aiocb1.aio_nbytes = BUFSIZ;
364
aiocb1.aio_reqprio = 0;
365
aiocb1.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
366
aiocb1.aio_sigevent.sigev_signo = SIGRTMIN;
367
aiocb1.aio_sigevent.sigev_value.sival_ptr = (void *) &aiocb1;
369
// Fire off the aio write.
370
if (aio_read (&aiocb1) == -1)
373
perror ("Error:Asynch_Read_Stream: aio_read queueing failed\n");
378
aiocb2.aio_fildes = file_handle;
379
aiocb2.aio_offset = BUFSIZ + 1;
380
aiocb2.aio_buf = mb2;
381
aiocb2.aio_nbytes = BUFSIZ;
382
aiocb2.aio_reqprio = 0;
383
aiocb2.aio_sigevent.sigev_notify = SIGEV_SIGNAL;
384
aiocb2.aio_sigevent.sigev_signo = SIGRTMIN;
385
aiocb2.aio_sigevent.sigev_value.sival_ptr = (void *) &aiocb2;
387
// Fire off the aio write.
388
if (aio_read (&aiocb2) == -1)
391
perror ("Error:Asynch_Read_Stream: aio_read queueing failed\n");
398
query_aio_completions (void)
401
size_t number_of_completions = 0;
402
for (number_of_completions = 0;
403
number_of_completions < 2;
404
number_of_completions++)
406
// Wait for <milli_seconds> amount of time.
407
// @@ Assigning <milli_seconds> to tv_sec.
412
// To get back the signal info.
415
// Await the RT completion signal.
416
int sig_return = sigtimedwait (&completion_signal,
421
// If failure is coz of timeout, then return *0* but set
422
// errno appropriately. This is what the WinNT proactor
424
if (sig_return == -1)
426
perror ("Error:Error waiting for RT completion signals\n");
430
// RT completion signals returned.
431
if (sig_return != SIGRTMIN)
433
//printf ("Unexpected signal (%d) has been received while waiting for RT Completion Signals\n",
439
//printf ("Sig number found in the sig_info block : %d\n",
440
// sig_info.si_signo);
442
// Is the signo returned consistent?
443
if (sig_info.si_signo != sig_return)
445
//printf ("Inconsistent signal number (%d) in the signal info block\n",
446
// sig_info.si_signo);
451
//printf ("Signal code for this signal delivery : %d\n",
452
// sig_info.si_code);
454
// Is the signal code an aio completion one?
455
if ((sig_info.si_code != SI_ASYNCIO) &&
456
(sig_info.si_code != SI_QUEUE))
458
//printf ("Unexpected signal code (%d) returned on completion querying\n",
459
// sig_info.si_code);
463
// Retrive the aiocb.
464
aiocb* aiocb_ptr = (aiocb *) sig_info.si_value.sival_ptr;
466
// Analyze error and return values. Return values are
467
// actually <errno>'s associated with the <aio_> call
468
// corresponding to aiocb_ptr.
469
int error_code = aio_error (aiocb_ptr);
470
if (error_code == -1)
472
perror ("Error:Invalid control block was sent to <aio_error> for compleion querying\n");
478
// Error occurred in the <aio_>call. Return the errno
479
// corresponding to that <aio_> call.
480
//printf ("Error:An AIO call has failed:Error code = %d\n",
485
// No error occured in the AIO operation.
486
int nbytes = aio_return (aiocb_ptr);
489
perror ("Error:Invalid control block was sent to <aio_return>\n");
493
//if (number_of_completions == 0)
495
//printf ("Number of bytes transferred : %d\n The buffer : %s \n",
500
//printf ("Number of bytes transferred : %d\n The buffer : %s \n",
508
test_aio_calls (void)
510
// Set up the input file.
511
// Open file (in SEQUENTIAL_SCAN mode)
512
file_handle = open ("test_aiosig.txt", O_RDONLY);
514
if (file_handle == -1)
520
unlink ("test_aiosig.txt"); // Unlink now so we don't have to do so later.
522
if (setup_signal_delivery () < 0)
525
if (issue_aio_calls () < 0)
528
if (query_aio_completions () < 0)
531
if (close (file_handle) != 0)
541
setup_signal_handler (int signal_number)
543
// Setting up the handler(!) for these signals.
544
struct sigaction reaction;
545
sigemptyset (&reaction.sa_mask); // Nothing else to mask.
546
reaction.sa_flags = SA_SIGINFO; // Realtime flag.
547
#if defined (SA_SIGACTION)
548
// Lynx says, it is better to set this bit to be portable.
549
reaction.sa_flags &= SA_SIGACTION;
550
#endif /* SA_SIGACTION */
551
reaction.sa_sigaction = null_handler; // Null handler.
552
int sigaction_return = sigaction (SIGRTMIN,
555
if (sigaction_return == -1)
557
perror ("Error:Proactor couldn't do sigaction for the RT SIGNAL");
565
null_handler (int /* signal_number */,
566
siginfo_t * /* info */,
567
void * /* context */)
574
if (test_aio_calls () == 0)
576
// printf ("RT SIG test successful:\n"
577
// "ACE_POSIX_SIG_PROACTOR should work in this platform\n");
581
//printf ("RT SIG test failed:\n"
582
// "ACE_POSIX_SIG_PROACTOR may not work in this platform\n");
588
ace_cv_feature_aio_calls=yes
591
ace_cv_feature_aio_calls=no
594
dnl Don't bother doing anything for cross-compiling here
595
dnl since the outer run-time test will prevent this
596
dnl inner run-time test from ever running when cross-compiling.
597
dnl We just put something in here to prevent autoconf
598
dnl from complaining.
599
ace_just_a_place_holder=ignoreme
602
ace_cv_feature_aio_calls=no
604
dnl Asynchronous IO test for cross-compiled platforms
605
dnl This test is weaker than the above run-time tests but it will
612
aiocb* aiocb_ptr (void);
615
ace_cv_feature_aio_calls=yes
618
ace_cv_feature_aio_calls=no
621
],[AC_DEFINE([ACE_HAS_AIO_CALLS])],[LIBS="$ace_save_LIBS"])
622
fi dnl test "$ace_has_aio_funcs" = yes