forked from boostorg/beast
beast file_body & file support seek.
win32 file_body handles seek correctly. Added seek to win32 file. file_body_writer handles offsets.
This commit is contained in:
1 parent
4ff4c79d5b
commit
1d965752b2
3 files changed
+167
-2
No files matched your search
@@ -160,6 +160,19 @@ public:
|
||||
*/
|
||||
void
|
||||
reset(File&& file, error_code& ec);
|
||||
|
||||
/** Set the cursor position of the file.
|
||||
|
||||
This function can be used to move the cursor of the file ahead
|
||||
so that only a part gets read. This file will also adjust the
|
||||
value_type, in case the file is already part of a body.
|
||||
|
||||
@param offset The offset in bytes from the beginning of the file
|
||||
|
||||
@param ec Set to the error, if any occurred
|
||||
*/
|
||||
|
||||
void seek(std::uint64_t offset, error_code& ec);
|
||||
};
|
||||
|
||||
template<class File>
|
||||
@@ -210,8 +223,29 @@ reset(File&& file, error_code& ec)
|
||||
|
||||
// Cache the size
|
||||
file_size_ = file_.size(ec);
|
||||
|
||||
// Consider the offset
|
||||
if (!ec)
|
||||
file_size_ -= file_.pos(ec);
|
||||
}
|
||||
|
||||
template<class File>
|
||||
void
|
||||
basic_file_body<File>::
|
||||
value_type::
|
||||
seek(std::uint64_t offset, error_code& ec)
|
||||
{
|
||||
file_.seek(offset, ec);
|
||||
// Cache the size
|
||||
if (!ec)
|
||||
file_size_ = file_.size(ec);
|
||||
|
||||
// Consider the offset
|
||||
if (!ec)
|
||||
file_size_ -= file_.pos(ec);
|
||||
}
|
||||
|
||||
|
||||
// This is called from message::payload_size
|
||||
template<class File>
|
||||
std::uint64_t
|
||||
|
||||
@@ -94,7 +94,7 @@ struct basic_file_body<file_win32>
|
||||
std::uint64_t
|
||||
size() const
|
||||
{
|
||||
return size_;
|
||||
return last_ - first_;
|
||||
}
|
||||
|
||||
void
|
||||
@@ -105,6 +105,9 @@ struct basic_file_body<file_win32>
|
||||
|
||||
void
|
||||
reset(file_win32&& file, error_code& ec);
|
||||
|
||||
void
|
||||
seek(std::uint64_t offset, error_code& ec);
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
@@ -284,11 +287,29 @@ reset(file_win32&& file, error_code& ec)
|
||||
close();
|
||||
return;
|
||||
}
|
||||
first_ = 0;
|
||||
|
||||
first_ = file_.pos(ec);
|
||||
if(ec)
|
||||
{
|
||||
close();
|
||||
return;
|
||||
}
|
||||
|
||||
last_ = size_;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline
|
||||
void
|
||||
basic_file_body<file_win32>::
|
||||
value_type::
|
||||
seek(std::uint64_t offset, error_code& ec)
|
||||
{
|
||||
first_ = offset;
|
||||
file_.seek(offset, ec);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
namespace detail {
|
||||
|
||||
Reference in new issue
Block a user