// ConsoleApplication1.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <conio.h>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
enum class FileIo
{
FI_NONE,
FI_READ,
FI_WRITE,
};
const int buffer_size = 10240000;
class MyOverlapped
{
public:
OVERLAPPED m_ol;
FileIo m_io;
char m_buffer[buffer_size];
int m_readPos;
int m_totalRead;
int m_writePos;
int m_totalWrite;
int m_fileSize;
CRITICAL_SECTION m_cs;
public:
MyOverlapped() : m_io(FileIo::FI_NONE), m_readPos(0), m_totalRead(0), m_writePos(0), m_totalWrite(0)
{
}
void Init()
{
m_io = FileIo::FI_NONE;
m_readPos = 0;
m_totalRead = 0;
m_writePos = 0;
m_totalWrite = 0;
::InitializeCriticalSection(&m_cs);
ZeroMemory(&m_ol, sizeof(m_ol));
}
void fini()
{
DeleteCriticalSection(&m_cs);
}
~MyOverlapped()
{
}
};
struct FileHandle
{
HANDLE hRead;
HANDLE hWri
异步读写文件
最新推荐文章于 2024-09-10 11:01:21 发布
该博客介绍了一个使用异步读写操作实现文件复制的C++示例。通过创建IO完成端口并利用缓冲区,实现了从一个文件到另一个文件的数据传输,确保了高效且非阻塞的操作。当读取完毕时,程序会停止并输出完成信息。
摘要由CSDN通过智能技术生成