
Now I'm wondering about ways to cut that down: 1. How can I avoid the allocations inside of openFile? 2. Would it help to call f6 in different threads? That is, does a thread yield when it calls an IO function?
openFile is quite expensive because it normally allocates a buffer, which I suspect accounts for most of the allocation you're seeing. It also sets up a finalizer, allocates the Handle, and does a couple of extra system calls. If the openFile isn't on the critical path, then it can help to do it in another thread, but only if the openFile is blocking (not usually the case if you're opening a normal file). You might consider bypassing the Handle interface and going to the bare metal using the Posix library, which will cut down on the overhead in openFile. The best solution is to avoid the open altogether if possible (eg. with caching), but I don't know about your particular application so this might not be a possibility. Cheers, Simon

Hi, I have a program that uses INET sockets and I wanted to change it to use Unix domain sockets. Here is the relevant code: import Network withSocketsDo $ do sock <- listenOn portID (h, hostname, portnumber) <- accept sock while this code works fine with portID = PortNumber (toEnum 9099) I get an error message when running it with portID = UnixSocket "/home/thiemann/.socket" Fail: user error Reason: accept: can't peform accept on socket in status Bound The file is still created with the right permissions: srw------- 1 thiemann users 0 Jan 14 22:48 /home/thiemann/.socket= Since there is not much that I can do in the Network module, it looks like there is a problem in its implementation? BTW, I'm running ghc-5.04.1 on this machine: [kailua] 108 > uname -a Linux kailua 2.4.18-4GB #1 Wed Mar 27 13:57:05 UTC 2002 i686 unknown It would be very convenient if I could use Unix sockets as they save me from implementing an authentication protocol. -Peter

In local.glasgow-haskell-users, you wrote:
I have a program that uses INET sockets and I wanted to change it to use Unix domain sockets. Here is the relevant code:
sock <- listenOn portID (h, hostname, portnumber) <- accept sock
I get an error message when running it with portID = UnixSocket "/home/thiemann/.socket"
Somebody decided that Unix sockets are Datagrams in Network.hs, which is wrong (thanks for finding this bug), they're Stream sockets. You might want to avoid Network for the time being and use Network.Sockets, because fixing this will trigger another bug: Network.accept is currently only designed for Inet-sockets, its type makes that clear without even resorting to The Source: you cannot get a host & port from a Unix socket, so while Socket.accept will work, Network.accept won't and fail on getHostBy*. The getHostBy* would have to be moved away from accept into listenOn first (Thanks, #2). I'd vote for removing Unix sockets from Network.hs to avoid this. (Sockets are already quite well abstracted on Un*x, so that's what you get for trying to put another layer on top of it #) Volker -- http://www-i2.informatik.rwth-aachen.de/stolz/ *** PGP *** S/MIME

Volker, I only saw your answer today since it was filed in my Haskell-mailing-list folder. Indeed, I've moved on to import Network.Socket and then duplicated part of my code. One thing that I found annoying was that the Protocol argument of Network.Socket.socket is not well specified. The type Protocol is abstract, but is a member of class Read. However, the Read syntax is nowhere specified. So I tried do sock <- socket AF_UNIX Stream (read "0") which works, but I'm sure that more informative strings work, too. -Peter

Am 06. Feb 2003 um 21:53 CET schrieb Peter Thiemann:
and then duplicated part of my code. One thing that I found annoying was that the Protocol argument of Network.Socket.socket is not well specified. The type Protocol is abstract, but is a member of class Read. However, the Read syntax is nowhere specified. So I tried
do sock <- socket AF_UNIX Stream (read "0")
which works, but I'm sure that more informative strings work, too.
Hm, ghc-5.04.2 compiles sock <- socket AF_UNIX Stream 0 just fine. Are you maybe looking for Network.BSD.getProtocolBy*? [ProtocolNumber is just a typdef for CInt] -- Volker Stolz * http://www-i2.informatik.rwth-aachen.de/stolz/ * PGP * S/MIME http://news.bbc.co.uk: `Israeli forces [...], declaring curfews that confine more than 700,000 people to their homes.'
participants (4)
-
Peter Thiemann
-
Simon Marlow
-
Volker Stolz
-
Volker Stolz