-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathHarpoon.h
55 lines (46 loc) · 1.27 KB
/
Harpoon.h
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
/*
* File: Harpoon.h
* Author: Ryan Kophs
*
* Created on December, 2014
*/
#pragma once
#include <string>
#include <vector>
#include <czmq.h>
/** Harpoon-Kraken is a PipeLine communication pattern used to
* stream files or plain data from a server to a client.
*
* The Client: Here called Harpoon connects (harpoon hit) the
* Kraken (server).
*
* The Harpoon keeps receiving/pulling data from the Kraken until
* mission achieved (Kraken is dead...) all the data is received.
*
* Originally this was described at zeromq.org as fileio model:
* http://zguide.zeromq.org/c:fileio3
*/
class Harpoon {
public:
enum class Spear : std::int8_t { MISS = -1, IMPALED = 0 };
enum class Battling : std::int8_t { TIMEOUT = -2, INTERRUPT = -1, VICTORIOUS = 0, CONTINUE = 1, CANCEL = 2 };
Harpoon();
Spear Aim(const std::string& location);
void MaxWaitInMs(const int timeoutMs);
Battling Heave(std::vector<uint8_t>& data);
Battling Cancel();
virtual ~Harpoon();
std::string EnumToString(Battling type) const;
protected:
Battling PollTimeout(int timeoutMs);
void RequestChunks();
void FreeChunk();
private:
void* mDealer;
zctx_t* mCtx;
size_t mQueueLength;
int mTimeoutMs;
size_t mCredit;
size_t mOffset;
zframe_t *mChunk;
};