Hi there,
socket Handles are unbuffered by the default, so
if you change the buffering by inserting
hSetBuffering handle
(BlockBuffered Nothing) -- or some such
after each call to socketToHandle / Socket.accept, you
should get a boost in throughput.
readSocket/writeSocket doesn't quite work with WinSock;
the files net/cbits/{read,write}Descriptor.c needs to
perform similar CPP tricks that std/cbits/{read,write}File.c
does, i.e., WinSock requires you to use send() recv()
instead of read() write().
You shouldn't have to use readSocket/writeSocket here though.
--sigbjorn
-Original Message-
From: Martijn [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, October 31, 2000 10:09
To: Sigbjorn Finne
Subject: RE: Socket.hs problem under Windows 2000
Hi Sigbjorn,
I'm sorry to bother you again, but in my eyes you're the
socket Guru, so if
anyone can help me, it must be you :-)
I'm still struggling with my sockets here (I find myself calling them
suck-its nowadays). I managed to create a socket connection
between a C and
a Haskell program, and all communication works, but is a lot
slower than I
expected. Socket communication in compiled GHC programs is
even slower than
in interpreted Hugs Programs (using a simple Lambada socket
library I made.)
I also tried to use readSocket from SocketPrim instead
hPutStr etc. but I
can't get this to work at all. writeSocket always gives an
"internal error
(EBADF)(error code: 8)" and read socket never gets any data,
even when the
other side uses handles and works.
The following two programs show the problem. The way they are
now, they
work but are slow, but if I use the now commented
read/writeSocket calls
instead, nothing works:
Begin: Server.hs ---
module Main where
import IO
import qualified Socket
import SocketPrim
import BSD
main = withSocketsDo $
do { hSetBuffering stdout NoBuffering
; putStrLn "Server: start listening"
; serversocket - Socket.listenOn (Socket.PortNumber )
; putStrLn "Start accepting"
; ~(sock', (SockAddrInet port haddr)) - SocketPrim.accept
serversocket -- taken from GHC lib Socket.lhs
; (HostEntry peername _ _ _) -
getHostByAddr AF_INET haddr
; handle - socketToHandle sock'
ReadWriteMode
; putStrLn ("Got connection from "++peername)
; let sendstr = (replicate 4000 'x')++['\n']
; putStrLn ("Start sending "++ show (length sendstr))
; loop
(do { putStr "."
; hPutStr handle sendstr -- works,
but is slow
-- ; writeSocket sock' sendstr -- doesn't work
; return ()
})
}
loop :: IO () - IO ()
loop act = loop' where loop' = do { act; loop' }
--
and
Begin: Client.hs
module Main where
import IO
import qualified Socket
import SocketPrim
import BSD
main = withSocketsDo $
do { hSetBuffering stdout NoBuffering
; putStrLn "Client: start connecting"
; proto - getProtocolNumber "tcp" -- taken from
GHC lib Socket.lhs
; sock - socket AF_INET Stream proto
; he- getHostByName "localhost"
; connect sock (SockAddrInet (hostAddress he))
; handle - socketToHandle sock ReadWriteMode
; putStrLn "Connected"
; loop
(do {
str - hGetLine handle-- works, but is slow
-- str - readSocketAll sock -- doesn't work
; if length str 0 then putStr (show (length
str)) else return ()
})
}
loop :: IO () - IO ()
loop act = loop' where loop' = do { act; loop' }
--
Does any of this sound familiar to you?
Thanks.
Doeidoei,
Martijn
___
Glasgow-haskell-bugs mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs