From 95f71a5f71fcf9979268eb0df6285727ccf5b754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=B6ntgen?= Date: Tue, 21 Aug 2012 15:46:30 +0200 Subject: [PATCH] Noux: add is_nonblocking() method Certain programs tend to set their sockets non-blocking. As previously descriptors in Noux were only blocking we now introduce a method to mark the used Io_channel as non-blocking. --- ports/src/noux/io_channel.h | 5 +++++ ports/src/noux/main.cc | 10 ++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ports/src/noux/io_channel.h b/ports/src/noux/io_channel.h index e473cb7a8e..c947eab449 100644 --- a/ports/src/noux/io_channel.h +++ b/ports/src/noux/io_channel.h @@ -70,6 +70,11 @@ namespace Noux { virtual bool check_unblock(bool rd, bool wr, bool ex) const { return false; } + /** + * Return true if the channel is set to non-blocking mode + */ + virtual bool is_nonblocking() { return false; } + /** * Register blocker for getting waked up on an I/O channel event * diff --git a/ports/src/noux/main.cc b/ports/src/noux/main.cc index a4aa76e333..da0db0dcd5 100644 --- a/ports/src/noux/main.cc +++ b/ports/src/noux/main.cc @@ -140,8 +140,9 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc) Shared_pointer io = _lookup_channel(_sysio->write_in.fd); - if (!io->check_unblock(false, true, false)) - _block_for_io_channel(io); + if (!io->is_nonblocking()) + if (!io->check_unblock(false, true, false)) + _block_for_io_channel(io); /* * 'io->write' is expected to update 'write_out.count' @@ -156,8 +157,9 @@ bool Noux::Child::syscall(Noux::Session::Syscall sc) { Shared_pointer io = _lookup_channel(_sysio->read_in.fd); - while (!io->check_unblock(true, false, false)) - _block_for_io_channel(io); + if (!io->is_nonblocking()) + while (!io->check_unblock(true, false, false)) + _block_for_io_channel(io); io->read(_sysio); return true;