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

Side by Side Diff: net/base/file_stream_win.cc

Issue 21363: Adds a new method ReadUntilComplete to FileStream which ensure that a... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 months 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 | Annotate | Revision Log
« no previous file with comments | « net/base/file_stream_posix.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. Use of this
2 // source code is governed by a BSD-style license that can be found in the 2 // source code is governed by a BSD-style license that can be found in the
3 // LICENSE file. 3 // LICENSE file.
4 4
5 #include "net/base/file_stream.h" 5 #include "net/base/file_stream.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 227 }
228 } else if (overlapped) { 228 } else if (overlapped) {
229 async_context_->IOCompletionIsPending(callback); 229 async_context_->IOCompletionIsPending(callback);
230 rv = ERR_IO_PENDING; 230 rv = ERR_IO_PENDING;
231 } else { 231 } else {
232 rv = static_cast<int>(bytes_read); 232 rv = static_cast<int>(bytes_read);
233 } 233 }
234 return rv; 234 return rv;
235 } 235 }
236 236
237 int FileStream::ReadUntilComplete(char *buf, int buf_len) {
238 int to_read = buf_len;
239 int bytes_total = 0;
240
241 do {
242 int bytes_read = Read(buf, to_read, NULL);
243 if (bytes_read <= 0) {
244 if (bytes_total == 0)
245 return bytes_read;
246
247 return bytes_total;
248 }
249
250 bytes_total += bytes_read;
251 buf += bytes_read;
252 to_read -= bytes_read;
253 } while (bytes_total < buf_len);
254
255 return bytes_total;
256 }
257
237 int FileStream::Write( 258 int FileStream::Write(
238 const char* buf, int buf_len, CompletionCallback* callback) { 259 const char* buf, int buf_len, CompletionCallback* callback) {
239 if (!IsOpen()) 260 if (!IsOpen())
240 return ERR_UNEXPECTED; 261 return ERR_UNEXPECTED;
241 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE); 262 DCHECK(open_flags_ & base::PLATFORM_FILE_WRITE);
242 263
243 OVERLAPPED* overlapped = NULL; 264 OVERLAPPED* overlapped = NULL;
244 if (async_context_.get()) { 265 if (async_context_.get()) {
245 DCHECK(!async_context_->callback()); 266 DCHECK(!async_context_->callback());
246 overlapped = async_context_->overlapped(); 267 overlapped = async_context_->overlapped();
(...skipping 14 matching lines...) Expand all
261 async_context_->IOCompletionIsPending(callback); 282 async_context_->IOCompletionIsPending(callback);
262 rv = ERR_IO_PENDING; 283 rv = ERR_IO_PENDING;
263 } else { 284 } else {
264 rv = static_cast<int>(bytes_written); 285 rv = static_cast<int>(bytes_written);
265 } 286 }
266 return rv; 287 return rv;
267 } 288 }
268 289
269 } // namespace net 290 } // namespace net
270 291
OLDNEW
« no previous file with comments | « net/base/file_stream_posix.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698