最常用的两个函数-WriteFile、ReadFile
BOOL
ReadFile( HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped);
BOOL
WriteFile( HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
ReadFile函数是向hFile句柄对应的设备进行读操作,且hFile句柄被创建时需要 GENERIC_READ 访问权限。
WriteFile函数是向hFile句柄对应的设备进行写操作,且hFile句柄被创建时需要 GENERIC_WRITE 访问权限。
对于同步I/O操作来说,最后一个参数lpOverlapped都被指定为NULL。
将数据刷新至设备
在CreateFile函数中我们可以通过几个标识(Flags)来设定系统缓存数据的方式;不过对于串口(Serial Port)、管道(pipes),我们可以调用BOOL FlushFileBuffers( HANDLE hFile)函数来强制系统将缓存的数据写入到I/O设备中。
同步I/O的取消操作
同步I/O操作使用简单,但它有一个弊端就是它会阻塞该线程的其他操作直到I/O操作完成。对于一般负责任的程序来说,你应该尽量使用异步I/O操作。大部分程序被挂起的共同的原因就是等待同步I/O操作的完成。
一个取消同步I/O操作的函数就是:BOOL CancelSynchronousIo( HANDLE hThread);其中hThread就是要取消其I/O操作的线程句柄,这个线程句柄在创建时需有THREAD_TERMINATE权限。
分享到:
相关推荐
Chapter 1 - Motivating I/O Problems and their Solutions Chapter 2 - Parallel Sorting on Heterogeneous Clusters Part Two - Selected Readings Chapter 3 - A Sensitivity Study of Parallel I/O under...
Mpeg-4/H.264视频编解码工程实践源码chapter2-chapter10,供大家一次性下载全。
Chapter 8 - I/O Flow and Dispatching Chapter 9 - I/O Targets Chapter 10 - Synchronization Chapter 11 - Driver Tracing and Diagnosability Chapter 12 - WDF Support Objects Chapter 13 - UMDF ...
MPEG-4/H.264视频编解码工程实践》的配套光盘代码10:chapter10
Chapter 10: HTTP Servers Chapter 11: The World Wide Web Chapter 12: Building and Parsing E-Mail Chapter 13: SMTP Chapter 14: POP Chapter 15: IMAP Chapter 16: Telnet and SSH Chapter 17: FTP ...
Chapter 10 - Encryption Chapter 11 - Logging Part III - IIS Programming Chapter 12 - ASP Programming Chapter 13 - COM Web Programming Chapter 14 - ASP.NET Web Forms Chapter 15 - ASP.NET ...
Chapter I - Introduction To Docker & Containers Chapter II - Installation & Configuration Chapter III - Basic Concepts Chapter IV - Advanced Concepts Chapter V - Working With Docker Images Chapter VI ...
机器学习101 与用于机器学习的数据集相关的存储库。 链接到教程博客: : 第1章 关于朴素贝叶斯的理论 ...https://medium.com/machine-learning-101/chapter-5-random-forest-classifier-56dc742
Chapter10-《Ext JS高级程序设计》源代码.rar Chapter9-《Ext JS高级程序设计》源代码.rar Chapter11-《Ext JS高级程序设计》源代码.rar Chapter13-《Ext JS高级程序设计》源代码.rar Chapter14-《Ext JS高级程序...
MPEG-4/H.264视频编解码工程实践》的配套光盘chapter3
《MPEG-4/H.264视频编解码工程实践》的配套光盘代码9:chapter9
《MPEG-4/H.264视频编解码工程实践》的配套光盘代码7:chapter7
chapter-02/songs-app-angularjs/chapter-02/songs-app-django/chapter-02/songs-app-rails/chapter-02/songs-app-symfony/3.3。 第3章。 chapter-03/songs-app-sinatra/3.4。 第四章chapter-04/new-p
课后练习题-chapter10-14.doc
CISSP ALL IN ONE 5TH EDITON - Part 1/3 ( Chapter01 - 04)
CISSP All In One 5th Edition - Part 2/3 ( Chapter05 - 08)
CISSP ALL IN ONE 5TH EDITON - Part 3/3 ( Chapter09 - 12)
- chapter4-1-2:[使用@Async实现异步调用](http://blog.didispace.com/springbootasync/) #### 日志管理 - chapter4-2-1:[默认日志的配置](http://blog.didispace.com/springbootlog/) - chapter4-2-2:[使用log...
操作系统概念英文课件:Chapter 10-file-system interface.pptx