Call failed handler for io error on non-linux platform.
@@ -26,6 +26,13 @@ ssize_t
FastOS_UNIX_File::Read(void *buffer, size_t len)
{
ssize_t nRead = read(_filedes, buffer, len);
+ if (nRead < 0 && _failedHandler != nullptr) {
+ int error = errno;
+ int64_t readOffset = GetPosition();
+ const char *fileName = GetFileName();
+ _failedHandler("read", fileName, error, readOffset, len, nRead);
+ errno = error;
+ }
return nRead;
}
@@ -34,6 +41,13 @@ ssize_t
FastOS_UNIX_File::Write2(const void *buffer, size_t len)
{
ssize_t writeRes = write(_filedes, buffer, len);
+ if (writeRes < 0 && _failedHandler != nullptr) {
+ int error = errno;
+ int64_t writeOffset = GetPosition();
+ const char *fileName = GetFileName();
+ _failedHandler("write", fileName, error, writeOffset, len, writeRes);
+ errno = error;
+ }
return writeRes;
}
@@ -58,6 +72,12 @@ void FastOS_UNIX_File::ReadBuf(void *buffer, size_t length,
ssize_t readResult;
readResult = pread(_filedes, buffer, length, readOffset);
+ if (readResult < 0 && _failedHandler != nullptr) {
+ int error = errno;
+ const char *fileName = GetFileName();
+ _failedHandler("read", fileName, error, readOffset, length, readResult);
+ errno = error;
+ }
if (static_cast<size_t>(readResult) != length) {
std::string errorString = readResult != -1 ?
std::string("short read") :
