aboutsummaryrefslogtreecommitdiff
path: root/src/base/platform
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/platform')
-rw-r--r--src/base/platform/unix/PosixSpawnSubProcess.cpp6
-rw-r--r--src/base/platform/unix/UnixFile.cpp22
2 files changed, 21 insertions, 7 deletions
diff --git a/src/base/platform/unix/PosixSpawnSubProcess.cpp b/src/base/platform/unix/PosixSpawnSubProcess.cpp
index 34ae6622..4471c39c 100644
--- a/src/base/platform/unix/PosixSpawnSubProcess.cpp
+++ b/src/base/platform/unix/PosixSpawnSubProcess.cpp
@@ -56,7 +56,7 @@ void PosixSpawnSubProcessImpl::PlatformCreateProcess(
const SubProcessStartInfo& start_info) {
auto check_error = [](int error, String message) {
if (error == 0) return;
- std::unique_ptr<ErrnoException> inner(new ErrnoException({}, error));
+ std::unique_ptr<ErrnoException> inner(new ErrnoException(error));
throw SubProcessFailedToStartException(std::move(message),
std::move(inner));
};
@@ -145,7 +145,7 @@ SubProcessExitResult PosixSpawnSubProcessImpl::PlatformWaitForProcess() {
continue;
}
- std::unique_ptr<ErrnoException> inner(new ErrnoException({}, errno));
+ std::unique_ptr<ErrnoException> inner(new ErrnoException(errno));
throw SubProcessInternalException(
u"Failed to call waitpid on a subprocess.", std::move(inner));
@@ -163,7 +163,7 @@ SubProcessExitResult PosixSpawnSubProcessImpl::PlatformWaitForProcess() {
void PosixSpawnSubProcessImpl::PlatformKillProcess() {
int error = kill(pid_, SIGKILL);
if (error != 0) {
- std::unique_ptr<ErrnoException> inner(new ErrnoException({}, errno));
+ std::unique_ptr<ErrnoException> inner(new ErrnoException(errno));
throw SubProcessInternalException(u"Failed to call kill on a subprocess.",
std::move(inner));
}
diff --git a/src/base/platform/unix/UnixFile.cpp b/src/base/platform/unix/UnixFile.cpp
index a3c5cc6c..763161ce 100644
--- a/src/base/platform/unix/UnixFile.cpp
+++ b/src/base/platform/unix/UnixFile.cpp
@@ -3,8 +3,9 @@
#include "cru/base/log/Logger.h"
#include <fcntl.h>
-#include <sys/fcntl.h>
+#include <sys/types.h>
#include <unistd.h>
+#include <cerrno>
namespace cru::platform::unix {
@@ -68,7 +69,7 @@ int UnixFileDescriptor::GetValue() const {
void UnixFileDescriptor::Close() {
EnsureValid();
if (!this->DoClose()) {
- throw ErrnoException(u"Failed to call close on file descriptor.");
+ throw ErrnoException("Failed to call close on file descriptor.");
}
descriptor_ = -1;
auto_close_ = false;
@@ -82,17 +83,30 @@ bool UnixFileDescriptor::DoClose() {
}
}
+ssize_t UnixFileDescriptor::Read(void* buffer, size_t size) {
+ EnsureValid();
+ auto result = ::read(GetValue(), buffer, size);
+ if (result == -1) {
+ if (errno == EAGAIN || errno == EWOULDBLOCK) {
+ return -1;
+ } else {
+ throw ErrnoException("Failed to read on file descriptor.");
+ }
+ }
+ return result;
+}
+
void UnixFileDescriptor::SetFileDescriptorFlags(int flags) {
EnsureValid();
if (::fcntl(GetValue(), F_SETFL, flags) != -1) {
- throw ErrnoException(u"Failed to set flags on file descriptor.");
+ throw ErrnoException("Failed to set flags on file descriptor.");
}
}
UniDirectionalUnixPipeResult OpenUniDirectionalPipe(UnixPipeFlag flags) {
int fds[2];
if (::pipe(fds) != 0) {
- throw ErrnoException(u"Failed to create unix pipe.");
+ throw ErrnoException("Failed to create unix pipe.");
}
UnixFileDescriptor read(fds[0]), write(fds[1]);