www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 17296] New: EINTR awareness - posix system calls can be

https://issues.dlang.org/show_bug.cgi?id=17296

          Issue ID: 17296
           Summary: EINTR awareness - posix system calls can be
                    interrupted by posix signal
           Product: D
           Version: D2
          Hardware: All
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: phobos
          Assignee: nobody puremagic.com
          Reporter: freeslave93 gmail.com

Phobos does not look to be EINTR-aware. Many posix functions used in phobos can
be potentially interrupted by delivering a signal.
Examples are posix write and read used in std.file.write and std.file.read.

It's easy to make EINTR-aware wrappers for such interruptible functions.

import core.stdc.errno;
import std.traits;

template deintr(alias func, Args...) if (isFunction!func &&
isIntegral!(ReturnType!func))
{
    ReturnType!func deintr(Parameters!func args) {
        ReturnType!func result;
        do {
            result = func(args);
        } while(result == -1 && .errno == EINTR);
        return result;
    }
}

then use it like this:

import core.sys.posix.unistd;
alias dwrite = deintr!(.write);
dwrite(fd, buf.ptr, buf.length);

The question is if it's really needed. What is the current phobos policy on
signals?

--
Apr 03 2017