Sockets again

George Russell ger@tzi.de
Tue, 29 Apr 2003 18:09:42 +0200


This is a multi-part message in MIME format.
--------------090304040705090204020905
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

The attached short program (compile with "ghc VServer.hs -o v -package net")
is supposed to set up a server on port 15151, wait for a connection, read
the first character from the connection, and print it out.  Unfortunately
if I test it, by running it, and starting up "telnet [machine] 15151"
somewhere else, and then type some random text, EG "foo[RETURN]", it does
not work.  It looks as if the problem is that VServer.hs issues the
command
    hSetBuffering handle (BlockBuffering (Just 4096))
on the connection, because when I change it to
    hSetBuffering handle NoBuffering
the program works.

However this is not what I want to do!!  Because setting NoBuffering on the
handle is going to mean that when the Server *outputs* something, it will
potentially be done very expensively character by character.  How do I
get block buffering on the Server's output, but not have input to the
server held up?

The same thing seems to happen with client Handles by the way.

--------------090304040705090204020905
Content-Type: text/plain;
 name="VServer.hs"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
 filename="VServer.hs"

LS0gVGVzdCBwcm9ncmFtIGZvciBzZXJ2ZXIgdXNpbmcgR0hDIFNvY2tldCBsaWJyYXJ5Lgpt
b2R1bGUgTWFpbihtYWluKSB3aGVyZQoKaW1wb3J0IElPCmltcG9ydCBOZXR3b3JrCgptYWlu
ID0KICAgZG8KICAgICAgc29ja2V0IDwtIGxpc3Rlbk9uIChQb3J0TnVtYmVyIDE1MTUxKQog
ICAgICAoaGFuZGxlLGhvc3ROYW1lLF8pIDwtIGFjY2VwdCBzb2NrZXQKICAgICAgaFNldEJ1
ZmZlcmluZyBoYW5kbGUgKEJsb2NrQnVmZmVyaW5nIChKdXN0IDQwOTYpKQogICAgICBwdXRT
dHIgKCJBY2NlcHRlZDogIisraG9zdE5hbWUrKyJcbiIpCiAgICAgIGMgPC0gaEdldENoYXIg
aGFuZGxlCiAgICAgIHB1dFN0ckxuIChzaG93IGMpCgo=
--------------090304040705090204020905--