| OLD | NEW |
| 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 /* Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be | 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. | 3 * found in the LICENSE file. |
| 4 */ | 4 */ |
| 5 | 5 |
| 6 #include "nacl_io/mount_http.h" | 6 #include "nacl_io/mount_http.h" |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <ctype.h> | 8 #include <ctype.h> |
| 9 #include <errno.h> | 9 #include <errno.h> |
| 10 #include <fcntl.h> | 10 #include <fcntl.h> |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 411 if (real_size < 0) | 411 if (real_size < 0) |
| 412 return -1; | 412 return -1; |
| 413 | 413 |
| 414 SetCachedSize(real_size); | 414 SetCachedSize(real_size); |
| 415 cached_data_.resize(real_size); | 415 cached_data_.resize(real_size); |
| 416 return real_size; | 416 return real_size; |
| 417 } | 417 } |
| 418 | 418 |
| 419 // We don't know how big the file is. Read in chunks. | 419 // We don't know how big the file is. Read in chunks. |
| 420 cached_data_.resize(MAX_READ_BUFFER_SIZE); | 420 cached_data_.resize(MAX_READ_BUFFER_SIZE); |
| 421 char* buf = cached_data_.data(); | |
| 422 size_t total_bytes_read = 0; | 421 size_t total_bytes_read = 0; |
| 423 size_t bytes_to_read = MAX_READ_BUFFER_SIZE; | 422 size_t bytes_to_read = MAX_READ_BUFFER_SIZE; |
| 424 while (true) { | 423 while (true) { |
| 424 char* buf = cached_data_.data() + total_bytes_read; |
| 425 int bytes_read = DownloadToBuffer(loader, buf, bytes_to_read); | 425 int bytes_read = DownloadToBuffer(loader, buf, bytes_to_read); |
| 426 if (bytes_read < 0) | 426 if (bytes_read < 0) |
| 427 return -1; | 427 return -1; |
| 428 | 428 |
| 429 total_bytes_read += bytes_read; | 429 total_bytes_read += bytes_read; |
| 430 | 430 |
| 431 if (bytes_read < bytes_to_read) { | 431 if (bytes_read < bytes_to_read) { |
| 432 SetCachedSize(total_bytes_read); | 432 SetCachedSize(total_bytes_read); |
| 433 cached_data_.resize(total_bytes_read); | 433 cached_data_.resize(total_bytes_read); |
| 434 return total_bytes_read; | 434 return total_bytes_read; |
| 435 } | 435 } |
| 436 | 436 |
| 437 buf += bytes_read; | |
| 438 cached_data_.resize(total_bytes_read + bytes_to_read); | 437 cached_data_.resize(total_bytes_read + bytes_to_read); |
| 439 } | 438 } |
| 440 } | 439 } |
| 441 | 440 |
| 442 int MountNodeHttp::ReadPartialFromCache(size_t offs, void* buf, size_t count) { | 441 int MountNodeHttp::ReadPartialFromCache(size_t offs, void* buf, size_t count) { |
| 443 if (offs > cached_data_.size()) { | 442 if (offs > cached_data_.size()) { |
| 444 errno = EINVAL; | 443 errno = EINVAL; |
| 445 return -1; | 444 return -1; |
| 446 } | 445 } |
| 447 | 446 |
| (...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 off_t len = manifest_node->Read(0, text, manifest_node->GetSize()); | 793 off_t len = manifest_node->Read(0, text, manifest_node->GetSize()); |
| 795 manifest_node->Release(); | 794 manifest_node->Release(); |
| 796 | 795 |
| 797 text[len] = 0; | 796 text[len] = 0; |
| 798 return text; | 797 return text; |
| 799 } | 798 } |
| 800 | 799 |
| 801 fprintf(stderr, "Could not open manifest: %s\n", manifest_name.c_str()); | 800 fprintf(stderr, "Could not open manifest: %s\n", manifest_name.c_str()); |
| 802 return NULL; | 801 return NULL; |
| 803 } | 802 } |
| OLD | NEW |