| 1 | /* $Id: async.cpp,v 1.1 1999-05-24 20:19:43 ktk Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * Win32 Asynchronous I/O Subsystem for OS/2 | 
|---|
| 5 | * | 
|---|
| 6 | * 1998/04/10 PH Patrick Haller (haller@zebra.fh-weingarten.de) | 
|---|
| 7 | * | 
|---|
| 8 | * @(#) Async.Cpp       1.0.0   1998/04/10 PH start | 
|---|
| 9 | * | 
|---|
| 10 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 11 | * | 
|---|
| 12 | */ | 
|---|
| 13 |  | 
|---|
| 14 | #ifndef _ASYNCIOSUBSYSTEM_H_ | 
|---|
| 15 | #define _ASYNCIOSUBSYSTEM_H_ | 
|---|
| 16 |  | 
|---|
| 17 |  | 
|---|
| 18 | /***************************************************************************** | 
|---|
| 19 | * Remark                                                                    * | 
|---|
| 20 | ***************************************************************************** | 
|---|
| 21 |  | 
|---|
| 22 | ReadFileEx | 
|---|
| 23 |  | 
|---|
| 24 | */ | 
|---|
| 25 |  | 
|---|
| 26 |  | 
|---|
| 27 |  | 
|---|
| 28 | /***************************************************************************** | 
|---|
| 29 | * Includes                                                                  * | 
|---|
| 30 | *****************************************************************************/ | 
|---|
| 31 |  | 
|---|
| 32 | #define  INCL_WIN | 
|---|
| 33 | #define  INCL_DOSMEMMGR | 
|---|
| 34 | #define  INCL_DOSSEMAPHORES | 
|---|
| 35 | #define  INCL_DOSERRORS | 
|---|
| 36 | #define  INCL_DOSPROCESS | 
|---|
| 37 | #define  INCL_DOSMODULEMGR | 
|---|
| 38 | #define  INCL_VIO | 
|---|
| 39 | #define  INCL_AVIO | 
|---|
| 40 | #include <os2.h> | 
|---|
| 41 | #include <builtin.h> | 
|---|
| 42 |  | 
|---|
| 43 | #include <stdlib.h> | 
|---|
| 44 | #include <string.h> | 
|---|
| 45 | #include "win32type.h" | 
|---|
| 46 | #include "misc.h" | 
|---|
| 47 | #include "unicode.h" | 
|---|
| 48 | #include "handlemanager.h" | 
|---|
| 49 |  | 
|---|
| 50 |  | 
|---|
| 51 | /***************************************************************************** | 
|---|
| 52 | * Defines & Macros                                                          * | 
|---|
| 53 | *****************************************************************************/ | 
|---|
| 54 |  | 
|---|
| 55 |  | 
|---|
| 56 | /***************************************************************************** | 
|---|
| 57 | * Structures                                                                * | 
|---|
| 58 | *****************************************************************************/ | 
|---|
| 59 |  | 
|---|
| 60 | typedef struct _IORequest | 
|---|
| 61 | { | 
|---|
| 62 | struct _IORequest *pNext;                   /* pointer to next I/O request */ | 
|---|
| 63 |  | 
|---|
| 64 | APIRET rc;                                   /* result code of I/O request */ | 
|---|
| 65 |  | 
|---|
| 66 | } IOREQUEST, *PIOREQUEST; | 
|---|
| 67 |  | 
|---|
| 68 |  | 
|---|
| 69 | typedef struct _Globals | 
|---|
| 70 | { | 
|---|
| 71 | HEV hevIOEvent;                      /* asynchronous I/O event completed ! */ | 
|---|
| 72 | TID tidIO;                           /* I/O thread                         */ | 
|---|
| 73 | } GLOBALS, *PGLOBALS; | 
|---|
| 74 |  | 
|---|
| 75 | static GLOBALS Globals; | 
|---|
| 76 |  | 
|---|
| 77 |  | 
|---|
| 78 | /***************************************************************************** | 
|---|
| 79 | * Name      : | 
|---|
| 80 | * Purpose   : | 
|---|
| 81 | * Parameters: | 
|---|
| 82 | * Variables : | 
|---|
| 83 | * Result    : | 
|---|
| 84 | * Remark    : | 
|---|
| 85 | * Status    : | 
|---|
| 86 | * | 
|---|
| 87 | * Author    : Patrick Haller [Tue, 1998/02/10 01:55] | 
|---|
| 88 | *****************************************************************************/ | 
|---|
| 89 |  | 
|---|
| 90 | DWORD WIN32API SleepEx(DWORD dwTimeout, | 
|---|
| 91 | BOOL  fAlertable) | 
|---|
| 92 | { | 
|---|
| 93 |  | 
|---|
| 94 | dprintf(("KERNEL32:  SleepEx(%u,%u)\n", | 
|---|
| 95 | dwTimeout, | 
|---|
| 96 | fAlertable)); | 
|---|
| 97 |  | 
|---|
| 98 | /* @@@PH could be implemented as a timed wait on a event semaphore */ | 
|---|
| 99 | /*       for the WAIT_IO_COMPLETION flag                           */ | 
|---|
| 100 |  | 
|---|
| 101 | if (fAlertable == FALSE) | 
|---|
| 102 | DosSleep(dwTimeout); | 
|---|
| 103 | else { | 
|---|
| 104 | dprintf(("SleepEx: Wait for io completion not supported!")); | 
|---|
| 105 | DosSleep(1); | 
|---|
| 106 | } | 
|---|
| 107 |  | 
|---|
| 108 | return (0); | 
|---|
| 109 | } | 
|---|
| 110 |  | 
|---|
| 111 |  | 
|---|
| 112 | /***************************************************************************** | 
|---|
| 113 | * Name      : BOOL ReadFileEx | 
|---|
| 114 | * Purpose   : The ReadFileEx function reads data from a file asynchronously. | 
|---|
| 115 | *             It is designed solely for asynchronous operation, unlike the | 
|---|
| 116 | *             ReadFile function, which is designed for both synchronous and | 
|---|
| 117 | *             asynchronous operation. ReadFileEx lets an application perform | 
|---|
| 118 | *             other processing during a file read operation. | 
|---|
| 119 | *             The ReadFileEx function reports its completion status asynchronously, | 
|---|
| 120 | *             calling a specified completion routine when reading is completed | 
|---|
| 121 | *             and the calling thread is in an alertable wait state. | 
|---|
| 122 | * Parameters: HANDLE       hFile                handle of file to read | 
|---|
| 123 | *             LPVOID       lpBuffer             address of buffer | 
|---|
| 124 | *             DWORD        nNumberOfBytesToRead number of bytes to read | 
|---|
| 125 | *             LPOVERLAPPED lpOverlapped         address of offset | 
|---|
| 126 | *             LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine | 
|---|
| 127 | * Variables : | 
|---|
| 128 | * Result    : TRUE / FALSE | 
|---|
| 129 | * Remark    : | 
|---|
| 130 | * Status    : UNTESTED STUB | 
|---|
| 131 | * | 
|---|
| 132 | * Author    : Patrick Haller [Mon, 1998/06/15 08:00] | 
|---|
| 133 | *****************************************************************************/ | 
|---|
| 134 |  | 
|---|
| 135 | #define LPOVERLAPPED_COMPLETION_ROUTINE LPVOID | 
|---|
| 136 |  | 
|---|
| 137 | DWORD WIN32API ReadFileEx(HANDLE       hFile, | 
|---|
| 138 | LPVOID       lpBuffer, | 
|---|
| 139 | DWORD        nNumberOfBytesToRead, | 
|---|
| 140 | LPOVERLAPPED lpOverlapped, | 
|---|
| 141 | LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine) | 
|---|
| 142 | { | 
|---|
| 143 | dprintf(("Kernel32: ReadFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n", | 
|---|
| 144 | hFile, | 
|---|
| 145 | lpBuffer, | 
|---|
| 146 | nNumberOfBytesToRead, | 
|---|
| 147 | lpOverlapped, | 
|---|
| 148 | lpCompletionRoutine)); | 
|---|
| 149 |  | 
|---|
| 150 |  | 
|---|
| 151 | return (FALSE); | 
|---|
| 152 | } | 
|---|
| 153 |  | 
|---|
| 154 |  | 
|---|
| 155 | /***************************************************************************** | 
|---|
| 156 | * Name      : BOOL WriteFileEx | 
|---|
| 157 | * Purpose   : The WriteFileEx function writes data to a file. It is designed | 
|---|
| 158 | *             solely for asynchronous operation, unlike WriteFile, which is | 
|---|
| 159 | *             designed for both synchronous and asynchronous operation. | 
|---|
| 160 | *             WriteFileEx reports its completion status asynchronously, | 
|---|
| 161 | *             calling a specified completion routine when writing is completed | 
|---|
| 162 | *             and the calling thread is in an alertable wait state. | 
|---|
| 163 | * Parameters: HANDLE       hFile                handle of file to write | 
|---|
| 164 | *             LPVOID       lpBuffer             address of buffer | 
|---|
| 165 | *             DWORD        nNumberOfBytesToRead number of bytes to write | 
|---|
| 166 | *             LPOVERLAPPED lpOverlapped         address of offset | 
|---|
| 167 | *             LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine address of completion routine | 
|---|
| 168 | * Variables : | 
|---|
| 169 | * Result    : TRUE / FALSE | 
|---|
| 170 | * Remark    : | 
|---|
| 171 | * Status    : UNTESTED STUB | 
|---|
| 172 | * | 
|---|
| 173 | * Author    : Patrick Haller [Mon, 1998/06/15 08:00] | 
|---|
| 174 | *****************************************************************************/ | 
|---|
| 175 |  | 
|---|
| 176 | DWORD WIN32API WriteFileEx(HANDLE       hFile, | 
|---|
| 177 | LPVOID       lpBuffer, | 
|---|
| 178 | DWORD        nNumberOfBytesToWrite, | 
|---|
| 179 | LPOVERLAPPED lpOverlapped, | 
|---|
| 180 | LPOVERLAPPED_COMPLETION_ROUTINE  lpCompletionRoutine) | 
|---|
| 181 | { | 
|---|
| 182 | dprintf(("Kernel32: WriteFileEx(%08xh,%08xh,%08xh,%08xh,%08xh) not implemented.\n", | 
|---|
| 183 | hFile, | 
|---|
| 184 | lpBuffer, | 
|---|
| 185 | nNumberOfBytesToWrite, | 
|---|
| 186 | lpOverlapped, | 
|---|
| 187 | lpCompletionRoutine)); | 
|---|
| 188 |  | 
|---|
| 189 |  | 
|---|
| 190 | return (FALSE); | 
|---|
| 191 | } | 
|---|
| 192 |  | 
|---|
| 193 |  | 
|---|
| 194 | #endif /* _ASYNCIOSUBSYSTEM_H_ */ | 
|---|