Git Product home page Git Product logo

Comments (11)

gregorycollins avatar gregorycollins commented on June 12, 2024

The design is kind of gross there, I would have newtyped over the int and provided a Monoid instance. That said we're probably stuck with it now. Please send a pull request if you need the other flags (it will require a major version bump).

from unix.

nh2 avatar nh2 commented on June 12, 2024

I cannot say much about the other flags, but O_CLOEXEC is important because it is the only way you are guaranteed in the general case not to leak FDs in a multi-threaded program that forks.

from unix.

nh2 avatar nh2 commented on June 12, 2024

@gregorycollins If I want to add some things to this, how would I deal with cross-platform compatibility and what platforms to I have to take care of?

Relatedly, this is the intersection of supported O_* flags for Linux and BSD:

O_APPEND
O_CLOEXEC
O_CREAT
O_DIRECT
O_DIRECTORY
O_EXCL
O_NOCTTY
O_NOFOLLOW
O_NONBLOCK
O_SYNC
O_TRUNC

And of those, the following are not implemented in the unix package:

O_CLOEXEC
O_CREAT
O_DIRECT
O_DIRECTORY
O_NOFOLLOW
O_SYNC

from unix.

nh2 avatar nh2 commented on June 12, 2024

Also, O_CLOEXEC doesn't seem to be supported on OSX < 10.7, see this Go thread.

from unix.

cartazio avatar cartazio commented on June 12, 2024

is there any reason why the alternative monoidal interface couldn't be added?

from unix.

hvr avatar hvr commented on June 12, 2024

@cartazio how exactly would you suggest doing that w/o breaking backward compatibility?

from unix.

cartazio avatar cartazio commented on June 12, 2024

add a new module? :)
something like System.Posix.IO.NG or something?

from unix.

gregorycollins avatar gregorycollins commented on June 12, 2024

...or just by adding a new open function with a new name.

I think we should deprecate the old style --- as noted on this bug, it doesn't cover all of the available flags, and extending the type or providing platform-specific flags is problematic because you will break pattern-matching if callers do that for some reason. The current API is also wasteful -- six heap allocations and all of those bools have to be walked by openFd. Newtype-over-int will probably get unboxed into a register.

from unix.

cartazio avatar cartazio commented on June 12, 2024

thats a better idea :)

from unix.

hasufell avatar hasufell commented on June 12, 2024

@gregorycollins If I want to add some things to this, how would I deal with cross-platform compatibility and what platforms to I have to take care of?

Relatedly, this is the intersection of supported O_* flags for Linux and BSD:

O_APPEND
O_CLOEXEC
O_CREAT
O_DIRECT
O_DIRECTORY
O_EXCL
O_NOCTTY
O_NOFOLLOW
O_NONBLOCK
O_SYNC
O_TRUNC

And of those, the following are not implemented in the unix package:

O_CLOEXEC
O_CREAT
O_DIRECT
O_DIRECTORY
O_NOFOLLOW
O_SYNC

unix-2.8.0.0 will have:

data OpenFileFlags =
 OpenFileFlags {
    append    :: Bool,           -- ^ O_APPEND
    exclusive :: Bool,           -- ^ O_EXCL, result is undefined if O_CREAT is False
                                 --
                                 -- __NOTE__: Result is undefined if 'creat' is 'Nothing'.
    noctty    :: Bool,           -- ^ O_NOCTTY
    nonBlock  :: Bool,           -- ^ O_NONBLOCK
    trunc     :: Bool,           -- ^ O_TRUNC
    nofollow  :: Bool,           -- ^ O_NOFOLLOW
                                 --
                                 -- @since 2.8.0.0
    creat     :: Maybe FileMode, -- ^ O_CREAT
                                 --
                                 -- @since 2.8.0.0
    cloexec   :: Bool,           -- ^ O_CLOEXEC
                                 --
                                 -- @since 2.8.0.0
    directory :: Bool,           -- ^ O_DIRECTORY
                                 --
                                 -- @since 2.8.0.0
    sync      :: Bool            -- ^ O_SYNC
                                 --
                                 -- @since 2.8.0.0
 }

O_DIRECT doesn't seem to be part of POSIX: https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/

So I think this can be closed.

from unix.

nh2 avatar nh2 commented on June 12, 2024

@hasufell Thank you, that is very useful.

I am very looking forward to the unix-2.8.0.0 release; with #59 in there we will finally have a chance to tack The CLOEXEC problem across the Haskell ecosystem.

Also thanks for your other recent unix efforts!

from unix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.