forked from pfent/rdma_tests
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRDMAMessageBuffer.h
62 lines (47 loc) · 1.9 KB
/
RDMAMessageBuffer.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
#ifndef RDMA_HASH_MAP_RDMAMESSAGEBUFFER_H
#define RDMA_HASH_MAP_RDMAMESSAGEBUFFER_H
#include <atomic>
#include "rdma/Network.hpp"
#include "rdma/CompletionQueuePair.hpp"
#include "rdma/QueuePair.hpp"
#include "rdma/MemoryRegion.hpp"
struct RDMANetworking {
rdma::Network network;
rdma::CompletionQueuePair completionQueue;
rdma::QueuePair queuePair;
/// Exchange the basic RDMA connection info for the network and queues
RDMANetworking(int sock);
};
class RDMAMessageBuffer {
public:
/// Send data to the remote site
void send(const uint8_t *data, size_t length);
void send(const uint8_t *data, size_t length, bool inln);
/// Receive data to a freshly allocated data vector
std::vector<uint8_t> receive();
/// Receive to a specific memory region with at last maxSize
size_t receive(void *whereTo, size_t maxSize);
/// Construct a message buffer of the given size, exchanging RDMA networking information over the given socket
/// size _must_ be a power of 2.
RDMAMessageBuffer(size_t size, int sock);
/// whether there is data to be read non-blockingly
bool hasData() const;
private:
const size_t size;
RDMANetworking net;
std::unique_ptr<volatile uint8_t[]> receiveBuffer;
std::atomic<size_t> readPos{0};
std::unique_ptr<uint8_t[]> sendBuffer;
size_t sendPos = 0;
volatile size_t currentRemoteReceive = 0;
rdma::MemoryRegion localSend;
rdma::MemoryRegion localReceive;
rdma::MemoryRegion localReadPos;
rdma::MemoryRegion localCurrentRemoteReceive;
rdma::RemoteMemoryRegion remoteReceive;
rdma::RemoteMemoryRegion remoteReadPos;
void writeToSendBuffer(const uint8_t *data, size_t sizeToWrite);
void readFromReceiveBuffer(size_t readPos, uint8_t *whereTo, size_t sizeToRead) const;
void zeroReceiveBuffer(size_t beginReceiveCount, size_t sizeToZero);
};
#endif //RDMA_HASH_MAP_RDMAMESSAGEBUFFER_H