Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(52)

Unified Diff: util/net/http_body.cc

Issue 791493007: Make http_body cross-platform (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@file-writer-redux
Patch Set: fixes Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/net/http_body.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/net/http_body.cc
diff --git a/util/net/http_body.cc b/util/net/http_body.cc
index e731c598e4d0257b7627cdd27987a789164f19b6..cdf810e37f5eeda4a264685306473d6d2bbac944 100644
--- a/util/net/http_body.cc
+++ b/util/net/http_body.cc
@@ -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";
}
« no previous file with comments | « util/net/http_body.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698