fun with sockets (ghc-5.04.1)

2003-03-11 Thread Peter Thiemann
Hi,
I'm running into a problem using server code (running on a UNIX domain
socket) that I basically snatched from Simon Marlow's web server:

++
mainLoop sock defUser getMs =
  do putStrLn "Accepting connections..."
 installHandler sigPIPE Ignore Nothing
 loop (0::Int)
  where
loop n =
  do (connection, peerAddress) <- accept sock
 h <- socketToHandle connection ReadWriteMode
 forkIO ( (talk n getMs defUser h `finally` goodBye n h)
  `Exception.catch` 
  (\e -> putStrLn ("Exception: " ++ show e))
)
 loop (n+1)

goodBye n h =
  do putStrLn (show n ++ ": finished")
 hClose h
++

After processing a random number of connections, the server dies with 

Fail: invalid argument
Action: accept
Reason: Invalid argument

after finishing the last connection. For the record, here is the code
that is executed for each connection:

++
talk n getMs user h =
  do hSetBuffering h LineBuffering
 putStrLn (show n ++ ": ")
 str <- hGetLine h
 lstr <- hGetLine h
 putStrLn ("...: " ++ lstr) -- last output before core dump
 let msglength = read (takeWhile isDigit (drop 1 lstr))
 rawmsg <- hGetContents h
 putStrLn ("Got " ++ show (length msg) ++ " characters")
++

The machine is
Linux kailua 2.4.18-4GB #1 Wed Mar 27 13:57:05 UTC 2002 i686 unknown
The problem seems to go away if I switch to INET sockets, so I'm also including
my initialization code:

++
  withSocketsDo $ do 
sock <- socket AF_UNIX Stream 0
bindSocket sock (SockAddrUnix path)
listen sock maxListenQueue
getMs <- initializeAll
mainLoop sock defUser getMs
++

-Peter
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


RE: fun with sockets (ghc-5.04.1)

2003-03-19 Thread Simon Marlow
Peter,

[...]
> After processing a random number of connections, the server dies with 
> 
> Fail: invalid argument
> Action: accept
> Reason: Invalid argument
[...]

I don't know what's wrong, I'm afraid.  Any chance you could supply us
with a working example that demonstrates the bug?

Cheers,
Simon
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: fun with sockets (ghc-5.04.1)

2003-03-19 Thread Volker Stolz
In local.glasgow-haskell-users, you wrote:
>> After processing a random number of connections, the server dies with 
>> 
>> Fail: invalid argument
>> Action: accept
>> Reason: Invalid argument
> [...]
> 
> I don't know what's wrong, I'm afraid.  Any chance you could supply us
> with a working example that demonstrates the bug?

I was on this for some time and even received an strace from Peter
 -- which DIDN'T show EINVAL at all on any accept!
He keeps seeing 'Evacuated object entered' messages on other runs,
so he might be experiencing a more severe problem. Reproducing this
with a recent ghc would be better, I guess...

BTW: There's a tracing primer at
http://www-i2.informatik.rwth-aachen.de/~stolz/Haskell/networking.txt
which explains some of the things you might find strange in traces
(ioctl TCGETS anyone?). Not quite finished and open for suggestions...

Volker

-- 
http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME
rage against the finite state machine 
___
Glasgow-haskell-users mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users