source: trunk/src/kernel32/overlappedio.h@ 7604

Last change on this file since 7604 was 7604, checked in by sandervl, 24 years ago

overlapped io updates & fixes

File size: 4.5 KB
Line 
1/* $Id: overlappedio.h,v 1.8 2001-12-10 12:55:13 sandervl Exp $ */
2
3/*
4 * Win32 overlapped IO class
5 *
6 * Copyright 2001 Sander van Leeuwen <sandervl@xs4all.nl>
7 *
8 * Project Odin Software License can be found in LICENSE.TXT
9 *
10 */
11
12#ifndef __OVERLAPPEDIO_H__
13#define __OVERLAPPEDIO_H__
14
15#define NR_ASYNC_OPERATIONS 4
16#define ASYNC_INDEX_READ 0
17#define ASYNC_INDEX_WRITE 1
18#define ASYNC_INDEX_POLL 2
19#define ASYNC_INDEX_BUSY 3
20
21#define ASYNCIO_READ 1
22#define ASYNCIO_WRITE 2
23#define ASYNCIO_READWRITE 4
24#define ASYNCIO_POLL 8
25
26//forward decl
27class OverlappedIOHandler;
28
29typedef struct {
30 DWORD dwOperation;
31 OverlappedIOHandler *lpOverlappedObj;
32} OVERLAPPED_THREAD_PARAM, *LPOVERLAPPED_THREAD_PARAM;
33
34
35class ASYNCIOREQUEST
36{
37public:
38 ASYNCIOREQUEST()
39 {
40 memset(this, 0, sizeof(ASYNCIOREQUEST));
41 };
42
43 DWORD dwAsyncType;
44 HANDLE hHandle;
45 LPCVOID lpBuffer;
46 DWORD nNumberOfBytes;
47 DWORD dwTimeOut;
48 LPOVERLAPPED lpOverlapped;
49 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine;
50 DWORD *lpdwResult;
51 DWORD dwLastError;
52 DWORD dwEventMask;
53 DWORD dwUserData;
54 BOOL fCancelled;
55 ASYNCIOREQUEST *next;
56};
57
58typedef ASYNCIOREQUEST *LPASYNCIOREQUEST;
59
60typedef DWORD (* LPOVERLAPPED_HANDLER)(LPASYNCIOREQUEST lpRequest, DWORD *lpdwResult, DWORD *lpdwTimeOut);
61
62enum OverlappedIOError {
63 InvalidParameter, OutOfMemory, EventCreationFailed, ThreadCreationFailed
64};
65
66class OverlappedIOHandler
67{
68public:
69 OverlappedIOHandler(LPOVERLAPPED_HANDLER lpReadHandler,
70 LPOVERLAPPED_HANDLER lpWriteHandler,
71 LPOVERLAPPED_HANDLER lpPollHandler = NULL,
72 BOOL fFullDuplex = FALSE);
73 ~OverlappedIOHandler();
74
75 BOOL WriteFile(HANDLE hHandle,
76 LPCVOID lpBuffer,
77 DWORD nNumberOfBytesToWrite,
78 LPDWORD lpNumberOfBytesWritten,
79 LPOVERLAPPED lpOverlapped,
80 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
81 DWORD dwUserData,
82 DWORD dwTimeOut = INFINITE);
83
84 BOOL ReadFile(HANDLE hHandle,
85 LPCVOID lpBuffer,
86 DWORD nNumberOfBytesToRead,
87 LPDWORD lpNumberOfBytesRead,
88 LPOVERLAPPED lpOverlapped,
89 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
90 DWORD dwUserData,
91 DWORD dwTimeOut = INFINITE);
92
93 BOOL WaitForEvent(HANDLE hHandle,
94 DWORD dwEventMask,
95 LPDWORD lpfdwEvtMask,
96 LPOVERLAPPED lpOverlapped,
97 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
98 DWORD dwUserData,
99 DWORD dwTimeOut = INFINITE);
100
101 BOOL CancelIo(HANDLE hHandle);
102
103 BOOL GetOverlappedResult(HANDLE hHandle,
104 LPOVERLAPPED lpoOverlapped,
105 LPDWORD lpcbTransfer,
106 BOOL fWait);
107
108protected:
109
110private:
111 LPASYNCIOREQUEST findAndRemoveRequest(int index, HANDLE hHandle);
112
113 DWORD threadHandler(DWORD fEvent);
114
115 HANDLE hThreadPoll;
116 HANDLE hThreadRead;
117 HANDLE hThreadWrite;
118 HANDLE hEventExit;
119 HANDLE hEventCancel;
120 HANDLE hEventPoll;
121 HANDLE hEventRead;
122 HANDLE hEventWrite;
123
124 LPOVERLAPPED_HANDLER lpReadHandler;
125 LPOVERLAPPED_HANDLER lpWriteHandler;
126 LPOVERLAPPED_HANDLER lpPollHandler;
127
128 CRITICAL_SECTION critsect;
129
130 DWORD dwAsyncType;
131 BOOL fFullDuplex;
132 //[ASYNC_INDEX_READ] list of pending read (+ write if half-duplex mode) operations
133 //[ASYNC_INDEX_WRITE] list of pending write (full-duplex mode) operations
134 //[ASYNC_INDEX_POLL] list of pending poll operations
135 //[ASYNC_INDEX_BUSY] list of operations that are being handled
136 LPASYNCIOREQUEST pending[NR_ASYNC_OPERATIONS];
137
138 friend DWORD CALLBACK OverlappedIOThread(LPVOID lpThreadParam);
139};
140
141
142#endif // __OVERLAPPEDIO_H__
Note: See TracBrowser for help on using the repository browser.