Skip to content
  • Ben Gamari's avatar
    base: Fix hWaitForInput with timeout on POSIX · e5732d2a
    Ben Gamari authored and Ben Gamari's avatar Ben Gamari committed
    This was previously broken (#13252) by
    f46369b8, which ported the fdReady
    function from `select` to `poll` and in so doing dropping support for
    timeouts. Unfortunately, while `select` tells us the amount of time not
    slept (on Linux anyways; it turns out this is implementation dependent),
    `poll` does not give us this luxury. Consequently, we manually need to
    track time slept in this case.
    
    Unfortunately, portably measuring time is hard. Ideally we would use
    `clock_gettime` with the monotonic clock here, but sadly this isn't
    supported on most versions of Darwin. Consequently, we instead use
    `gettimeofday`, running the risk of system time changes messing us up.
    
    Test Plan: Validate
    
    Reviewers: simonmar, austin, hvr
    
    Reviewed By: simonmar
    
    Subscribers: rwbarton, thomie
    
    GHC Trac Issues: #13252
    
    Differential Revision: https://phabricator.haskell.org/D3473
    e5732d2a