34
34
#define TORRENT_DISK_BUFFER_HOLDER_HPP_INCLUDED
36
36
#include "libtorrent/config.hpp"
37
#include "libtorrent/assert.hpp"
38
40
namespace libtorrent
41
namespace aux { class session_impl; }
43
namespace aux { struct session_impl; }
44
struct disk_buffer_pool;
44
46
struct TORRENT_EXPORT disk_buffer_holder
46
48
disk_buffer_holder(aux::session_impl& ses, char* buf);
47
disk_buffer_holder(disk_io_thread& iothread, char* buf);
49
disk_buffer_holder(disk_buffer_pool& disk_pool, char* buf);
50
disk_buffer_holder(disk_buffer_pool& disk_pool, char* buf, int num_blocks);
48
51
~disk_buffer_holder();
50
53
char* get() const { return m_buf; }
51
void reset(char* buf = 0);
54
void reset(char* buf = 0, int num_blocks = 1);
55
void swap(disk_buffer_holder& h)
57
TORRENT_ASSERT(&h.m_disk_pool == &m_disk_pool);
58
std::swap(h.m_buf, m_buf);
53
61
typedef char* (disk_buffer_holder::*unspecified_bool_type)();
54
62
operator unspecified_bool_type() const
55
63
{ return m_buf == 0? 0: &disk_buffer_holder::release; }
58
disk_io_thread& m_iothread;
66
disk_buffer_pool& m_disk_pool;