From ec4d0e426d0e022f6acc1aec831cb2c771354356 Mon Sep 17 00:00:00 2001 From: Michael Lotz Date: Sun, 5 May 2013 18:00:04 +0200 Subject: [PATCH] BMediaNode: Handle port read syscall interrupts by retrying. The syscall might be interrupted, especially in signal heavy applications. In that case we need to retry the read until the timeout runs out. since the timeout is already absolute we don't need to adjust anything. --- src/kits/media/MediaNode.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/kits/media/MediaNode.cpp b/src/kits/media/MediaNode.cpp index beb41e24fb..c4c67fc96a 100644 --- a/src/kits/media/MediaNode.cpp +++ b/src/kits/media/MediaNode.cpp @@ -364,13 +364,23 @@ BMediaNode::WaitForMessage(bigtime_t waitUntil, char data[B_MEDIA_MESSAGE_SIZE]; // about 16 KByte stack used int32 message; - ssize_t size = read_port_etc(ControlPort(), &message, data, sizeof(data), - B_ABSOLUTE_TIMEOUT, waitUntil); - if (size < 0) { + ssize_t size; + while (true) { + size = read_port_etc(ControlPort(), &message, data, + sizeof(data), B_ABSOLUTE_TIMEOUT, waitUntil); + + if (size >= 0) + break; + status_t error = (status_t)size; - if (error != B_TIMED_OUT && error != B_BAD_PORT_ID) + if (error == B_INTERRUPTED) + continue; + + if (error != B_TIMED_OUT && error != B_BAD_PORT_ID) { ERROR("BMediaNode::WaitForMessage: read_port_etc error: %s\n", strerror(error)); + } + return error; }