Skip to content

Commit 9a69efd

Browse files
committed
Stuff.
1 parent 25d2dce commit 9a69efd

3 files changed

Lines changed: 20 additions & 14 deletions

File tree

src/data/chunk_handle.h

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33

44
#include "chunk_list_node.h"
55

6+
#include <cerrno>
7+
68
namespace torrent {
79

810
class ChunkListNode;
@@ -27,7 +29,7 @@ class ChunkHandle {
2729

2830
uint32_t index() const { return m_node->index(); }
2931

30-
static ChunkHandle from_error(int e) { ChunkHandle h; h.set_error_number(e); return h; }
32+
static ChunkHandle from_error(int err);
3133

3234
private:
3335
ChunkListNode* m_node;
@@ -37,6 +39,16 @@ class ChunkHandle {
3739
int m_errno;
3840
};
3941

42+
inline ChunkHandle
43+
ChunkHandle::from_error(int err) {
44+
if (err == 0)
45+
err = ENOENT;
46+
47+
ChunkHandle h;
48+
h.set_error_number(err);
49+
return h;
50+
}
51+
4052
} // namespace torrent
4153

4254
#endif

src/data/chunk_list.cc

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,15 @@ ChunkList::get(size_type index, get_flags flags) {
109109
throw internal_error("ChunkList::get(...) called with get_hashing and get_not_hashing flags set.");
110110

111111
if (chunk == nullptr) {
112+
int err = errno;
113+
112114
LT_LOG_THIS(DEBUG, "Could not create: memory:%" PRIu64 " block:%" PRIu32 " errno:%i errmsg:%s.",
113115
m_manager->memory_usage(),
114116
m_manager->memory_block_count(),
115-
errno, std::strerror(errno));
117+
err, std::strerror(err));
116118

117119
m_manager->deallocate(m_chunk_size, allocate_flags | ChunkManager::allocate_revert_log);
118-
119-
if (errno == 0)
120-
return ChunkHandle::from_error(ENOENT);
121-
122-
return ChunkHandle::from_error(errno);
120+
return ChunkHandle::from_error(err);
123121
}
124122

125123
node->set_chunk(chunk);
@@ -135,12 +133,8 @@ ChunkList::get(size_type index, get_flags flags) {
135133

136134
Chunk* chunk = m_slot_create_chunk(index, prot_flags);
137135

138-
if (chunk == nullptr) {
139-
if (errno == 0)
140-
return ChunkHandle::from_error(ENOENT);
141-
136+
if (chunk == nullptr)
142137
return ChunkHandle::from_error(errno);
143-
}
144138

145139
delete node->chunk();
146140

src/data/chunk_list_node.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
#ifndef LIBTORRENT_DATA_CHUNK_LIST_NODE_H
22
#define LIBTORRENT_DATA_CHUNK_LIST_NODE_H
33

4-
#include <cinttypes>
5-
64
#include "torrent/utils/chrono.h"
75

6+
#include <cinttypes>
7+
88
namespace torrent {
99

1010
class Chunk;

0 commit comments

Comments
 (0)