Asynchronous vs. synchronous mode
The driver can be used in synchronous (FILE_ATTRIBUTE_NORMAL in CreateFile)
or asynchronous (FILE_FLAG_OVERLAPPED) mode.
However, the synchronous mode has an essential disadvantage:
Every request to the driver (WriteFile,
ReadFile,
DeviceIoControl)
must finish, before the next request can be processed.
This means, if you have a ReadFile pending
(waiting for data packets) you cannot deinit the driver or execute a WriteFile.
Also cancelling the pending request via CancelIo is not possible!
This is the main reason, why you should (in most cases) use the asynchronous
mode. The asynchronous mode causes little more programming overhead, but
enables you, to take advantage of having several requests running at the
same time.
The asynchronous mode can be split in 2 more modes:
"blocking" and "nonblocking"
"Blocking" means that you use the function GetOverlappedResult
with the parameter "bWait" set to TRUE. This is the case in the code fragments
in this documentation.
This mode should be used in a multithreading application. However a
multithreaded application needs possibly synchronization between the several
threads.
"Nonblocking" means, that GetOverlappedResult returns immediately
(parameter bWait set to FALSE). In this case you have to poll (call GetOverlappedResult
again), if and when the operation is finished. This mode is useful with
a singlethreaded application, where some other work can be done meantime.
Singlethreaded applications are in most cases easier to develop, because
no synchronization between several threads is needed.
For further information please take a look in your compilers manuals or the platform SDK of Microsoft.