mirror of
https://github.com/chromium/crashpad.git
synced 2025-03-09 14:06:33 +00:00
Add Logging{Read,Write}FD() and CheckedCloseFD().
R=rsesek@chromium.org Review URL: https://codereview.chromium.org/756653004
This commit is contained in:
parent
e9482a704d
commit
af1c7eb098
@ -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
|
||||
|
@ -30,6 +30,7 @@ namespace crashpad {
|
||||
//! have been read into \a buffer.
|
||||
//!
|
||||
//! \sa WriteFD
|
||||
//! \sa LoggingReadFD
|
||||
//! \sa CheckedReadFD
|
||||
//! \sa CheckedReadFDAtEOF
|
||||
ssize_t ReadFD(int fd, void* buffer, size_t size);
|
||||
@ -45,9 +46,35 @@ ssize_t ReadFD(int fd, void* buffer, size_t size);
|
||||
//! been written to \a fd.
|
||||
//!
|
||||
//! \sa ReadFD
|
||||
//! \sa LoggingWriteFD
|
||||
//! \sa CheckedWriteFD
|
||||
ssize_t WriteFD(int fd, const void* buffer, size_t size);
|
||||
|
||||
//! \brief Wraps ReadFD(), ensuring that exactly \a size bytes are read.
|
||||
//!
|
||||
//! \return `true` on success. If \a size is out of the range of possible
|
||||
//! `read()` return values, if the underlying ReadFD() fails, or if other
|
||||
//! than \a size bytes were read, this function logs a message and returns
|
||||
//! `false`.
|
||||
//!
|
||||
//! \sa LoggingWriteFD
|
||||
//! \sa ReadFD
|
||||
//! \sa CheckedReadFD
|
||||
//! \sa CheckedReadFDAtEOF
|
||||
bool LoggingReadFD(int fd, void* buffer, size_t size);
|
||||
|
||||
//! \brief Wraps WriteFD(), ensuring that exactly \a size bytes are written.
|
||||
//!
|
||||
//! \return `true` on success. If \a size is out of the range of possible
|
||||
//! `write()` return values, if the underlying WriteFD() fails, or if other
|
||||
//! than \a size bytes were written, this function logs a message and
|
||||
//! returns `false`.
|
||||
//!
|
||||
//! \sa LoggingReadFD
|
||||
//! \sa WriteFD
|
||||
//! \sa CheckedWriteFD
|
||||
bool LoggingWriteFD(int fd, const void* buffer, size_t size);
|
||||
|
||||
//! \brief Wraps ReadFD(), ensuring that exactly \a size bytes are read.
|
||||
//!
|
||||
//! If \a size is out of the range of possible `read()` return values, if the
|
||||
@ -56,6 +83,7 @@ ssize_t WriteFD(int fd, const void* buffer, size_t size);
|
||||
//!
|
||||
//! \sa CheckedWriteFD
|
||||
//! \sa ReadFD
|
||||
//! \sa LoggingReadFD
|
||||
//! \sa CheckedReadFDAtEOF
|
||||
void CheckedReadFD(int fd, void* buffer, size_t size);
|
||||
|
||||
@ -67,6 +95,7 @@ void CheckedReadFD(int fd, void* buffer, size_t size);
|
||||
//!
|
||||
//! \sa CheckedReadFD
|
||||
//! \sa WriteFD
|
||||
//! \sa LoggingWriteFD
|
||||
void CheckedWriteFD(int fd, const void* buffer, size_t size);
|
||||
|
||||
//! \brief Wraps ReadFD(), ensuring that it indicates end-of-file.
|
||||
@ -85,6 +114,12 @@ void CheckedReadFDAtEOF(int fd);
|
||||
//! `false` is returned.
|
||||
bool LoggingCloseFD(int fd);
|
||||
|
||||
//! \brief Wraps `close()`, ensuring that it succeeds.
|
||||
//!
|
||||
//! If `close()` fails, this function causes execution to terminate without
|
||||
//! returning.
|
||||
void CheckedCloseFD(int fd);
|
||||
|
||||
} // namespace crashpad
|
||||
|
||||
#endif // CRASHPAD_UTIL_FILE_FD_IO_H_
|
||||
|
Loading…
x
Reference in New Issue
Block a user