hmbdc
simplify-high-performance-messaging-programming
DownloadMemory.hpp
1 #include "hmbdc/Copyright.hpp"
2 #pragma once
3 
4 #include <fstream>
5 #include <stdint.h>
6 #include <stdlib.h>
7 
8 
9 namespace hmbdc { namespace os {
10 using namespace std;
13  : addr_(nullptr)
14  , fullLen_(0)
15  , len_(0) {
16  }
17 
18  void* open(size_t len) {
19  addr_ = (char*)memalign(SMP_CACHE_BYTES, len);
20  if (addr_) {
21  fullLen_ = len;
22  len_ = 0;
23  return addr_;
24  }
25  return nullptr;
26  }
27 
28  explicit operator bool() const {
29  return addr_;
30  }
31 
32  bool writeDone() const {
33  return fullLen_ == len_;
34  }
35 
36  size_t write(void const* mem, size_t l) {
37  auto wl = min(l, fullLen_ - len_);
38  if (addr_) {
39  memcpy(addr_ + len_, mem, wl);
40  }
41  len_ += wl;
42  return wl;
43  }
44 
45  size_t fullLen() const {
46  return fullLen_;
47  }
48 
49  void close() {
50  addr_ = nullptr;
51  fullLen_ = 0;
52  len_ = 0;
53  }
54 
55 private:
56  char* addr_;
57  size_t fullLen_;
58  size_t len_;
59 
60 };
61 
62 }}
Definition: TypedString.hpp:74
Definition: DownloadMemory.hpp:11
Definition: Client.hpp:11