-
Notifications
You must be signed in to change notification settings - Fork 13
/
Kraken.h
65 lines (55 loc) · 1.57 KB
/
Kraken.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
56
57
58
59
60
61
62
63
64
65
/*
* File: Harpoon.h
* Author: Ryan Kophs
*
* Created on December, 2014
*/
#pragma once
#include <string>
#include <vector>
#include <czmq.h>
struct _zctx_t;
typedef struct _zctx_t zctx_t;
/** Harpoon-Kraken is a PipeLine communication pattern used to
* Battling 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...) the data is received.
*
* Originally this was described at zeromq.org as fileio model:
* http://zguide.zeromq.org/c:fileio3
*/
class Kraken {
public:
enum class Spear : std::int8_t { MISS = -1, IMPALED = 0 };
enum class Battling : std::int8_t { TIMEOUT = -2, INTERRUPT = -1, CONTINUE = 0, CANCEL = 1 };
typedef std::vector<uint8_t> Chunks;
Kraken();
Spear SetLocation(const std::string& location);
void MaxWaitInMs(const int timeout);
void ChangeDefaultMaxChunkSizeInBytes(const size_t bytes);
size_t MaxChunkSizeInBytes();
Battling FinalBreach();
Battling SendTidalWave(const Chunks& data);
virtual ~Kraken();
std::string EnumToString(Battling type) const;
protected:
Battling SendRawData(const uint8_t*, int size);
Battling PollTimeout(int timeoutMs);
Battling NextChunkId();
void FreeOldRequests();
void FreeChunk();
private:
void* mRouter;
zctx_t* mCtx;
std::string mLocation;
size_t mQueueLength;
size_t mMaxChunkSize;
char* mNextChunk;
zframe_t* mIdentity;
int mTimeoutMs;
zframe_t* mChunk;
};