summaryrefslogtreecommitdiff
path: root/examples/Reactor/Proactor/Aio_Platform_Test_C.cpp
blob: f68d91e7b6ed65406e5961300e1c94c99c65a933 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// $Id$
// ============================================================================
//
// = FILENAME
//    aio_platform_test_c.cpp
//
// =  DESCRITPTION
//     Testing the platform for POSIX Asynchronous I/O. This is the C
//     version of the  $ACE_ROOT/tests/Aio_Platform_Test.cpp. Useful
//     to send bug reports.
//
// = AUTHOR
//    Programming for the Real World. Bill O. GallMeister.
//    Modified by Alexander Babu Arulanthu <alex@cs.wustl.edu>
//
// =====================================================================


#include <unistd.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <signal.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>

#include <limits.h>

#include <aio.h>

int do_sysconf (void);
int have_asynchio (void);

static int file_handle = -1;
char mb1 [BUFSIZ + 1];
char mb2 [BUFSIZ + 1];
aiocb aiocb1, aiocb2;
sigset_t completion_signal;

// For testing the <aio> stuff.
int test_aio_calls (void);
int issue_aio_calls (void);
int query_aio_completions (void);
int setup_signal_delivery (void);
int do_sysconf (void);
int have_asynchio (void);
  
int
do_sysconf (void)
{
  // Call sysconf to find out runtime values.
  errno = 0;
#if defined (_SC_LISTIO_AIO_MAX)
  printf ("Runtime value of LISTIO_AIO_MAX is %d, errno = %d\n",
          sysconf(_SC_LISTIO_AIO_MAX),
          errno);
#else
  printf ("Runtime value of AIO_LISTIO_MAX is %d, errno = %d\n",
          sysconf(_SC_AIO_LISTIO_MAX),
          errno);
#endif  
  
  errno = 0;
  printf ("Runtime value of AIO_MAX is %d, errno = %d\n",
          sysconf (_SC_AIO_MAX),
          errno);

  errno = 0;
  printf ("Runtime value of _POSIX_ASYNCHRONOUS_IO is %d, errno = %d\n",
          sysconf (_SC_ASYNCHRONOUS_IO),
          errno);

  errno = 0;
  printf ("Runtime value of _POSIX_REALTIME_SIGNALS is %d, errno = %d\n",
          sysconf (_SC_REALTIME_SIGNALS),
          errno);

  errno = 0;
  printf ("Runtime value of RTSIG_MAX %d, Errno = %d\n",
          sysconf (_SC_RTSIG_MAX), 
          errno);
  
  errno = 0;
  printf ("Runtime value of SIGQUEUE_MAX %d, Errno = %d\n",
          sysconf (_SC_SIGQUEUE_MAX),
          errno); 
  return 0;
}

int
have_asynchio (void)
{
#if defined (_POSIX_ASYNCHRONOUS_IO)
  // POSIX Asynch IO is present in this system.
#if defined (_POSIX_ASYNC_IO)
  // If this is defined and it is not -1, POSIX_ASYNCH is supported
  // everywhere in the system.
#if _POSIX_ASYNC_IO == -1
  printf ("_POSIX_ASYNC_IO = -1.. ASYNCH IO NOT supported at all\n");
  return -1;
#else /* Not _POSIX_ASYNC_IO == -1 */
  printf ("_POSIX_ASYNC_IO = %d\n ASYNCH IO is supported FULLY\n",
          _POSIX_ASYNC_IO);
#endif /* _POSIX_ASYNC_IO == -1 */
  
#else  /* Not defined  _POSIX_ASYNC_IO */
  printf ("_POSIX_ASYNC_IO is not defined.\n");
  printf ("AIO might *not* be supported on some paths\n");
#endif /* _POSIX_ASYNC_IO */
  
  // System defined POSIX Values.
  printf ("System claims to have  POSIX_ASYNCHRONOUS_IO\n");

  printf ("_POSIX_AIO_LISTIO_MAX = %d\n", _POSIX_AIO_LISTIO_MAX);
  printf ("_POSIX_AIO_MAX = %d\n", _POSIX_AIO_MAX);

  // Check and print the run time values.
  do_sysconf ();
  
  return 0;
  
#else /* Not _POSIX_ASYNCHRONOUS_IO */
  printf ("No support._POSIX_ASYNCHRONOUS_IO itself is not defined\n");
  return -1;
#endif /* _POSIX_ASYNCHRONOUS_IO */  
}

int
ACE_TMAIN (int, ACE_TCHAR *[])
{
  if (have_asynchio () == 0)
    printf ("Test successful\n");
  else
    printf ("Test not successful\n");
  return 0;
}