
At line 206 of this file there is a withFd function that might suit your needs,
https://patch-tag.com/r/mae/sendfile/snapshot/current/content/pretty/src/Net...
-- The Fd should not be used after the action returns because the
-- Handler may be garbage collected and than will cause the finalizer
-- to close the fd.
withFd :: Handle -> (Fd -> IO a) -> IO a
#ifdef __GLASGOW_HASKELL__
#if __GLASGOW_HASKELL__ >= 611
withFd h f = withHandle_ "withFd" h $ \ Handle__{..} -> do
case cast haDevice of
Nothing -> ioError (ioeSetErrorString (mkIOError IllegalOperation
"withFd" (Just h) Nothing)
"handle is not a file descriptor")
Just fd -> f (Fd (fromIntegral (FD.fdFD fd)))
#else
withFd h f =
withHandle_ "withFd" h $ \ h_ ->
f (Fd (fromIntegral (haFD h_)))
#endif
#endif
It uses GHC internals stuff, so it could easily break someday.
On Thu, Jan 27, 2011 at 2:00 PM, Volker Wysk
Hello
I need to get the file descriptor, which is encapsulated inside a handle. handleToFd gets it, but the fd is closed. Is it possible to extract the fd from the handle, without modifying the handle?
Greetings, Volker
_______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users