Wolfgang Jeltsch pushed to branch wip/jeltsch/obtaining-os-handles at Glasgow Haskell Compiler / GHC

Commits:

1 changed file:

Changes:

  • libraries/base/src/GHC/IO/Handle.hs
    ... ... @@ -198,38 +198,45 @@ handleStateVarWritingBiased (DuplexHandle _ _ writingVar) = writingVar
    198 198
     {-|
    
    199 199
         Yields the result of another operation if that operation succeeded, and
    
    200 200
         otherwise throws an exception that signals that the other operation failed
    
    201
    -    because a certain I/O subsystem is not in use.
    
    201
    +    because some Haskell handle does not use an operating-system handle of a
    
    202
    +    required type.
    
    202 203
     -}
    
    203
    -requiringSubsystem :: String
    
    204
    -                      -- ^ The name of the required subsystem
    
    205
    -                   -> Maybe a
    
    206
    -                      -- ^ The result of the other operation if it succeeded
    
    207
    -                   -> IO a
    
    208
    -requiringSubsystem subsystemName
    
    209
    -    = maybe (ioException subsystemRequired) return
    
    204
    +requiringOSHandleOfType :: String
    
    205
    +                           -- ^ The name of the operating-system handle type
    
    206
    +                        -> Maybe a
    
    207
    +                           {-^
    
    208
    +                               The result of the other operation if it succeeded
    
    209
    +                           -}
    
    210
    +                        -> IO a
    
    211
    +requiringOSHandleOfType osHandleTypeName
    
    212
    +    = maybe (ioException osHandleOfTypeRequired) return
    
    210 213
         where
    
    211 214
     
    
    212
    -    subsystemRequired :: IOException
    
    213
    -    subsystemRequired = IOError Nothing
    
    214
    -                                IllegalOperation
    
    215
    -                                ""
    
    216
    -                                (subsystemName ++ " I/O subsystem required")
    
    217
    -                                Nothing
    
    218
    -                                Nothing
    
    215
    +    osHandleOfTypeRequired :: IOException
    
    216
    +    osHandleOfTypeRequired
    
    217
    +        = IOError Nothing
    
    218
    +                  IllegalOperation
    
    219
    +                  ""
    
    220
    +                  ("handle does not use " ++ osHandleTypeName ++ "s")
    
    221
    +                  Nothing
    
    222
    +                  Nothing
    
    219 223
     
    
    220 224
     {-|
    
    221
    -    Obtains the POSIX file descriptor of a device if the POSIX I/O subsystem is
    
    222
    -    in use, and throws an exception otherwise.
    
    225
    +    Obtains the POSIX file descriptor of a device if the device contains one,
    
    226
    +    and throws an exception otherwise.
    
    223 227
     -}
    
    224 228
     getFileDescriptor :: Typeable d => d -> IO CInt
    
    225
    -getFileDescriptor = requiringSubsystem "POSIX" . fmap fdFD . cast
    
    229
    +getFileDescriptor = requiringOSHandleOfType "POSIX file descriptor" .
    
    230
    +                    fmap fdFD . cast
    
    226 231
     
    
    227 232
     {-|
    
    228
    -    Obtains the Windows handle of a device if the Windows I/O subsystem is in
    
    229
    -    use, and throws an exception otherwise.
    
    233
    +    Obtains the Windows handle of a device if the device contains one, and
    
    234
    +    throws an exception otherwise.
    
    230 235
     -}
    
    231 236
     getWindowsHandle :: Typeable d => d -> IO (Ptr ())
    
    232
    -getWindowsHandle = requiringSubsystem "native" . toMaybeWindowsHandle where
    
    237
    +getWindowsHandle = requiringOSHandleOfType "Windows handle" .
    
    238
    +                   toMaybeWindowsHandle
    
    239
    +    where
    
    233 240
     
    
    234 241
         toMaybeWindowsHandle :: Typeable d => d -> Maybe (Ptr ())
    
    235 242
     #if defined(mingw32_HOST_OS)
    
    ... ... @@ -257,7 +264,7 @@ getWindowsHandle = requiringSubsystem "native" . toMaybeWindowsHandle where
    257 264
         further operations on the handle are blocked to a degree that interference
    
    258 265
         with this action is prevented.
    
    259 266
     
    
    260
    -    If the I/O subsystem in use is not the POSIX one, an exception is thrown.
    
    267
    +    If the handle does not use POSIX file descriptors, an exception is thrown.
    
    261 268
     
    
    262 269
         See [below](#with-ref-caveats) for caveats regarding this operation.
    
    263 270
     -}
    
    ... ... @@ -275,7 +282,7 @@ withFileDescriptorReadingBiased = withOSHandle "withFileDescriptorReadingBiased"
    275 282
         further operations on the handle are blocked to a degree that interference
    
    276 283
         with this action is prevented.
    
    277 284
     
    
    278
    -    If the I/O subsystem in use is not the POSIX one, an exception is thrown.
    
    285
    +    If the handle does not use POSIX file descriptors, an exception is thrown.
    
    279 286
     
    
    280 287
         See [below](#with-ref-caveats) for caveats regarding this operation.
    
    281 288
     -}
    
    ... ... @@ -293,7 +300,7 @@ withFileDescriptorWritingBiased = withOSHandle "withFileDescriptorWritingBiased"
    293 300
         operations on the Haskell handle are blocked to a degree that interference
    
    294 301
         with this action is prevented.
    
    295 302
     
    
    296
    -    If the I/O subsystem in use is not the Windows one, an exception is thrown.
    
    303
    +    If the Haskell handle does not use Windows handles, an exception is thrown.
    
    297 304
     
    
    298 305
         See [below](#with-ref-caveats) for caveats regarding this operation.
    
    299 306
     -}
    
    ... ... @@ -311,7 +318,7 @@ withWindowsHandleReadingBiased = withOSHandle "withWindowsHandleReadingBiased"
    311 318
         operations on the Haskell handle are blocked to a degree that interference
    
    312 319
         with this action is prevented.
    
    313 320
     
    
    314
    -    If the I/O subsystem in use is not the Windows one, an exception is thrown.
    
    321
    +    If the Haskell handle does not use Windows handles, an exception is thrown.
    
    315 322
     
    
    316 323
         See [below](#with-ref-caveats) for caveats regarding this operation.
    
    317 324
     -}