ReactOS  0.4.14-dev-98-gb0d4763
iocompl.c File Reference
#include <k32.h>
#include <debug.h>
Include dependency graph for iocompl.c:

Go to the source code of this file.

Macros

#define NDEBUG
 
#define FILE_SKIP_COMPLETION_PORT_ON_SUCCESS   0x1
 
#define FILE_SKIP_SET_EVENT_ON_HANDLE   0x2
 

Functions

BOOL WINAPI SetFileCompletionNotificationModes (IN HANDLE FileHandle, IN UCHAR Flags)
 
HANDLE WINAPI CreateIoCompletionPort (IN HANDLE FileHandle, IN HANDLE ExistingCompletionPort, IN ULONG_PTR CompletionKey, IN DWORD NumberOfConcurrentThreads)
 
BOOL WINAPI GetQueuedCompletionStatus (IN HANDLE CompletionHandle, IN LPDWORD lpNumberOfBytesTransferred, OUT PULONG_PTR lpCompletionKey, OUT LPOVERLAPPED *lpOverlapped, IN DWORD dwMilliseconds)
 
BOOL WINAPI PostQueuedCompletionStatus (IN HANDLE CompletionHandle, IN DWORD dwNumberOfBytesTransferred, IN ULONG_PTR dwCompletionKey, IN LPOVERLAPPED lpOverlapped)
 
BOOL WINAPI GetOverlappedResult (IN HANDLE hFile, IN LPOVERLAPPED lpOverlapped, OUT LPDWORD lpNumberOfBytesTransferred, IN BOOL bWait)
 
BOOL WINAPI BindIoCompletionCallback (IN HANDLE FileHandle, IN LPOVERLAPPED_COMPLETION_ROUTINE Function, IN ULONG Flags)
 

Macro Definition Documentation

◆ FILE_SKIP_COMPLETION_PORT_ON_SUCCESS

#define FILE_SKIP_COMPLETION_PORT_ON_SUCCESS   0x1

Definition at line 21 of file iocompl.c.

◆ FILE_SKIP_SET_EVENT_ON_HANDLE

#define FILE_SKIP_SET_EVENT_ON_HANDLE   0x2

Definition at line 22 of file iocompl.c.

◆ NDEBUG

#define NDEBUG

Definition at line 12 of file iocompl.c.

Function Documentation

◆ BindIoCompletionCallback()

BOOL WINAPI BindIoCompletionCallback ( IN HANDLE  FileHandle,
IN LPOVERLAPPED_COMPLETION_ROUTINE  Function,
IN ULONG  Flags 
)

Definition at line 260 of file iocompl.c.

263 {
265 
266  /* Call RTL */
269  Flags);
270  if (!NT_SUCCESS(Status))
271  {
272  /* Set error and fail */
274  return FALSE;
275  }
276 
277  /* Return success */
278  return TRUE;
279 }
#define TRUE
Definition: types.h:120
VOID(* PIO_APC_ROUTINE)(IN PVOID ApcContext, IN PIO_STATUS_BLOCK IoStatusBlock, IN ULONG Reserved)
Definition: nt_native.h:877
LONG NTSTATUS
Definition: precomp.h:26
HANDLE FileHandle
Definition: stats.c:38
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
static LPOVERLAPPED_COMPLETION_ROUTINE Function
Definition: sync.c:684
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSYSAPI NTSTATUS NTAPI RtlSetIoCompletionCallback(_In_ HANDLE FileHandle, _In_ PIO_APC_ROUTINE Callback, _In_ ULONG Flags)
Status
Definition: gdiplustypes.h:24

◆ CreateIoCompletionPort()

HANDLE WINAPI CreateIoCompletionPort ( IN HANDLE  FileHandle,
IN HANDLE  ExistingCompletionPort,
IN ULONG_PTR  CompletionKey,
IN DWORD  NumberOfConcurrentThreads 
)

Definition at line 48 of file iocompl.c.

52 {
54  HANDLE NewPort;
55  FILE_COMPLETION_INFORMATION CompletionInformation;
57 
58  /* Check if this is a new port */
59  NewPort = ExistingCompletionPort;
60  if (!ExistingCompletionPort)
61  {
62  /* Create it */
63  Status = NtCreateIoCompletion(&NewPort,
65  NULL,
66  NumberOfConcurrentThreads);
67  if (!NT_SUCCESS(Status))
68  {
69  /* Convert error and fail */
71  return FALSE;
72  }
73  }
74 
75  /* Check if no actual file is being associated with the completion port */
77  {
78  /* Was there a port already associated? */
79  if (ExistingCompletionPort)
80  {
81  /* You are not allowed using an old port and dropping the handle */
82  NewPort = NULL;
84  }
85  }
86  else
87  {
88  /* We have a file handle, so associated it with this completion port */
89  CompletionInformation.Port = NewPort;
90  CompletionInformation.Key = (PVOID)CompletionKey;
93  &CompletionInformation,
96  if (!NT_SUCCESS(Status))
97  {
98  /* Convert the error code and close the newly created port, if any */
100  if (!ExistingCompletionPort) NtClose(NewPort);
101  return FALSE;
102  }
103  }
104 
105  /* Return the newly created port, if any */
106  return NewPort;
107 }
#define IO_COMPLETION_ALL_ACCESS
Definition: file.c:72
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
HANDLE FileHandle
Definition: stats.c:38
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
void * PVOID
Definition: retypes.h:9
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtClose(IN HANDLE Handle)
Definition: obhandle.c:3399
Status
Definition: gdiplustypes.h:24
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
NTSTATUS NTAPI NtCreateIoCompletion(OUT PHANDLE IoCompletionHandle, IN ACCESS_MASK DesiredAccess, IN POBJECT_ATTRIBUTES ObjectAttributes, IN ULONG NumberOfConcurrentThreads)
Definition: iocomp.c:253
NTSYSAPI NTSTATUS NTAPI NtSetInformationFile(IN HANDLE hFile, OUT PIO_STATUS_BLOCK pIoStatusBlock, IN PVOID FileInformationBuffer, IN ULONG FileInformationBufferLength, IN FILE_INFORMATION_CLASS FileInfoClass)
Definition: iofunc.c:3042

Referenced by iocp_async_closesocket(), iocp_async_read(), iocp_async_read_closesocket(), iocp_async_read_thread(), iocp_async_read_thread_closesocket(), serverThreadMain4(), test_completion(), test_completion_port(), test_file_completion_information(), test_sioAddressListChange(), test_synchronous_WSAIoctl(), test_WriteFileGather(), and test_WSARecv().

◆ GetOverlappedResult()

BOOL WINAPI GetOverlappedResult ( IN HANDLE  hFile,
IN LPOVERLAPPED  lpOverlapped,
OUT LPDWORD  lpNumberOfBytesTransferred,
IN BOOL  bWait 
)

Definition at line 204 of file iocompl.c.

208 {
209  DWORD WaitStatus;
210  HANDLE hObject;
211 
212  /* Check for pending operation */
213  if (lpOverlapped->Internal == STATUS_PENDING)
214  {
215  /* Check if the caller is okay with waiting */
216  if (!bWait)
217  {
218  /* Set timeout */
219  WaitStatus = WAIT_TIMEOUT;
220  }
221  else
222  {
223  /* Wait for the result */
224  hObject = lpOverlapped->hEvent ? lpOverlapped->hEvent : hFile;
225  WaitStatus = WaitForSingleObject(hObject, INFINITE);
226  }
227 
228  /* Check for timeout */
229  if (WaitStatus == WAIT_TIMEOUT)
230  {
231  /* We have to override the last error with INCOMPLETE instead */
233  return FALSE;
234  }
235 
236  /* Fail if we had an error -- the last error is already set */
237  if (WaitStatus) return FALSE;
238  }
239 
240  /* Return bytes transferred */
241  *lpNumberOfBytesTransferred = lpOverlapped->InternalHigh;
242 
243  /* Check for failure during I/O */
244  if (!NT_SUCCESS(lpOverlapped->Internal))
245  {
246  /* Set the error and fail */
247  BaseSetLastNTError(lpOverlapped->Internal);
248  return FALSE;
249  }
250 
251  /* All done */
252  return TRUE;
253 }
#define TRUE
Definition: types.h:120
#define ERROR_IO_INCOMPLETE
Definition: winerror.h:576
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define STATUS_PENDING
Definition: ntstatus.h:82
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
#define WAIT_TIMEOUT
Definition: dderror.h:14
_In_ HANDLE hFile
Definition: mswsock.h:90
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90
#define INFINITE
Definition: serial.h:102

Referenced by _overlapped_read_sync(), _overlapped_write_sync(), _test_overlapped_failure(), _test_overlapped_result(), Control(), FileAsyncReader_SyncRead(), FileAsyncReader_WaitForNext(), GetDeviceData(), KmtFltGetMessageResult(), CKsInterfaceHandler::KsCompleteIo(), KsSynchronousDeviceControl(), local_server_thread(), LogToFile(), overlapped_server(), PerformIO(), CPipe::Read(), ScmControlService(), ScmSendStartCommand(), ScmWaitForServiceConnect(), serverThreadMain3(), SyncOverlappedDeviceIoControl(), tcp_recv(), tcp_send(), test_AbortWaitCts(), test_AcceptEx(), test_async_file_errors(), test_ConnectEx(), test_events(), test_file_completion_information(), test_null_device(), test_overlapped(), test_overlapped_error(), test_read_device(), test_read_write(), test_readdirectorychanges(), test_send(), test_WaitBreak(), test_WaitCommEvent(), test_WaitCts(), test_WaitDcd(), test_WaitDsr(), test_WaitRing(), test_WaitRx(), test_waittxempty(), test_write_watch(), test_WSARecv(), testNotifyAddrChange(), and WSPGetOverlappedResult().

◆ GetQueuedCompletionStatus()

BOOL WINAPI GetQueuedCompletionStatus ( IN HANDLE  CompletionHandle,
IN LPDWORD  lpNumberOfBytesTransferred,
OUT PULONG_PTR  lpCompletionKey,
OUT LPOVERLAPPED lpOverlapped,
IN DWORD  dwMilliseconds 
)

Definition at line 114 of file iocompl.c.

119 {
122  ULONG_PTR CompletionKey;
124  PLARGE_INTEGER TimePtr;
125 
126  /* Convert the timeout and then call the native API */
127  TimePtr = BaseFormatTimeOut(&Time, dwMilliseconds);
128  Status = NtRemoveIoCompletion(CompletionHandle,
129  (PVOID*)&CompletionKey,
131  &IoStatus,
132  TimePtr);
133  if (!(NT_SUCCESS(Status)) || (Status == STATUS_TIMEOUT))
134  {
135  /* Clear out the overlapped output */
136  *lpOverlapped = NULL;
137 
138  /* Check what kind of error we got */
139  if (Status == STATUS_TIMEOUT)
140  {
141  /* Timeout error is set directly since there's no conversion */
143  }
144  else
145  {
146  /* Any other error gets converted */
148  }
149 
150  /* This is a failure case */
151  return FALSE;
152  }
153 
154  /* Write back the output parameters */
155  *lpCompletionKey = CompletionKey;
156  *lpNumberOfBytesTransferred = IoStatus.Information;
157 
158  /* Check for error */
159  if (!NT_SUCCESS(IoStatus.Status))
160  {
161  /* Convert and fail */
163  return FALSE;
164  }
165 
166  /* Return success */
167  return TRUE;
168 }
#define TRUE
Definition: types.h:120
IN PLARGE_INTEGER IN ULONG IN BOOLEAN IN ULONG IN BOOLEAN OUT PIO_STATUS_BLOCK IoStatus
Definition: fatprocs.h:2650
LONG NTSTATUS
Definition: precomp.h:26
PLARGE_INTEGER WINAPI BaseFormatTimeOut(OUT PLARGE_INTEGER Timeout, IN DWORD dwMilliseconds)
Definition: utils.c:288
uint32_t ULONG_PTR
Definition: typedefs.h:63
#define STATUS_TIMEOUT
Definition: ntstatus.h:81
smooth NULL
Definition: ftsmooth.c:416
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define SetLastError(x)
Definition: compat.h:409
#define WAIT_TIMEOUT
Definition: dderror.h:14
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90
NTSTATUS NTAPI NtRemoveIoCompletion(IN HANDLE IoCompletionHandle, OUT PVOID *KeyContext, OUT PVOID *ApcContext, OUT PIO_STATUS_BLOCK IoStatusBlock, IN PLARGE_INTEGER Timeout OPTIONAL)
Definition: iocomp.c:444
static PLARGE_INTEGER Time
Definition: time.c:105

Referenced by _test_completion(), iocp_async_closesocket(), iocp_async_read(), iocp_async_read_closesocket(), iocp_async_read_thread(), iocp_async_read_thread_closesocket(), serverThreadMain4(), test_completion(), test_completion_port(), test_file_completion_information(), test_sioAddressListChange(), test_synchronous_WSAIoctl(), and test_WriteFileGather().

◆ PostQueuedCompletionStatus()

BOOL WINAPI PostQueuedCompletionStatus ( IN HANDLE  CompletionHandle,
IN DWORD  dwNumberOfBytesTransferred,
IN ULONG_PTR  dwCompletionKey,
IN LPOVERLAPPED  lpOverlapped 
)

Definition at line 175 of file iocompl.c.

179 {
181 
182  /* Call the native API */
183  Status = NtSetIoCompletion(CompletionHandle,
184  (PVOID)dwCompletionKey,
187  dwNumberOfBytesTransferred);
188  if (!NT_SUCCESS(Status))
189  {
190  /* Convert the error and fail */
192  return FALSE;
193  }
194 
195  /* Success path */
196  return TRUE;
197 }
#define TRUE
Definition: types.h:120
LONG NTSTATUS
Definition: precomp.h:26
DWORD BaseSetLastNTError(IN NTSTATUS Status)
Definition: reactos.cpp:166
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
NTSTATUS NTAPI NtSetIoCompletion(IN HANDLE IoCompletionPortHandle, IN PVOID CompletionKey, IN PVOID CompletionContext, IN NTSTATUS CompletionStatus, IN ULONG CompletionInformation)
Definition: iocomp.c:568
Status
Definition: gdiplustypes.h:24
_In_ HANDLE _In_ DWORD _In_ DWORD _Inout_opt_ LPOVERLAPPED lpOverlapped
Definition: mswsock.h:90
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by async_notifier_proc(), and WSPIoctl().

◆ SetFileCompletionNotificationModes()

BOOL WINAPI SetFileCompletionNotificationModes ( IN HANDLE  FileHandle,
IN UCHAR  Flags 
)

Definition at line 30 of file iocompl.c.

32 {
34  {
36  return FALSE;
37  }
38 
40  return FALSE;
41 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define FILE_SKIP_COMPLETION_PORT_ON_SUCCESS
Definition: iocompl.c:21
_Must_inspect_result_ _In_ ULONG Flags
Definition: wsk.h:170
#define FILE_SKIP_SET_EVENT_ON_HANDLE
Definition: iocompl.c:22
#define SetLastError(x)
Definition: compat.h:409
#define UNIMPLEMENTED
Definition: debug.h:114