'util' builds on Windows after this.

R=mark@chromium.org, rsesek@chromium.org
BUG=crashpad:1

Review URL: https://codereview.chromium.org/791493007
This commit is contained in:
Scott Graham 2014-12-19 15:21:19 -08:00
Родитель 4e8a78c182
Коммит 9cfd2c515e
2 изменённых файлов: 18 добавлений и 26 удалений

Просмотреть файл

@ -14,17 +14,13 @@
#include "util/net/http_body.h"
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <algorithm>
#include <limits>
#include "base/logging.h"
#include "base/posix/eintr_wrapper.h"
#include "base/stl_util.h"
#include "util/file/file_io.h"
namespace crashpad {
@ -50,37 +46,34 @@ ssize_t StringHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, size_t max_len) {
}
FileHTTPBodyStream::FileHTTPBodyStream(const base::FilePath& path)
: HTTPBodyStream(), path_(path), fd_(kUnopenedFile) {
: HTTPBodyStream(), path_(path), file_(), file_state_(kUnopenedFile) {
}
FileHTTPBodyStream::~FileHTTPBodyStream() {
if (fd_ >= 0) {
LoggingCloseFile(fd_);
}
}
ssize_t FileHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, size_t max_len) {
switch (fd_) {
switch (file_state_) {
case kUnopenedFile:
fd_ = HANDLE_EINTR(open(path_.value().c_str(), O_RDONLY));
if (fd_ < 0) {
fd_ = kFileOpenError;
PLOG(ERROR) << "Cannot open " << path_.value();
file_.reset(LoggingOpenFileForRead(path_));
if (!file_.is_valid()) {
file_state_ = kFileOpenError;
return -1;
}
file_state_ = kReading;
break;
case kFileOpenError:
return -1;
case kClosedAtEOF:
return 0;
default:
case kReading:
break;
}
ssize_t rv = ReadFile(fd_, buffer, max_len);
ssize_t rv = ReadFile(file_.get(), buffer, max_len);
if (rv == 0) {
LoggingCloseFile(fd_);
fd_ = kClosedAtEOF;
file_.reset();
file_state_ = kClosedAtEOF;
} else if (rv < 0) {
PLOG(ERROR) << "read";
}

Просмотреть файл

@ -23,6 +23,7 @@
#include "base/basictypes.h"
#include "base/files/file_path.h"
#include "util/file/file_io.h"
namespace crashpad {
@ -83,18 +84,16 @@ class FileHTTPBodyStream : public HTTPBodyStream {
ssize_t GetBytesBuffer(uint8_t* buffer, size_t max_len) override;
private:
enum InvalidFD {
kUnopenedFile = -1,
kFileOpenError = -2,
kClosedAtEOF = -3,
enum FileState {
kUnopenedFile,
kFileOpenError,
kClosedAtEOF,
kReading,
};
base::FilePath path_;
// If |fd_| is greater than or equal to zero, it is an opened descriptor
// from which an instance of this class is reading. If |fd_| is less than
// zero, the value corresponds to an InvalidFD value.
int fd_;
ScopedFileHandle file_;
FileState file_state_;
DISALLOW_COPY_AND_ASSIGN(FileHTTPBodyStream);
};