| 65 | } |
| 66 | |
| 67 | comm::RetCode CheckPointStat::Init(const string &dir, const string &file) { |
| 68 | if (dir.empty() || file.empty()) |
| 69 | return comm::RetCode::RET_ERR_ARG; |
| 70 | |
| 71 | impl_->dir = dir; |
| 72 | impl_->file = file; |
| 73 | string path{impl_->dir + impl_->file}; |
| 74 | |
| 75 | impl_->buf = nullptr; |
| 76 | impl_->len = sizeof(CheckPointStatItem_t); |
| 77 | |
| 78 | int fd = open(path.c_str(), O_RDWR | O_CREAT, S_IRUSR | S_IWUSR); |
| 79 | if (fd < 0) { |
| 80 | QLErr("open err path %s %s", path.c_str(), strerror(errno)); |
| 81 | return comm::RetCode::RET_ERR_SYS; |
| 82 | } |
| 83 | |
| 84 | if (ftruncate(fd, (off_t)impl_->len) < 0) { |
| 85 | QLErr("ftruncate err %s", strerror(errno)); |
| 86 | close(fd); |
| 87 | return comm::RetCode::RET_ERR_SYS; |
| 88 | } |
| 89 | |
| 90 | void *pa{mmap(nullptr, impl_->len, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0)}; |
| 91 | |
| 92 | close(fd); |
| 93 | |
| 94 | if ((char *)pa == MAP_FAILED) { |
| 95 | QLErr("mmap err %s", strerror(errno)); |
| 96 | return comm::RetCode::RET_ERR_SYS; |
| 97 | } |
| 98 | |
| 99 | impl_->buf = (CheckPointStatItem_t*)pa; |
| 100 | |
| 101 | return comm::RetCode::RET_OK; |
| 102 | } |
| 103 | |
| 104 | comm::RetCode CheckPointStat::GetCheckPoint(uint64_t &cp) { |
| 105 | cp = -1; |
nothing calls this directly
no test coverage detected