Wrapper around ``pipe2(2)``

    :param flags:
        Optional flags to set. This should almost always include O_CLOEXEC so
        that the resulting code is not racy (see the discussion about O_CLOEXEC
        to understand why this flag is essential). It can also include
        O_NONBLOCK or O_DIRECT, depending on the desired behavior.
    :returns:
        A pair of descriptors (read_end, write_end)

def pipe2(flags=0):
    """
    Wrapper around ``pipe2(2)``

    :param flags:
        Optional flags to set. This should almost always include O_CLOEXEC so
        that the resulting code is not racy (see the discussion about O_CLOEXEC
        to understand why this flag is essential). It can also include
        O_NONBLOCK or O_DIRECT, depending on the desired behavior.
    :returns:
        A pair of descriptors (read_end, write_end)
    """
    pair = (c_int * 2)()
    _pipe2(byref(pair), flags)
    return pair[0], pair[1]