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 // For 64-bit file access (off_t = off64_t, lseek64, etc). | 5 // For 64-bit file access (off_t = off64_t, lseek64, etc). |
6 #define _FILE_OFFSET_BITS 64 | 6 #define _FILE_OFFSET_BITS 64 |
7 | 7 |
8 #include "net/base/file_stream_context.h" | 8 #include "net/base/file_stream_context.h" |
9 | 9 |
10 #include <errno.h> | 10 #include <errno.h> |
(...skipping 22 matching lines...) Expand all Loading... |
33 #define stat stat64 | 33 #define stat stat64 |
34 #define fstat fstat64 | 34 #define fstat fstat64 |
35 #endif | 35 #endif |
36 | 36 |
37 namespace net { | 37 namespace net { |
38 | 38 |
39 // We cast back and forth, so make sure it's the size we're expecting. | 39 // We cast back and forth, so make sure it's the size we're expecting. |
40 COMPILE_ASSERT(sizeof(int64) == sizeof(off_t), off_t_64_bit); | 40 COMPILE_ASSERT(sizeof(int64) == sizeof(off_t), off_t_64_bit); |
41 | 41 |
42 // Make sure our Whence mappings match the system headers. | 42 // Make sure our Whence mappings match the system headers. |
43 COMPILE_ASSERT(FROM_BEGIN == SEEK_SET && | 43 COMPILE_ASSERT(FROM_BEGIN == SEEK_SET&& FROM_CURRENT == SEEK_CUR&& FROM_END == |
44 FROM_CURRENT == SEEK_CUR && | 44 SEEK_END, |
45 FROM_END == SEEK_END, whence_matches_system); | 45 whence_matches_system); |
46 | 46 |
47 FileStream::Context::Context(const scoped_refptr<base::TaskRunner>& task_runner) | 47 FileStream::Context::Context(const scoped_refptr<base::TaskRunner>& task_runner) |
48 : async_in_progress_(false), | 48 : async_in_progress_(false), orphaned_(false), task_runner_(task_runner) { |
49 orphaned_(false), | |
50 task_runner_(task_runner) { | |
51 } | 49 } |
52 | 50 |
53 FileStream::Context::Context(base::File file, | 51 FileStream::Context::Context(base::File file, |
54 const scoped_refptr<base::TaskRunner>& task_runner) | 52 const scoped_refptr<base::TaskRunner>& task_runner) |
55 : file_(file.Pass()), | 53 : file_(file.Pass()), |
56 async_in_progress_(false), | 54 async_in_progress_(false), |
57 orphaned_(false), | 55 orphaned_(false), |
58 task_runner_(task_runner) { | 56 task_runner_(task_runner) { |
59 } | 57 } |
60 | 58 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 base::Unretained(this), | 92 base::Unretained(this), |
95 IntToInt64(callback))); | 93 IntToInt64(callback))); |
96 DCHECK(posted); | 94 DCHECK(posted); |
97 | 95 |
98 async_in_progress_ = true; | 96 async_in_progress_ = true; |
99 return ERR_IO_PENDING; | 97 return ERR_IO_PENDING; |
100 } | 98 } |
101 | 99 |
102 FileStream::Context::IOResult FileStream::Context::SeekFileImpl(Whence whence, | 100 FileStream::Context::IOResult FileStream::Context::SeekFileImpl(Whence whence, |
103 int64 offset) { | 101 int64 offset) { |
104 off_t res = lseek(file_.GetPlatformFile(), static_cast<off_t>(offset), | 102 off_t res = lseek(file_.GetPlatformFile(), |
| 103 static_cast<off_t>(offset), |
105 static_cast<int>(whence)); | 104 static_cast<int>(whence)); |
106 if (res == static_cast<off_t>(-1)) | 105 if (res == static_cast<off_t>(-1)) |
107 return IOResult::FromOSError(errno); | 106 return IOResult::FromOSError(errno); |
108 | 107 |
109 return IOResult(res, 0); | 108 return IOResult(res, 0); |
110 } | 109 } |
111 | 110 |
112 FileStream::Context::IOResult FileStream::Context::FlushFileImpl() { | 111 FileStream::Context::IOResult FileStream::Context::FlushFileImpl() { |
113 ssize_t res = HANDLE_EINTR(fsync(file_.GetPlatformFile())); | 112 ssize_t res = HANDLE_EINTR(fsync(file_.GetPlatformFile())); |
114 if (res == -1) | 113 if (res == -1) |
115 return IOResult::FromOSError(errno); | 114 return IOResult::FromOSError(errno); |
116 | 115 |
117 return IOResult(res, 0); | 116 return IOResult(res, 0); |
118 } | 117 } |
119 | 118 |
120 FileStream::Context::IOResult FileStream::Context::ReadFileImpl( | 119 FileStream::Context::IOResult FileStream::Context::ReadFileImpl( |
121 scoped_refptr<IOBuffer> buf, | 120 scoped_refptr<IOBuffer> buf, |
122 int buf_len) { | 121 int buf_len) { |
123 // Loop in the case of getting interrupted by a signal. | 122 // Loop in the case of getting interrupted by a signal. |
124 ssize_t res = HANDLE_EINTR(read(file_.GetPlatformFile(), buf->data(), | 123 ssize_t res = HANDLE_EINTR( |
125 static_cast<size_t>(buf_len))); | 124 read(file_.GetPlatformFile(), buf->data(), static_cast<size_t>(buf_len))); |
126 if (res == -1) | 125 if (res == -1) |
127 return IOResult::FromOSError(errno); | 126 return IOResult::FromOSError(errno); |
128 | 127 |
129 return IOResult(res, 0); | 128 return IOResult(res, 0); |
130 } | 129 } |
131 | 130 |
132 FileStream::Context::IOResult FileStream::Context::WriteFileImpl( | 131 FileStream::Context::IOResult FileStream::Context::WriteFileImpl( |
133 scoped_refptr<IOBuffer> buf, | 132 scoped_refptr<IOBuffer> buf, |
134 int buf_len) { | 133 int buf_len) { |
135 ssize_t res = HANDLE_EINTR(write(file_.GetPlatformFile(), buf->data(), | 134 ssize_t res = |
136 buf_len)); | 135 HANDLE_EINTR(write(file_.GetPlatformFile(), buf->data(), buf_len)); |
137 if (res == -1) | 136 if (res == -1) |
138 return IOResult::FromOSError(errno); | 137 return IOResult::FromOSError(errno); |
139 | 138 |
140 return IOResult(res, 0); | 139 return IOResult(res, 0); |
141 } | 140 } |
142 | 141 |
143 } // namespace net | 142 } // namespace net |
OLD | NEW |