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

Side by Side Diff: util/net/http_body.cc

Issue 811823003: Cross platform low level file IO wrappers (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: . 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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Crashpad Authors. All rights reserved. 1 // Copyright 2014 The Crashpad Authors. All rights reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 #include "util/net/http_body.h" 15 #include "util/net/http_body.h"
16 16
17 #include <fcntl.h> 17 #include <fcntl.h>
18 #include <string.h> 18 #include <string.h>
19 #include <unistd.h> 19 #include <unistd.h>
20 20
21 #include <algorithm> 21 #include <algorithm>
22 #include <limits> 22 #include <limits>
23 23
24 #include "base/logging.h" 24 #include "base/logging.h"
25 #include "base/posix/eintr_wrapper.h" 25 #include "base/posix/eintr_wrapper.h"
26 #include "base/stl_util.h" 26 #include "base/stl_util.h"
27 #include "util/file/fd_io.h" 27 #include "util/file/file_io.h"
28 28
29 namespace crashpad { 29 namespace crashpad {
30 30
31 StringHTTPBodyStream::StringHTTPBodyStream(const std::string& string) 31 StringHTTPBodyStream::StringHTTPBodyStream(const std::string& string)
32 : HTTPBodyStream(), string_(string), bytes_read_() { 32 : HTTPBodyStream(), string_(string), bytes_read_() {
33 } 33 }
34 34
35 StringHTTPBodyStream::~StringHTTPBodyStream() { 35 StringHTTPBodyStream::~StringHTTPBodyStream() {
36 } 36 }
37 37
(...skipping 10 matching lines...) Expand all
48 bytes_read_ += num_bytes_returned; 48 bytes_read_ += num_bytes_returned;
49 return num_bytes_returned; 49 return num_bytes_returned;
50 } 50 }
51 51
52 FileHTTPBodyStream::FileHTTPBodyStream(const base::FilePath& path) 52 FileHTTPBodyStream::FileHTTPBodyStream(const base::FilePath& path)
53 : HTTPBodyStream(), path_(path), fd_(kUnopenedFile) { 53 : HTTPBodyStream(), path_(path), fd_(kUnopenedFile) {
54 } 54 }
55 55
56 FileHTTPBodyStream::~FileHTTPBodyStream() { 56 FileHTTPBodyStream::~FileHTTPBodyStream() {
57 if (fd_ >= 0) { 57 if (fd_ >= 0) {
58 LoggingCloseFD(fd_); 58 LoggingCloseFile(fd_);
59 } 59 }
60 } 60 }
61 61
62 ssize_t FileHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, size_t max_len) { 62 ssize_t FileHTTPBodyStream::GetBytesBuffer(uint8_t* buffer, size_t max_len) {
63 switch (fd_) { 63 switch (fd_) {
64 case kUnopenedFile: 64 case kUnopenedFile:
65 fd_ = HANDLE_EINTR(open(path_.value().c_str(), O_RDONLY)); 65 fd_ = HANDLE_EINTR(open(path_.value().c_str(), O_RDONLY));
66 if (fd_ < 0) { 66 if (fd_ < 0) {
67 fd_ = kFileOpenError; 67 fd_ = kFileOpenError;
68 PLOG(ERROR) << "Cannot open " << path_.value(); 68 PLOG(ERROR) << "Cannot open " << path_.value();
69 return -1; 69 return -1;
70 } 70 }
71 break; 71 break;
72 case kFileOpenError: 72 case kFileOpenError:
73 return -1; 73 return -1;
74 case kClosedAtEOF: 74 case kClosedAtEOF:
75 return 0; 75 return 0;
76 default: 76 default:
77 break; 77 break;
78 } 78 }
79 79
80 ssize_t rv = ReadFD(fd_, buffer, max_len); 80 ssize_t rv = ReadFile(fd_, buffer, max_len);
81 if (rv == 0) { 81 if (rv == 0) {
82 LoggingCloseFD(fd_); 82 LoggingCloseFile(fd_);
83 fd_ = kClosedAtEOF; 83 fd_ = kClosedAtEOF;
84 } else if (rv < 0) { 84 } else if (rv < 0) {
85 PLOG(ERROR) << "read"; 85 PLOG(ERROR) << "read";
86 } 86 }
87 return rv; 87 return rv;
88 } 88 }
89 89
90 CompositeHTTPBodyStream::CompositeHTTPBodyStream( 90 CompositeHTTPBodyStream::CompositeHTTPBodyStream(
91 const CompositeHTTPBodyStream::PartsList& parts) 91 const CompositeHTTPBodyStream::PartsList& parts)
92 : HTTPBodyStream(), parts_(parts), current_part_(parts_.begin()) { 92 : HTTPBodyStream(), parts_(parts), current_part_(parts_.begin()) {
(...skipping 19 matching lines...) Expand all
112 } else if (this_read < 0) { 112 } else if (this_read < 0) {
113 return this_read; 113 return this_read;
114 } 114 }
115 bytes_copied += this_read; 115 bytes_copied += this_read;
116 } 116 }
117 117
118 return bytes_copied; 118 return bytes_copied;
119 } 119 }
120 120
121 } // namespace crashpad 121 } // namespace crashpad
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698