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

Unified Diff: util/file/fd_io.cc

Issue 756653004: Add Logging{Read,Write}FD() and CheckedCloseFD() (Closed) Base URL: https://chromium.googlesource.com/crashpad/crashpad@master
Patch Set: Created 6 years, 1 month 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « util/file/fd_io.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: util/file/fd_io.cc
diff --git a/util/file/fd_io.cc b/util/file/fd_io.cc
index 270539c404440609a6d54f76f939f7ecf203ed3e..cc97400ba34ba3e827a71f9c9dc1955ad18e1e8d 100644
--- a/util/file/fd_io.cc
+++ b/util/file/fd_io.cc
@@ -74,24 +74,42 @@ ssize_t WriteFD(int fd, const void* buffer, size_t size) {
return ReadOrWrite<WriteTraits>(fd, buffer, size);
}
-void CheckedReadFD(int fd, void* buffer, size_t size) {
+bool LoggingReadFD(int fd, void* buffer, size_t size) {
ssize_t expect = base::checked_cast<ssize_t>(size);
ssize_t rv = ReadFD(fd, buffer, size);
if (rv < 0) {
- PCHECK(rv == expect) << "read";
- } else {
- CHECK_EQ(rv, expect) << "read";
+ PLOG(ERROR) << "read";
+ return false;
}
+ if (rv != expect) {
+ LOG(ERROR) << "read: expected " << expect << ", observed " << rv;
+ return false;
+ }
+
+ return true;
}
-void CheckedWriteFD(int fd, const void* buffer, size_t size) {
+bool LoggingWriteFD(int fd, const void* buffer, size_t size) {
ssize_t expect = base::checked_cast<ssize_t>(size);
ssize_t rv = WriteFD(fd, buffer, size);
if (rv < 0) {
- PCHECK(rv == expect) << "write";
- } else {
- CHECK_EQ(rv, expect) << "write";
+ PLOG(ERROR) << "write";
+ return false;
}
+ if (rv != expect) {
+ LOG(ERROR) << "write: expected " << expect << ", observed " << rv;
+ return false;
+ }
+
+ return true;
+}
+
+void CheckedReadFD(int fd, void* buffer, size_t size) {
+ CHECK(LoggingReadFD(fd, buffer, size));
+}
+
+void CheckedWriteFD(int fd, const void* buffer, size_t size) {
+ CHECK(LoggingWriteFD(fd, buffer, size));
}
void CheckedReadFDAtEOF(int fd) {
@@ -110,4 +128,8 @@ bool LoggingCloseFD(int fd) {
return rv == 0;
}
+void CheckedCloseFD(int fd) {
+ CHECK(LoggingCloseFD(fd));
+}
+
} // namespace crashpad
« no previous file with comments | « util/file/fd_io.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698