Index: net/base/file_stream_context_posix.cc |
diff --git a/net/base/file_stream_context_posix.cc b/net/base/file_stream_context_posix.cc |
index 0c16ef4160bee5a8a73991ee72574bf384cfe40d..1bc1640c4bd5faa3ca353d8998dfcaf1762c7c68 100644 |
--- a/net/base/file_stream_context_posix.cc |
+++ b/net/base/file_stream_context_posix.cc |
@@ -68,8 +68,11 @@ FileStream::Context::~Context() { |
int64 FileStream::Context::GetFileSize() const { |
struct stat info; |
- if (fstat(file_, &info) != 0) |
- return RecordAndMapError(errno, FILE_ERROR_SOURCE_GET_SIZE); |
+ if (fstat(file_, &info) != 0) { |
+ IOResult result = IOResult::FromOSError(errno); |
+ RecordError(result, FILE_ERROR_SOURCE_GET_SIZE); |
+ return result.result; |
+ } |
return static_cast<int64>(info.st_size); |
} |
@@ -96,9 +99,9 @@ int FileStream::Context::ReadAsync(IOBuffer* in_buf, |
int FileStream::Context::ReadSync(char* in_buf, int buf_len) { |
scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(in_buf); |
- int64 result = ReadFileImpl(buf, buf_len); |
- CheckForIOError(&result, FILE_ERROR_SOURCE_READ); |
- return result; |
+ IOResult result = ReadFileImpl(buf, buf_len); |
+ RecordError(result, FILE_ERROR_SOURCE_READ); |
+ return result.result; |
} |
int FileStream::Context::WriteAsync(IOBuffer* in_buf, |
@@ -123,54 +126,59 @@ int FileStream::Context::WriteAsync(IOBuffer* in_buf, |
int FileStream::Context::WriteSync(const char* in_buf, int buf_len) { |
scoped_refptr<IOBuffer> buf = new WrappedIOBuffer(in_buf); |
- int64 result = WriteFileImpl(buf, buf_len); |
- CheckForIOError(&result, FILE_ERROR_SOURCE_WRITE); |
- return result; |
+ IOResult result = WriteFileImpl(buf, buf_len); |
+ RecordError(result, FILE_ERROR_SOURCE_WRITE); |
+ return result.result; |
} |
int FileStream::Context::Truncate(int64 bytes) { |
- int result = ftruncate(file_, bytes); |
- if (result == 0) |
- return bytes; |
+ if (ftruncate(file_, bytes) != 0) { |
+ IOResult result = IOResult::FromOSError(errno); |
+ RecordError(result, FILE_ERROR_SOURCE_SET_EOF); |
+ return result.result; |
+ } |
- return RecordAndMapError(errno, FILE_ERROR_SOURCE_SET_EOF); |
+ return bytes; |
} |
-int64 FileStream::Context::SeekFileImpl(Whence whence, int64 offset) { |
+FileStream::Context::IOResult FileStream::Context::SeekFileImpl(Whence whence, |
+ int64 offset) { |
off_t res = lseek(file_, static_cast<off_t>(offset), |
static_cast<int>(whence)); |
if (res == static_cast<off_t>(-1)) |
- return errno; |
+ return IOResult::FromOSError(errno); |
- return res; |
+ return IOResult(res, 0); |
} |
-int64 FileStream::Context::FlushFileImpl() { |
+FileStream::Context::IOResult FileStream::Context::FlushFileImpl() { |
ssize_t res = HANDLE_EINTR(fsync(file_)); |
if (res == -1) |
- return errno; |
+ return IOResult::FromOSError(errno); |
- return res; |
+ return IOResult(res, 0); |
} |
-int64 FileStream::Context::ReadFileImpl(scoped_refptr<IOBuffer> buf, |
- int buf_len) { |
+FileStream::Context::IOResult FileStream::Context::ReadFileImpl( |
+ scoped_refptr<IOBuffer> buf, |
+ int buf_len) { |
// Loop in the case of getting interrupted by a signal. |
ssize_t res = HANDLE_EINTR(read(file_, buf->data(), |
static_cast<size_t>(buf_len))); |
if (res == -1) |
- return errno; |
+ return IOResult::FromOSError(errno); |
- return res; |
+ return IOResult(res, 0); |
} |
-int64 FileStream::Context::WriteFileImpl(scoped_refptr<IOBuffer> buf, |
- int buf_len) { |
+FileStream::Context::IOResult FileStream::Context::WriteFileImpl( |
+ scoped_refptr<IOBuffer> buf, |
+ int buf_len) { |
ssize_t res = HANDLE_EINTR(write(file_, buf->data(), buf_len)); |
if (res == -1) |
- return errno; |
+ return IOResult::FromOSError(errno); |
- return res; |
+ return IOResult(res, 0); |
} |
} // namespace net |