logo       

[ ghc-Bugs-734716 ] ghc-5.05: handle closed by hselect: msg#00012

lang.haskell.glasgow.bugs

Subject: [ ghc-Bugs-734716 ] ghc-5.05: handle closed by hselect

Bugs item #734716, was opened at 2003-05-08 17:52
Message generated for change (Comment added) made by volkersf
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=734716&group_id=8032

Category: hslibs/util
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Nobody/Anonymous (nobody)
Assigned to: Nobody/Anonymous (nobody)
Summary: ghc-5.05: handle closed by hselect

Initial Comment:
The included program, compiled with ghc-5.05 fails with the error
Fail: illegal operation
Action: hGetChar
Handle: {loc=<socket: 4>,type=duplex (read-
write),binary=True,buffering=none}
Reason: handle is closed
File: <socket: 4>

The error occurs on both Mac OS X 10.2.6 and FreeBSD 4.7.

The program works as expected when compiled with ghc-5.04.2.

module Main where
import Select
import Network
import Network.Socket
import IO

portId = (PortNumber portNum)
portNum = 9099

main = do
sock <- listenOn portId
(handle,_,_) <- Network.accept sock
putStrLn ("Read")
c <- (hGetChar handle)
putStrLn ("Got: " ++ show c)

----------------------------------------------------------------------

Comment By: Volker Stolz (volkersf)
Date: 2003-05-13 14:17

Message:
Logged In: YES
user_id=126328

Ah, yes, now I can reprocduce it and it all makes perfect sense: hSelect uses
handleToFd which as a side effect closes the descriptor. This means you cannot
use the (Haskell) handle afterwards. Please use e.g. dup, or, even better, try
to avoid hSelect altogether. Don't forget that usually there's no need for
select()ing first.

handleToFd h = withHandle "handleToFd" h $ \ h_ -> do
-- converting a Handle into an Fd effectively means
-- letting go of the Handle; it is put into a closed
-- state as a result.


----------------------------------------------------------------------

Comment By: Nobody/Anonymous (nobody)
Date: 2003-05-13 12:03

Message:
Logged In: NO

Somehow the only important line (hSelect) got lost in the submission.

module Main where
import Select
import Network
import Network.Socket
import IO

portId = (PortNumber portNum)
portNum = 9099

main = do
sock <- listenOn portId
(handle,_,_) <- Network.accept sock
hSelect [handle] [] [] Nothing
putStrLn ("Read")
c <- (hGetChar handle)
putStrLn ("Got: " ++ show c)

Compiled with ghc --make M1 -o M1 -package network -package util this
fails with

Fail: illegal operation
Action: hGetChar
Handle: {loc=<socket: 4>,type=duplex (read-
write),binary=True,buffering=block (1024)}
Reason: handle is closed
File: <socket: 4>



----------------------------------------------------------------------

Comment By: Volker Stolz (volkersf)
Date: 2003-05-10 17:22

Message:
Logged In: YES
user_id=126328

Do you mean hGetChar instead of hSelect? The Select-module is in the deprecated
hslibs-branch and you do not use it in your program.

It works fine with recent ghc-5.05 from CVS on FreeBSD 4.8-STABLE if I comment
out the 'import Select' and compile with -package network.
Maybe you should update your snapshot and try again.

----------------------------------------------------------------------

You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=108032&aid=734716&group_id=8032


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise