Files
transmission/libtransmission/inout.h
Charles Kerr 445302855d refactor: async file IO prep (#8740)
* refactor: make TrBlockSize a constant

* refactor: add tr_byte_span::is_valid()

refactor: add tr_byte_span::size()

* refactor: add tr_block_info::byte_span_for_block()

refactor: add tr_block_info::byte_span_for_req()

* refactor: tr_ioRead(), tr_ioWrite() take an open_files arg

* refactor: use std::span for open-files fallback writes
2026-03-29 21:31:12 -05:00

46 lines
1.3 KiB
C++

// This file Copyright © Mnemosyne LLC.
// It may be used under GPLv2 (SPDX: GPL-2.0-only), GPLv3 (SPDX: GPL-3.0-only),
// or any future license endorsed by Mnemosyne LLC.
// License text can be found in the licenses/ folder.
#pragma once
#ifndef __TRANSMISSION__
#error only libtransmission should #include this header.
#endif
#include <cstdint> // uint8_t
#include <span>
#include "libtransmission/error-types.h"
#include "libtransmission/block-info.h"
#include "libtransmission/types.h"
class tr_open_files;
struct tr_torrent;
/**
* Reads the block specified by the piece index, offset, and length.
* @return 0 on success, or an errno value on failure.
*/
[[nodiscard]] tr_error_code_t tr_ioRead(
tr_torrent const& tor,
tr_open_files& open_files,
tr_block_info::Location const& loc,
std::span<uint8_t> setme);
/**
* Writes the block specified by the piece index, offset, and length.
* @return 0 on success, or an errno value on failure.
*/
[[nodiscard]] tr_error_code_t tr_ioWrite(
tr_torrent& tor,
tr_open_files& open_files,
tr_block_info::Location const& loc,
std::span<uint8_t const> writeme);
/**
* @brief Test to see if the piece matches its metainfo's SHA1 checksum.
*/
[[nodiscard]] bool tr_ioTestPiece(tr_torrent const& tor, tr_piece_index_t piece);