Repository navigation
Expand file tree
/
Copy pathxread_task.cpp
More file actions
59 lines (54 loc) · 1.43 KB
/
Copy pathxread_task.cpp
File metadata and controls
59 lines (54 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include "xread_task.h"
#include <iostream>
#include "xdata.h"
using namespace std;
/// <summary>
/// 初始化读取线程,获取文件大小
/// </summary>
/// <param name="filename"></param>
/// <returns></returns>
bool XReadTask::Init(std::string filename)
{
if (filename.empty())return false;
ifs_.open(filename, ios::binary); //二进制打开
if (!ifs_)
{
cerr << "open file " << filename << " failed!" << endl;
return false;
}
cout << filename << " open success!" << endl;
ifs_.seekg(0, ios::end);
data_byte_ = ifs_.tellg();
ifs_.seekg(0, ios::beg);
cout << " file size " << data_byte_ << endl;
return true;
}
void XReadTask::Main()
{
cout << "begin thread XReadTask::Main" << endl;
while (!is_exit_)
{
if (ifs_.eof())break;
//char buf[10240] = { 0 };
//创建内存池空间管理对象
auto data = XData::Make(this->mem_pool_);
int data_size = 1024;
//申请空间
void* buf = data->New(data_size);
//读取文件
ifs_.read((char*)buf, data_size);
if (ifs_.gcount() <= 0)break;
data->set_size(ifs_.gcount());
if (ifs_.eof())
{
data->set_end(true);
}
//cout << "["<<ifs_.gcount()<<"]" << flush;
if (next_)
{
next_->PushBack(data);
}
}
ifs_.close();
cout << "end thread XReadTask::Main" << endl;
}