mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-19 18:03:47 +00:00
Change file op |ssize_t|s to FileOperationResult
R=mark@chromium.org Review URL: https://codereview.chromium.org/1416493006 .
This commit is contained in:
parent
63916623cd
commit
3d598cdbcd
@ -24,12 +24,6 @@
|
|||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#ifdef _WIN64
|
|
||||||
typedef int64_t ssize_t;
|
|
||||||
#else
|
|
||||||
typedef __w64 int ssize_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
typedef unsigned int pid_t;
|
typedef unsigned int pid_t;
|
||||||
|
|
||||||
#endif // CRASHPAD_COMPAT_WIN_SYS_TYPES_H_
|
#endif // CRASHPAD_COMPAT_WIN_SYS_TYPES_H_
|
||||||
|
@ -566,7 +566,7 @@ int DatabaseUtilMain(int argc, char* argv[]) {
|
|||||||
call_error_writing_crash_report(database.get(), new_report);
|
call_error_writing_crash_report(database.get(), new_report);
|
||||||
|
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
ssize_t read_result;
|
FileOperationResult read_result;
|
||||||
do {
|
do {
|
||||||
read_result = file_reader->Read(buf, sizeof(buf));
|
read_result = file_reader->Read(buf, sizeof(buf));
|
||||||
if (read_result < 0) {
|
if (read_result < 0) {
|
||||||
|
@ -20,8 +20,8 @@
|
|||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
bool LoggingReadFile(FileHandle file, void* buffer, size_t size) {
|
bool LoggingReadFile(FileHandle file, void* buffer, size_t size) {
|
||||||
ssize_t expect = base::checked_cast<ssize_t>(size);
|
FileOperationResult expect = base::checked_cast<FileOperationResult>(size);
|
||||||
ssize_t rv = ReadFile(file, buffer, size);
|
FileOperationResult rv = ReadFile(file, buffer, size);
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
PLOG(ERROR) << "read";
|
PLOG(ERROR) << "read";
|
||||||
return false;
|
return false;
|
||||||
@ -35,8 +35,8 @@ bool LoggingReadFile(FileHandle file, void* buffer, size_t size) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool LoggingWriteFile(FileHandle file, const void* buffer, size_t size) {
|
bool LoggingWriteFile(FileHandle file, const void* buffer, size_t size) {
|
||||||
ssize_t expect = base::checked_cast<ssize_t>(size);
|
FileOperationResult expect = base::checked_cast<FileOperationResult>(size);
|
||||||
ssize_t rv = WriteFile(file, buffer, size);
|
FileOperationResult rv = WriteFile(file, buffer, size);
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
PLOG(ERROR) << "write";
|
PLOG(ERROR) << "write";
|
||||||
return false;
|
return false;
|
||||||
@ -59,7 +59,7 @@ void CheckedWriteFile(FileHandle file, const void* buffer, size_t size) {
|
|||||||
|
|
||||||
void CheckedReadFileAtEOF(FileHandle file) {
|
void CheckedReadFileAtEOF(FileHandle file) {
|
||||||
char c;
|
char c;
|
||||||
ssize_t rv = ReadFile(file, &c, 1);
|
FileOperationResult rv = ReadFile(file, &c, 1);
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
PCHECK(rv == 0) << "read";
|
PCHECK(rv == 0) << "read";
|
||||||
} else {
|
} else {
|
||||||
|
@ -21,8 +21,8 @@
|
|||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
bool FileReaderInterface::ReadExactly(void* data, size_t size) {
|
bool FileReaderInterface::ReadExactly(void* data, size_t size) {
|
||||||
ssize_t expect = base::checked_cast<ssize_t>(size);
|
FileOperationResult expect = base::checked_cast<FileOperationResult>(size);
|
||||||
ssize_t rv = Read(data, size);
|
FileOperationResult rv = Read(data, size);
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
// Read() will have logged its own error.
|
// Read() will have logged its own error.
|
||||||
return false;
|
return false;
|
||||||
@ -41,14 +41,14 @@ WeakFileHandleFileReader::WeakFileHandleFileReader(FileHandle file_handle)
|
|||||||
WeakFileHandleFileReader::~WeakFileHandleFileReader() {
|
WeakFileHandleFileReader::~WeakFileHandleFileReader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t WeakFileHandleFileReader::Read(void* data, size_t size) {
|
FileOperationResult WeakFileHandleFileReader::Read(void* data, size_t size) {
|
||||||
DCHECK_NE(file_handle_, kInvalidFileHandle);
|
DCHECK_NE(file_handle_, kInvalidFileHandle);
|
||||||
|
|
||||||
// Don’t use LoggingReadFile(), which insists on a full read and only returns
|
// Don’t use LoggingReadFile(), which insists on a full read and only returns
|
||||||
// a bool. This method permits short reads and returns the number of bytes
|
// a bool. This method permits short reads and returns the number of bytes
|
||||||
// read.
|
// read.
|
||||||
base::checked_cast<ssize_t>(size);
|
base::checked_cast<FileOperationResult>(size);
|
||||||
ssize_t rv = ReadFile(file_handle_, data, size);
|
FileOperationResult rv = ReadFile(file_handle_, data, size);
|
||||||
if (rv < 0) {
|
if (rv < 0) {
|
||||||
PLOG(ERROR) << "read";
|
PLOG(ERROR) << "read";
|
||||||
return -1;
|
return -1;
|
||||||
@ -88,7 +88,7 @@ void FileReader::Close() {
|
|||||||
file_.reset();
|
file_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FileReader::Read(void* data, size_t size) {
|
FileOperationResult FileReader::Read(void* data, size_t size) {
|
||||||
DCHECK(file_.is_valid());
|
DCHECK(file_.is_valid());
|
||||||
return weak_file_handle_file_reader_.Read(data, size);
|
return weak_file_handle_file_reader_.Read(data, size);
|
||||||
}
|
}
|
||||||
@ -105,7 +105,7 @@ WeakStdioFileReader::WeakStdioFileReader(FILE* file)
|
|||||||
WeakStdioFileReader::~WeakStdioFileReader() {
|
WeakStdioFileReader::~WeakStdioFileReader() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t WeakStdioFileReader::Read(void* data, size_t size) {
|
FileOperationResult WeakStdioFileReader::Read(void* data, size_t size) {
|
||||||
DCHECK(file_);
|
DCHECK(file_);
|
||||||
|
|
||||||
size_t rv = fread(data, 1, size, file_);
|
size_t rv = fread(data, 1, size, file_);
|
||||||
|
@ -37,7 +37,7 @@ class FileReaderInterface : public virtual FileSeekerInterface {
|
|||||||
//! \return The number of bytes actually read if the operation succeeded,
|
//! \return The number of bytes actually read if the operation succeeded,
|
||||||
//! which may be `0` or any positive value less than or equal to \a size.
|
//! which may be `0` or any positive value less than or equal to \a size.
|
||||||
//! `-1` if the operation failed, with an error message logged.
|
//! `-1` if the operation failed, with an error message logged.
|
||||||
virtual ssize_t Read(void* data, size_t size) = 0;
|
virtual FileOperationResult Read(void* data, size_t size) = 0;
|
||||||
|
|
||||||
//! \brief Wraps Read(), ensuring that the read succeeded and exactly \a size
|
//! \brief Wraps Read(), ensuring that the read succeeded and exactly \a size
|
||||||
//! bytes were read.
|
//! bytes were read.
|
||||||
@ -69,7 +69,7 @@ class WeakFileHandleFileReader : public FileReaderInterface {
|
|||||||
~WeakFileHandleFileReader() override;
|
~WeakFileHandleFileReader() override;
|
||||||
|
|
||||||
// FileReaderInterface:
|
// FileReaderInterface:
|
||||||
ssize_t Read(void* data, size_t size) override;
|
FileOperationResult Read(void* data, size_t size) override;
|
||||||
|
|
||||||
// FileSeekerInterface:
|
// FileSeekerInterface:
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ class FileReader : public FileReaderInterface {
|
|||||||
//!
|
//!
|
||||||
//! \note It is only valid to call this method between a successful Open() and
|
//! \note It is only valid to call this method between a successful Open() and
|
||||||
//! a Close().
|
//! a Close().
|
||||||
ssize_t Read(void* data, size_t size) override;
|
FileOperationResult Read(void* data, size_t size) override;
|
||||||
|
|
||||||
// FileSeekerInterface:
|
// FileSeekerInterface:
|
||||||
|
|
||||||
@ -160,7 +160,7 @@ class WeakStdioFileReader : public FileReaderInterface {
|
|||||||
~WeakStdioFileReader() override;
|
~WeakStdioFileReader() override;
|
||||||
|
|
||||||
// FileReaderInterface:
|
// FileReaderInterface:
|
||||||
ssize_t Read(void* data, size_t size) override;
|
FileOperationResult Read(void* data, size_t size) override;
|
||||||
|
|
||||||
// FileSeekerInterface:
|
// FileSeekerInterface:
|
||||||
|
|
||||||
|
@ -33,8 +33,9 @@ StringFile::~StringFile() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void StringFile::SetString(const std::string& string) {
|
void StringFile::SetString(const std::string& string) {
|
||||||
CHECK_LE(string.size(),
|
CHECK_LE(
|
||||||
implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()));
|
string.size(),
|
||||||
|
implicit_cast<size_t>(std::numeric_limits<FileOperationResult>::max()));
|
||||||
string_ = string;
|
string_ = string;
|
||||||
offset_ = 0;
|
offset_ = 0;
|
||||||
}
|
}
|
||||||
@ -44,7 +45,7 @@ void StringFile::Reset() {
|
|||||||
offset_ = 0;
|
offset_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t StringFile::Read(void* data, size_t size) {
|
FileOperationResult StringFile::Read(void* data, size_t size) {
|
||||||
DCHECK(offset_.IsValid());
|
DCHECK(offset_.IsValid());
|
||||||
|
|
||||||
const size_t offset = offset_.ValueOrDie();
|
const size_t offset = offset_.ValueOrDie();
|
||||||
@ -54,7 +55,7 @@ ssize_t StringFile::Read(void* data, size_t size) {
|
|||||||
|
|
||||||
const size_t nread = std::min(size, string_.size() - offset);
|
const size_t nread = std::min(size, string_.size() - offset);
|
||||||
|
|
||||||
base::CheckedNumeric<ssize_t> new_offset = offset_;
|
base::CheckedNumeric<FileOperationResult> new_offset = offset_;
|
||||||
new_offset += nread;
|
new_offset += nread;
|
||||||
if (!new_offset.IsValid()) {
|
if (!new_offset.IsValid()) {
|
||||||
LOG(ERROR) << "Read(): file too large";
|
LOG(ERROR) << "Read(): file too large";
|
||||||
@ -75,7 +76,7 @@ bool StringFile::Write(const void* data, size_t size) {
|
|||||||
string_.resize(offset);
|
string_.resize(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
base::CheckedNumeric<ssize_t> new_offset = offset_;
|
base::CheckedNumeric<FileOperationResult> new_offset = offset_;
|
||||||
new_offset += size;
|
new_offset += size;
|
||||||
if (!new_offset.IsValid()) {
|
if (!new_offset.IsValid()) {
|
||||||
LOG(ERROR) << "Write(): file too large";
|
LOG(ERROR) << "Write(): file too large";
|
||||||
@ -97,7 +98,7 @@ bool StringFile::WriteIoVec(std::vector<WritableIoVec>* iovecs) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Avoid writing anything at all if it would cause an overflow.
|
// Avoid writing anything at all if it would cause an overflow.
|
||||||
base::CheckedNumeric<ssize_t> new_offset = offset_;
|
base::CheckedNumeric<FileOperationResult> new_offset = offset_;
|
||||||
for (const WritableIoVec& iov : *iovecs) {
|
for (const WritableIoVec& iov : *iovecs) {
|
||||||
new_offset += iov.iov_len;
|
new_offset += iov.iov_len;
|
||||||
if (!new_offset.IsValid()) {
|
if (!new_offset.IsValid()) {
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
|
|
||||||
#include "base/basictypes.h"
|
#include "base/basictypes.h"
|
||||||
#include "base/numerics/safe_math.h"
|
#include "base/numerics/safe_math.h"
|
||||||
|
#include "util/file/file_io.h"
|
||||||
#include "util/file/file_reader.h"
|
#include "util/file/file_reader.h"
|
||||||
#include "util/file/file_writer.h"
|
#include "util/file/file_writer.h"
|
||||||
|
|
||||||
@ -50,7 +51,7 @@ class StringFile : public FileReaderInterface, public FileWriterInterface {
|
|||||||
void Reset();
|
void Reset();
|
||||||
|
|
||||||
// FileReaderInterface:
|
// FileReaderInterface:
|
||||||
ssize_t Read(void* data, size_t size) override;
|
FileOperationResult Read(void* data, size_t size) override;
|
||||||
|
|
||||||
// FileWriterInterface:
|
// FileWriterInterface:
|
||||||
bool Write(const void* data, size_t size) override;
|
bool Write(const void* data, size_t size) override;
|
||||||
|
@ -197,13 +197,16 @@ TEST(StringFile, WriteInvalid) {
|
|||||||
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
|
||||||
|
|
||||||
EXPECT_FALSE(string_file.Write(
|
EXPECT_FALSE(string_file.Write(
|
||||||
"", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()) + 1));
|
"",
|
||||||
|
implicit_cast<size_t>(std::numeric_limits<FileOperationResult>::max()) +
|
||||||
|
1));
|
||||||
EXPECT_TRUE(string_file.string().empty());
|
EXPECT_TRUE(string_file.string().empty());
|
||||||
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(0, string_file.Seek(0, SEEK_CUR));
|
||||||
|
|
||||||
EXPECT_TRUE(string_file.Write("a", 1));
|
EXPECT_TRUE(string_file.Write("a", 1));
|
||||||
EXPECT_FALSE(string_file.Write(
|
EXPECT_FALSE(string_file.Write(
|
||||||
"", implicit_cast<size_t>(std::numeric_limits<ssize_t>::max())));
|
"",
|
||||||
|
implicit_cast<size_t>(std::numeric_limits<FileOperationResult>::max())));
|
||||||
EXPECT_EQ(1u, string_file.string().size());
|
EXPECT_EQ(1u, string_file.string().size());
|
||||||
EXPECT_EQ("a", string_file.string());
|
EXPECT_EQ("a", string_file.string());
|
||||||
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
|
||||||
@ -290,7 +293,7 @@ TEST(StringFile, WriteIoVecInvalid) {
|
|||||||
WritableIoVec iov;
|
WritableIoVec iov;
|
||||||
EXPECT_EQ(1, string_file.Seek(1, SEEK_CUR));
|
EXPECT_EQ(1, string_file.Seek(1, SEEK_CUR));
|
||||||
iov.iov_base = "a";
|
iov.iov_base = "a";
|
||||||
iov.iov_len = std::numeric_limits<ssize_t>::max();
|
iov.iov_len = std::numeric_limits<FileOperationResult>::max();
|
||||||
iovecs.push_back(iov);
|
iovecs.push_back(iov);
|
||||||
EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
|
EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
|
||||||
EXPECT_TRUE(string_file.string().empty());
|
EXPECT_TRUE(string_file.string().empty());
|
||||||
@ -300,7 +303,7 @@ TEST(StringFile, WriteIoVecInvalid) {
|
|||||||
iov.iov_base = "a";
|
iov.iov_base = "a";
|
||||||
iov.iov_len = 1;
|
iov.iov_len = 1;
|
||||||
iovecs.push_back(iov);
|
iovecs.push_back(iov);
|
||||||
iov.iov_len = std::numeric_limits<ssize_t>::max() - 1;
|
iov.iov_len = std::numeric_limits<FileOperationResult>::max() - 1;
|
||||||
iovecs.push_back(iov);
|
iovecs.push_back(iov);
|
||||||
EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
|
EXPECT_FALSE(string_file.WriteIoVec(&iovecs));
|
||||||
EXPECT_TRUE(string_file.string().empty());
|
EXPECT_TRUE(string_file.string().empty());
|
||||||
@ -449,7 +452,9 @@ TEST(StringFile, SeekInvalid) {
|
|||||||
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
|
||||||
EXPECT_LT(string_file.Seek(-1, SEEK_SET), 0);
|
EXPECT_LT(string_file.Seek(-1, SEEK_SET), 0);
|
||||||
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
|
||||||
EXPECT_LT(string_file.Seek(std::numeric_limits<ssize_t>::min(), SEEK_SET), 0);
|
EXPECT_LT(string_file.Seek(std::numeric_limits<FileOperationResult>::min(),
|
||||||
|
SEEK_SET),
|
||||||
|
0);
|
||||||
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(1, string_file.Seek(0, SEEK_CUR));
|
||||||
EXPECT_LT(string_file.Seek(std::numeric_limits<FileOffset>::min(), SEEK_SET),
|
EXPECT_LT(string_file.Seek(std::numeric_limits<FileOffset>::min(), SEEK_SET),
|
||||||
0);
|
0);
|
||||||
@ -487,7 +492,8 @@ TEST(StringFile, SeekSet) {
|
|||||||
EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
|
||||||
EXPECT_FALSE(string_file.SeekSet(-1));
|
EXPECT_FALSE(string_file.SeekSet(-1));
|
||||||
EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
|
||||||
EXPECT_FALSE(string_file.SeekSet(std::numeric_limits<ssize_t>::min()));
|
EXPECT_FALSE(
|
||||||
|
string_file.SeekSet(std::numeric_limits<FileOperationResult>::min()));
|
||||||
EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
|
||||||
EXPECT_FALSE(string_file.SeekSet(std::numeric_limits<FileOffset>::min()));
|
EXPECT_FALSE(string_file.SeekSet(std::numeric_limits<FileOffset>::min()));
|
||||||
EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
|
EXPECT_EQ(10, string_file.Seek(0, SEEK_CUR));
|
||||||
|
@ -32,15 +32,16 @@ StringHTTPBodyStream::StringHTTPBodyStream(const std::string& string)
|
|||||||
StringHTTPBodyStream::~StringHTTPBodyStream() {
|
StringHTTPBodyStream::~StringHTTPBodyStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t StringHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, size_t max_len) {
|
FileOperationResult StringHTTPBodyStream::GetBytesBuffer(uint8_t* buffer,
|
||||||
|
size_t max_len) {
|
||||||
size_t num_bytes_remaining = string_.length() - bytes_read_;
|
size_t num_bytes_remaining = string_.length() - bytes_read_;
|
||||||
if (num_bytes_remaining == 0) {
|
if (num_bytes_remaining == 0) {
|
||||||
return num_bytes_remaining;
|
return num_bytes_remaining;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t num_bytes_returned =
|
size_t num_bytes_returned = std::min(
|
||||||
std::min(std::min(num_bytes_remaining, max_len),
|
std::min(num_bytes_remaining, max_len),
|
||||||
implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()));
|
implicit_cast<size_t>(std::numeric_limits<FileOperationResult>::max()));
|
||||||
memcpy(buffer, &string_[bytes_read_], num_bytes_returned);
|
memcpy(buffer, &string_[bytes_read_], num_bytes_returned);
|
||||||
bytes_read_ += num_bytes_returned;
|
bytes_read_ += num_bytes_returned;
|
||||||
return num_bytes_returned;
|
return num_bytes_returned;
|
||||||
@ -53,7 +54,8 @@ FileHTTPBodyStream::FileHTTPBodyStream(const base::FilePath& path)
|
|||||||
FileHTTPBodyStream::~FileHTTPBodyStream() {
|
FileHTTPBodyStream::~FileHTTPBodyStream() {
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t FileHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, size_t max_len) {
|
FileOperationResult FileHTTPBodyStream::GetBytesBuffer(uint8_t* buffer,
|
||||||
|
size_t max_len) {
|
||||||
switch (file_state_) {
|
switch (file_state_) {
|
||||||
case kUnopenedFile:
|
case kUnopenedFile:
|
||||||
file_.reset(LoggingOpenFileForRead(path_));
|
file_.reset(LoggingOpenFileForRead(path_));
|
||||||
@ -71,7 +73,7 @@ ssize_t FileHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, size_t max_len) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t rv = ReadFile(file_.get(), buffer, max_len);
|
FileOperationResult rv = ReadFile(file_.get(), buffer, max_len);
|
||||||
if (rv == 0) {
|
if (rv == 0) {
|
||||||
file_.reset();
|
file_.reset();
|
||||||
file_state_ = kClosedAtEOF;
|
file_state_ = kClosedAtEOF;
|
||||||
@ -90,14 +92,16 @@ CompositeHTTPBodyStream::~CompositeHTTPBodyStream() {
|
|||||||
STLDeleteContainerPointers(parts_.begin(), parts_.end());
|
STLDeleteContainerPointers(parts_.begin(), parts_.end());
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t CompositeHTTPBodyStream::GetBytesBuffer(uint8_t* buffer,
|
FileOperationResult CompositeHTTPBodyStream::GetBytesBuffer(uint8_t* buffer,
|
||||||
size_t buffer_len) {
|
size_t buffer_len) {
|
||||||
ssize_t max_len = std::min(
|
FileOperationResult max_len = std::min(
|
||||||
buffer_len, implicit_cast<size_t>(std::numeric_limits<ssize_t>::max()));
|
buffer_len,
|
||||||
ssize_t bytes_copied = 0;
|
implicit_cast<size_t>(std::numeric_limits<FileOperationResult>::max()));
|
||||||
|
FileOperationResult bytes_copied = 0;
|
||||||
while (bytes_copied < max_len && current_part_ != parts_.end()) {
|
while (bytes_copied < max_len && current_part_ != parts_.end()) {
|
||||||
ssize_t this_read = (*current_part_)->GetBytesBuffer(
|
FileOperationResult this_read =
|
||||||
buffer + bytes_copied, max_len - bytes_copied);
|
(*current_part_)
|
||||||
|
->GetBytesBuffer(buffer + bytes_copied, max_len - bytes_copied);
|
||||||
|
|
||||||
if (this_read == 0) {
|
if (this_read == 0) {
|
||||||
// If the current part has returned 0 indicating EOF, advance the current
|
// If the current part has returned 0 indicating EOF, advance the current
|
||||||
|
@ -42,7 +42,8 @@ class HTTPBodyStream {
|
|||||||
//! \return On success, a positive number indicating the number of bytes
|
//! \return On success, a positive number indicating the number of bytes
|
||||||
//! actually copied to \a buffer. On failure, a negative number. When
|
//! actually copied to \a buffer. On failure, a negative number. When
|
||||||
//! the stream has no more data, returns `0`.
|
//! the stream has no more data, returns `0`.
|
||||||
virtual ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) = 0;
|
virtual FileOperationResult GetBytesBuffer(uint8_t* buffer,
|
||||||
|
size_t max_len) = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HTTPBodyStream() {}
|
HTTPBodyStream() {}
|
||||||
@ -60,7 +61,7 @@ class StringHTTPBodyStream : public HTTPBodyStream {
|
|||||||
~StringHTTPBodyStream() override;
|
~StringHTTPBodyStream() override;
|
||||||
|
|
||||||
// HTTPBodyStream:
|
// HTTPBodyStream:
|
||||||
ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
|
FileOperationResult GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string string_;
|
std::string string_;
|
||||||
@ -81,7 +82,7 @@ class FileHTTPBodyStream : public HTTPBodyStream {
|
|||||||
~FileHTTPBodyStream() override;
|
~FileHTTPBodyStream() override;
|
||||||
|
|
||||||
// HTTPBodyStream:
|
// HTTPBodyStream:
|
||||||
ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
|
FileOperationResult GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum FileState {
|
enum FileState {
|
||||||
@ -115,7 +116,7 @@ class CompositeHTTPBodyStream : public HTTPBodyStream {
|
|||||||
~CompositeHTTPBodyStream() override;
|
~CompositeHTTPBodyStream() override;
|
||||||
|
|
||||||
// HTTPBodyStream:
|
// HTTPBodyStream:
|
||||||
ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
|
FileOperationResult GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
PartsList parts_;
|
PartsList parts_;
|
||||||
|
@ -47,7 +47,7 @@ TEST(StringHTTPBodyStream, SmallString) {
|
|||||||
|
|
||||||
std::string string("Hello, world");
|
std::string string("Hello, world");
|
||||||
StringHTTPBodyStream stream(string);
|
StringHTTPBodyStream stream(string);
|
||||||
EXPECT_EQ(implicit_cast<ssize_t>(string.length()),
|
EXPECT_EQ(implicit_cast<FileOperationResult>(string.length()),
|
||||||
stream.GetBytesBuffer(buf, sizeof(buf)));
|
stream.GetBytesBuffer(buf, sizeof(buf)));
|
||||||
|
|
||||||
std::string actual(reinterpret_cast<const char*>(buf), string.length());
|
std::string actual(reinterpret_cast<const char*>(buf), string.length());
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
#include "base/memory/scoped_ptr.h"
|
#include "base/memory/scoped_ptr.h"
|
||||||
#include "gtest/gtest.h"
|
#include "gtest/gtest.h"
|
||||||
|
#include "util/file/file_io.h"
|
||||||
#include "util/net/http_body.h"
|
#include "util/net/http_body.h"
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
@ -31,7 +32,7 @@ std::string ReadStreamToString(HTTPBodyStream* stream, size_t buffer_size) {
|
|||||||
scoped_ptr<uint8_t[]> buf(new uint8_t[buffer_size]);
|
scoped_ptr<uint8_t[]> buf(new uint8_t[buffer_size]);
|
||||||
std::string result;
|
std::string result;
|
||||||
|
|
||||||
ssize_t bytes_read;
|
FileOperationResult bytes_read;
|
||||||
while ((bytes_read = stream->GetBytesBuffer(buf.get(), buffer_size)) != 0) {
|
while ((bytes_read = stream->GetBytesBuffer(buf.get(), buffer_size)) != 0) {
|
||||||
if (bytes_read < 0) {
|
if (bytes_read < 0) {
|
||||||
ADD_FAILURE() << "Failed to read from stream: " << bytes_read;
|
ADD_FAILURE() << "Failed to read from stream: " << bytes_read;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "base/strings/sys_string_conversions.h"
|
#include "base/strings/sys_string_conversions.h"
|
||||||
#include "third_party/apple_cf/CFStreamAbstract.h"
|
#include "third_party/apple_cf/CFStreamAbstract.h"
|
||||||
|
#include "util/file/file_io.h"
|
||||||
#include "util/misc/implicit_cast.h"
|
#include "util/misc/implicit_cast.h"
|
||||||
#include "util/net/http_body.h"
|
#include "util/net/http_body.h"
|
||||||
|
|
||||||
@ -93,7 +94,8 @@ class HTTPBodyStreamCFReadStream {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t bytes_read = GetStream(info)->GetBytesBuffer(buffer, buffer_length);
|
FileOperationResult bytes_read =
|
||||||
|
GetStream(info)->GetBytesBuffer(buffer, buffer_length);
|
||||||
if (bytes_read < 0) {
|
if (bytes_read < 0) {
|
||||||
error->error = -1;
|
error->error = -1;
|
||||||
error->domain = kCFStreamErrorDomainCustom;
|
error->domain = kCFStreamErrorDomainCustom;
|
||||||
|
@ -121,7 +121,7 @@ class HTTPTransportTestFixture : public MultiprocessExec {
|
|||||||
// Read until the child's stdout closes.
|
// Read until the child's stdout closes.
|
||||||
std::string request;
|
std::string request;
|
||||||
char buf[32];
|
char buf[32];
|
||||||
ssize_t bytes_read;
|
FileOperationResult bytes_read;
|
||||||
while ((bytes_read = ReadFile(ReadPipeHandle(), buf, sizeof(buf))) != 0) {
|
while ((bytes_read = ReadFile(ReadPipeHandle(), buf, sizeof(buf))) != 0) {
|
||||||
ASSERT_GE(bytes_read, 0);
|
ASSERT_GE(bytes_read, 0);
|
||||||
request.append(buf, bytes_read);
|
request.append(buf, bytes_read);
|
||||||
|
@ -22,8 +22,9 @@
|
|||||||
#include "base/scoped_generic.h"
|
#include "base/scoped_generic.h"
|
||||||
#include "base/strings/stringprintf.h"
|
#include "base/strings/stringprintf.h"
|
||||||
#include "base/strings/utf_string_conversions.h"
|
#include "base/strings/utf_string_conversions.h"
|
||||||
#include "util/net/http_body.h"
|
|
||||||
#include "package.h"
|
#include "package.h"
|
||||||
|
#include "util/file/file_io.h"
|
||||||
|
#include "util/net/http_body.h"
|
||||||
|
|
||||||
namespace crashpad {
|
namespace crashpad {
|
||||||
|
|
||||||
@ -174,7 +175,7 @@ bool HTTPTransportWin::ExecuteSynchronously(std::string* response_body) {
|
|||||||
const size_t kBufferSize = 4096;
|
const size_t kBufferSize = 4096;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
uint8_t buffer[kBufferSize];
|
uint8_t buffer[kBufferSize];
|
||||||
ssize_t bytes_to_write =
|
FileOperationResult bytes_to_write =
|
||||||
body_stream()->GetBytesBuffer(buffer, sizeof(buffer));
|
body_stream()->GetBytesBuffer(buffer, sizeof(buffer));
|
||||||
if (bytes_to_write == 0)
|
if (bytes_to_write == 0)
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user