00001 /* 00002 Copyright 2003 by Marc J. Rochkind. All rights reserved. 00003 May be copied only for purposes and under conditions described 00004 on the Web page www.basepath.com/aup/copyright.htm. 00005 00006 The Example Files are provided "as is," without any warranty; 00007 without even the implied warranty of merchantability or fitness 00008 for a particular purpose. The author and his publisher are not 00009 responsible for any damages, direct or incidental, resulting 00010 from the use or non-use of these Example Files. 00011 00012 The Example Files may contain defects, and some contain deliberate 00013 coding mistakes that were included for educational reasons. 00014 You are responsible for determining if and how the Example Files 00015 are to be used. 00016 00017 */ 00018 #include "ux.hpp" 00019 00020 using namespace Ux; 00021 00022 /** 00023 Calls aio_cancel. 00024 */ 00025 int Aio::cancel(int fd) 00026 { 00027 #if _POSIX_ASYNCHRONOUS_IO > 0 00028 int r; 00029 00030 if ((r = ::aio_cancel(fd, this)) == -1) 00031 throw Error(errno); 00032 return r; 00033 #else 00034 throw Error(ENOSYS); 00035 #endif 00036 } 00037 00038 /** 00039 Calls aio_error. 00040 */ 00041 int Aio::error(void) 00042 { 00043 #if _POSIX_ASYNCHRONOUS_IO > 0 00044 return ::aio_error(this); 00045 #else 00046 throw Error(ENOSYS); 00047 #endif 00048 } 00049 00050 /** 00051 Calls aio_fsync. 00052 */ 00053 void Aio::sync(int op) 00054 { 00055 #if _POSIX_ASYNCHRONOUS_IO > 0 00056 if (::aio_fsync(op, this) == -1) 00057 throw Error(errno); 00058 #else 00059 throw Error(ENOSYS); 00060 #endif 00061 } 00062 00063 /** 00064 Calls aio_read. 00065 */ 00066 void Aio::read(void) 00067 { 00068 #if _POSIX_ASYNCHRONOUS_IO > 0 00069 if (::aio_read(this) == -1) 00070 throw Error(errno); 00071 #else 00072 throw Error(ENOSYS); 00073 #endif 00074 } 00075 00076 /** 00077 Calls aio_return. 00078 */ 00079 ssize_t Aio::return_status(void) 00080 { 00081 #if _POSIX_ASYNCHRONOUS_IO > 0 00082 ssize_t r; 00083 00084 if ((r = ::aio_return(this)) == -1) 00085 throw Error(errno); 00086 return r; 00087 #else 00088 throw Error(ENOSYS); 00089 #endif 00090 } 00091 00092 /** 00093 Calls aio_suspend. 00094 */ 00095 /* static */ void Aio::suspend(const struct aiocb *const list[], int cbcnt, 00096 const struct timespec *timeout) 00097 { 00098 #if _POSIX_ASYNCHRONOUS_IO > 0 00099 if (::aio_suspend(list, cbcnt, timeout) == -1) 00100 throw Error(errno); 00101 #else 00102 throw Error(ENOSYS); 00103 #endif 00104 } 00105 00106 /** 00107 Calls aio_write. 00108 */ 00109 void Aio::write(void) 00110 { 00111 #if _POSIX_ASYNCHRONOUS_IO > 0 00112 if (::aio_write(this) == -1) 00113 throw Error(errno); 00114 #else 00115 throw Error(ENOSYS); 00116 #endif 00117 } 00118 00119 /** 00120 Calls lio_listio. 00121 */ 00122 /* static */ void Aio::listio(int mode, struct aiocb *const list[], 00123 int cbcnt, struct sigevent *sig) 00124 { 00125 #if _POSIX_ASYNCHRONOUS_IO > 0 00126 if (::lio_listio(mode, list, cbcnt, sig) == -1) 00127 throw Error(errno); 00128 #else 00129 throw Error(ENOSYS); 00130 #endif 00131 }