Back to index

glibc  2.9
aio.h
Go to the documentation of this file.
00001 /* Copyright (C) 1996-2000,2003,2004,2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 /*
00020  * ISO/IEC 9945-1:1996 6.7: Asynchronous Input and Output
00021  */
00022 
00023 #ifndef _AIO_H
00024 #define _AIO_H       1
00025 
00026 #include <features.h>
00027 #include <fcntl.h>
00028 #include <signal.h>
00029 #include <time.h>
00030 #include <sys/types.h>
00031 
00032 __BEGIN_DECLS
00033 
00034 /* Asynchronous I/O control block.  */
00035 struct aiocb
00036 {
00037   int aio_fildes;           /* File desriptor.  */
00038   int aio_lio_opcode;              /* Operation to be performed.  */
00039   int aio_reqprio;          /* Request priority offset.  */
00040   volatile void *aio_buf;   /* Location of buffer.  */
00041   size_t aio_nbytes;        /* Length of transfer.  */
00042   struct sigevent aio_sigevent;    /* Signal number and value.  */
00043 
00044   /* Internal members.  */
00045   struct aiocb *__next_prio;
00046   int __abs_prio;
00047   int __policy;
00048   int __error_code;
00049   __ssize_t __return_value;
00050 
00051 #ifndef __USE_FILE_OFFSET64
00052   __off_t aio_offset;              /* File offset.  */
00053   char __pad[sizeof (__off64_t) - sizeof (__off_t)];
00054 #else
00055   __off64_t aio_offset;            /* File offset.  */
00056 #endif
00057   char __unused[32];
00058 };
00059 
00060 /* The same for the 64bit offsets.  Please note that the members aio_fildes
00061    to __return_value have to be the same in aiocb and aiocb64.  */
00062 #ifdef __USE_LARGEFILE64
00063 struct aiocb64
00064 {
00065   int aio_fildes;           /* File desriptor.  */
00066   int aio_lio_opcode;              /* Operation to be performed.  */
00067   int aio_reqprio;          /* Request priority offset.  */
00068   volatile void *aio_buf;   /* Location of buffer.  */
00069   size_t aio_nbytes;        /* Length of transfer.  */
00070   struct sigevent aio_sigevent;    /* Signal number and value.  */
00071 
00072   /* Internal members.  */
00073   struct aiocb *__next_prio;
00074   int __abs_prio;
00075   int __policy;
00076   int __error_code;
00077   __ssize_t __return_value;
00078 
00079   __off64_t aio_offset;            /* File offset.  */
00080   char __unused[32];
00081 };
00082 #endif
00083 
00084 
00085 #ifdef __USE_GNU
00086 /* To customize the implementation one can use the following struct.
00087    This implementation follows the one in Irix.  */
00088 struct aioinit
00089   {
00090     int aio_threads;        /* Maximal number of threads.  */
00091     int aio_num;            /* Number of expected simultanious requests. */
00092     int aio_locks;          /* Not used.  */
00093     int aio_usedba;         /* Not used.  */
00094     int aio_debug;          /* Not used.  */
00095     int aio_numusers;              /* Not used.  */
00096     int aio_idle_time;             /* Number of seconds before idle thread
00097                                terminates.  */
00098     int aio_reserved;
00099   };
00100 #endif
00101 
00102 
00103 /* Return values of cancelation function.  */
00104 enum
00105 {
00106   AIO_CANCELED,
00107 #define AIO_CANCELED AIO_CANCELED
00108   AIO_NOTCANCELED,
00109 #define AIO_NOTCANCELED AIO_NOTCANCELED
00110   AIO_ALLDONE
00111 #define AIO_ALLDONE AIO_ALLDONE
00112 };
00113 
00114 
00115 /* Operation codes for `aio_lio_opcode'.  */
00116 enum
00117 {
00118   LIO_READ,
00119 #define LIO_READ LIO_READ
00120   LIO_WRITE,
00121 #define LIO_WRITE LIO_WRITE
00122   LIO_NOP
00123 #define LIO_NOP LIO_NOP
00124 };
00125 
00126 
00127 /* Synchronization options for `lio_listio' function.  */
00128 enum
00129 {
00130   LIO_WAIT,
00131 #define LIO_WAIT LIO_WAIT
00132   LIO_NOWAIT
00133 #define LIO_NOWAIT LIO_NOWAIT
00134 };
00135 
00136 
00137 /* Allow user to specify optimization.  */
00138 #ifdef __USE_GNU
00139 extern void aio_init (__const struct aioinit *__init) __THROW __nonnull ((1));
00140 #endif
00141 
00142 
00143 #ifndef __USE_FILE_OFFSET64
00144 /* Enqueue read request for given number of bytes and the given priority.  */
00145 extern int aio_read (struct aiocb *__aiocbp) __THROW __nonnull ((1));
00146 /* Enqueue write request for given number of bytes and the given priority.  */
00147 extern int aio_write (struct aiocb *__aiocbp) __THROW __nonnull ((1));
00148 
00149 /* Initiate list of I/O requests.  */
00150 extern int lio_listio (int __mode,
00151                      struct aiocb *__const __list[__restrict_arr],
00152                      int __nent, struct sigevent *__restrict __sig)
00153   __THROW __nonnull ((2));
00154 
00155 /* Retrieve error status associated with AIOCBP.  */
00156 extern int aio_error (__const struct aiocb *__aiocbp) __THROW __nonnull ((1));
00157 /* Return status associated with AIOCBP.  */
00158 extern __ssize_t aio_return (struct aiocb *__aiocbp) __THROW __nonnull ((1));
00159 
00160 /* Try to cancel asynchronous I/O requests outstanding against file
00161    descriptor FILDES.  */
00162 extern int aio_cancel (int __fildes, struct aiocb *__aiocbp) __THROW;
00163 
00164 /* Suspend calling thread until at least one of the asynchronous I/O
00165    operations referenced by LIST has completed.
00166 
00167    This function is a cancellation point and therefore not marked with
00168    __THROW.  */
00169 extern int aio_suspend (__const struct aiocb *__const __list[], int __nent,
00170                      __const struct timespec *__restrict __timeout)
00171   __nonnull ((1));
00172 
00173 /* Force all operations associated with file desriptor described by
00174    `aio_fildes' member of AIOCBP.  */
00175 extern int aio_fsync (int __operation, struct aiocb *__aiocbp)
00176   __THROW __nonnull ((2));
00177 #else
00178 # ifdef __REDIRECT_NTH
00179 extern int __REDIRECT_NTH (aio_read, (struct aiocb *__aiocbp), aio_read64)
00180   __nonnull ((1));
00181 extern int __REDIRECT_NTH (aio_write, (struct aiocb *__aiocbp), aio_write64)
00182   __nonnull ((1));
00183 
00184 extern int __REDIRECT_NTH (lio_listio,
00185                         (int __mode,
00186                          struct aiocb *__const __list[__restrict_arr],
00187                          int __nent, struct sigevent *__restrict __sig),
00188                         lio_listio64) __nonnull ((2));
00189 
00190 extern int __REDIRECT_NTH (aio_error, (__const struct aiocb *__aiocbp),
00191                         aio_error64) __nonnull ((1));
00192 extern __ssize_t __REDIRECT_NTH (aio_return, (struct aiocb *__aiocbp),
00193                              aio_return64) __nonnull ((1));
00194 
00195 extern int __REDIRECT_NTH (aio_cancel,
00196                         (int __fildes, struct aiocb *__aiocbp),
00197                         aio_cancel64);
00198 
00199 extern int __REDIRECT_NTH (aio_suspend,
00200                         (__const struct aiocb *__const __list[], int __nent,
00201                          __const struct timespec *__restrict __timeout),
00202                         aio_suspend64) __nonnull ((1));
00203 
00204 extern int __REDIRECT_NTH (aio_fsync,
00205                         (int __operation, struct aiocb *__aiocbp),
00206                         aio_fsync64) __nonnull ((2));
00207 
00208 # else
00209 #  define aio_read aio_read64
00210 #  define aio_write aio_write64
00211 #  define lio_listio lio_listio64
00212 #  define aio_error aio_error64
00213 #  define aio_return aio_return64
00214 #  define aio_cancel aio_cancel64
00215 #  define aio_suspend aio_suspend64
00216 #  define aio_fsync aio_fsync64
00217 # endif
00218 #endif
00219 
00220 #ifdef __USE_LARGEFILE64
00221 extern int aio_read64 (struct aiocb64 *__aiocbp) __THROW __nonnull ((1));
00222 extern int aio_write64 (struct aiocb64 *__aiocbp) __THROW __nonnull ((1));
00223 
00224 extern int lio_listio64 (int __mode,
00225                       struct aiocb64 *__const __list[__restrict_arr],
00226                       int __nent, struct sigevent *__restrict __sig)
00227   __THROW __nonnull ((2));
00228 
00229 extern int aio_error64 (__const struct aiocb64 *__aiocbp)
00230   __THROW __nonnull ((1));
00231 extern __ssize_t aio_return64 (struct aiocb64 *__aiocbp)
00232   __THROW __nonnull ((1));
00233 
00234 extern int aio_cancel64 (int __fildes, struct aiocb64 *__aiocbp) __THROW;
00235 
00236 extern int aio_suspend64 (__const struct aiocb64 *__const __list[], int __nent,
00237                        __const struct timespec *__restrict __timeout)
00238   __THROW __nonnull ((1));
00239 
00240 extern int aio_fsync64 (int __operation, struct aiocb64 *__aiocbp)
00241   __THROW __nonnull ((2));
00242 #endif
00243 
00244 __END_DECLS
00245 
00246 #endif /* aio.h */