-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRemoteBuf.h
80 lines (65 loc) · 1.95 KB
/
RemoteBuf.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <vector>
#include <string>
#include <future>
#include <unordered_map>
#include <cassert>
#include <stdexcept>
#include <mutex>
#include <src/client/BladeClient.h>
#include <src/common/AllocationRecord.h>
#include "utils.h"
namespace RemoteBuf {
const int INITIAL_BUFFER_SIZE = 16384;
const char RDMA_PORT[] = "12345";
const char RDMA_ADDR[] = "10.10.49.94";
/* Buffer is not reentrant */
class Buffer {
public:
Buffer();
~Buffer();
/* Writes buf with size s to LocalBuf */
void write(char *buf, unsigned int s);
/* Writes buf with size s to LocalBuf at specified offset */
void write(char *buf, unsigned int s, unsigned int off);
/* Flush pending requests (write) */
void flush();
/* Copy LocalBuf to buf */
void read(char *buf);
/* Get the size of the buffer, regardless of where it is located. */
unsigned int getSize();
private:
std::vector<char> LocalBuf;
bool WriteInProgress;
bool BufferIsRemote;
unsigned int Size;
std::future<bool> WriteFuture;
sirius::AllocationRecord Alloc;
sirius::BladeClient Client;
bool writeRemote();
bool readRemote();
void write(char *buf, unsigned int s, std::vector<char>::iterator start);
};
/* BufferManager not reentrant */
class BufferManager {
public:
BufferManager();
~BufferManager();
/* Creates buffer with specified id.
* Throws an exception if the buffer already exists
*/
Buffer *createBuffer(const std::string id);
/* Gets the buffer with specified id.
* Throws an exception if the buffer doesn't exist
*/
Buffer *getBuffer(const std::string id);
/* If the buffer exists, it is deleted.
* If it doesn't, an exception is thrown.
*/
void deleteBuffer(const std::string id);
/* Returns true if the buffer with specified id exists. */
bool bufferExists(const std::string id);
private:
std::unordered_map<std::string, Buffer *> Buffers;
std::mutex BM;
};
}