forked from foshougua/network-dash
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyTask.cpp
More file actions
72 lines (55 loc) · 1.47 KB
/
MyTask.cpp
File metadata and controls
72 lines (55 loc) · 1.47 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
60
61
62
63
64
65
66
67
68
69
70
71
/*************************************************************************
> File Name: MyTask.cpp
> Author:
> Mail:
> Created Time: 2017年05月09日 星期二 09时42分24秒
************************************************************************/
#include<fstream>
#include"MyTask.h"
#include<thread>
#include<iostream>
#include<zmq.h>
#include<string>
using std::string;
using std::cout;
using std::endl;
void MyTask::Run()
{
cout << this->blockID << "Run: ";
void *pCtx = NULL;
void *pSock = NULL;
const char * pAddr = "tcp://127.0.0.1:7766";
if((pCtx = zmq_ctx_new()) == NULL)
{
return ;
}
if((pSock = zmq_socket(pCtx, ZMQ_DEALER)) == NULL)
{
zmq_ctx_destroy(pCtx);
return ;
}
int iSndTimeOut = 5000;
if(zmq_setsockopt(pSock, ZMQ_RCVTIMEO, &iSndTimeOut, sizeof(iSndTimeOut)) < 0)
{
zmq_close(pSock);
zmq_ctx_destroy(pCtx);
return ;
}
if(zmq_connect(pSock, pAddr) < 0)
{
zmq_close(pSock);
zmq_ctx_destroy(pCtx);
}
char block[1024 * 1024 * 4];
this->file->file.seekg((blockID - 1) * 1024 * 1024 * 4, std::ios::beg);
this->file->file.read(block, sizeof(block));
if(zmq_send(pSock, block, sizeof(block), 0) < 0)
{
std::cout<<"Send message error!!"<<std::endl;
}
else
{
std::cout<<"Block "<< this->blockID << " Send" << std::endl;
}
std::this_thread::sleep_for(std::chrono::seconds(1));
}