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

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

overlapped io updates

File size: 3.8 KB
Line 
1/* $Id: overlappedio.h,v 1.4 2001-12-06 15:57:52 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 3
16#define ASYNC_INDEX_READ 0
17#define ASYNC_INDEX_WRITE 1
18#define ASYNC_INDEX_POLL 2
19
20#define ASYNCIO_READ 1
21#define ASYNCIO_WRITE 2
22#define ASYNCIO_READWRITE 4
23#define ASYNCIO_POLL 8
24
25//forward decl
26class OverlappedIOHandler;
27
28typedef struct {
29 DWORD dwOperation;
30 OverlappedIOHandler *lpOverlappedObj;
31} OVERLAPPED_THREAD_PARAM, *LPOVERLAPPED_THREAD_PARAM;
32
33typedef struct tagOVERLAPPED_ODIN{
34 DWORD dwAsyncType;
35 HANDLE hHandle;
36 LPCVOID lpBuffer;
37 ULONG nNumberOfBytes;
38 LPOVERLAPPED lpOverlapped;
39 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine;
40 DWORD *lpdwResult;
41 DWORD dwLastError;
42 DWORD dwUserData;
43 tagOVERLAPPED_ODIN *next;
44} ASYNCIOREQUEST, *LPASYNCIOREQUEST;
45
46typedef BOOL (* SYSTEM LPOVERLAPPED_HANDLER)(LPASYNCIOREQUEST lpRequest, DWORD *lpdwResult, DWORD *lpdwTimeOut);
47
48enum OverlappedIOError {
49 InvalidParameter, OutOfMemory, EventCreationFailed, ThreadCreationFailed
50};
51
52class OverlappedIOHandler
53{
54public:
55 OverlappedIOHandler(LPOVERLAPPED_HANDLER lpReadHandler,
56 LPOVERLAPPED_HANDLER lpWriteHandler,
57 LPOVERLAPPED_HANDLER lpPollHandler = NULL);
58 ~OverlappedIOHandler();
59
60 BOOL WriteFile(HANDLE hHandle,
61 LPCVOID lpBuffer,
62 DWORD nNumberOfBytesToWrite,
63 LPDWORD lpNumberOfBytesWritten,
64 LPOVERLAPPED lpOverlapped,
65 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
66 DWORD dwUserData);
67
68 BOOL ReadFile(HANDLE hHandle,
69 LPCVOID lpBuffer,
70 DWORD nNumberOfBytesToRead,
71 LPDWORD lpNumberOfBytesRead,
72 LPOVERLAPPED lpOverlapped,
73 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
74 DWORD dwUserData);
75
76 BOOL WaitForEvent(HANDLE hHandle,
77 LPDWORD lpfdwEvtMask,
78 LPOVERLAPPED lpOverlapped,
79 LPOVERLAPPED_COMPLETION_ROUTINE lpCompletionRoutine,
80 DWORD dwUserData);
81
82 BOOL CancelIo(HANDLE hHandle);
83
84 BOOL GetOverlappedResult(HANDLE hHandle,
85 LPOVERLAPPED lpoOverlapped,
86 LPDWORD lpcbTransfer,
87 DWORD dwTimeout);
88
89protected:
90
91private:
92 LPASYNCIOREQUEST findAndRemoveRequest(int index, HANDLE hHandle);
93
94 DWORD threadHandler(DWORD fEvent);
95
96 HANDLE hThreadPoll;
97 HANDLE hThreadRead;
98 HANDLE hThreadWrite;
99 HANDLE hEventExit;
100 HANDLE hEventPoll;
101 HANDLE hEventRead;
102 HANDLE hEventWrite;
103
104 LPOVERLAPPED_HANDLER lpReadHandler;
105 LPOVERLAPPED_HANDLER lpWriteHandler;
106 LPOVERLAPPED_HANDLER lpPollHandler;
107
108 CRITICAL_SECTION critsect;
109
110 DWORD dwAsyncType;
111 //[ASYNC_INDEX_READ] list of pending read (+ write if half-duplex mode) operations
112 //[ASYNC_INDEX_WRITE] list of pending write (full-duplex mode) operations
113 //[ASYNC_INDEX_POLL] list of pending poll operations
114 LPASYNCIOREQUEST pending[NR_ASYNC_OPERATIONS];
115
116 friend DWORD CALLBACK OverlappedIOThread(LPVOID lpThreadParam);
117};
118
119
120#endif // __OVERLAPPEDIO_H__
Note: See TracBrowser for help on using the repository browser.