[MLton] SIGPIPE causes incompatibility with basis library spec

Stephen Weeks MLton@mlton.org
Fri, 19 Nov 2004 17:00:46 -0800


The basis library spec requires functions like Socket.sendVec to raise
an exception if they fail.  However, with MLton (on Linux anyway),
sending to a socket that hasn't yet been connected causes a SIGPIPE
signal, which causes the program to die.  For example, the following
program does not print "exception" as it should.

----------------------------------------------------------------------
val buf = Word8VectorSlice.full (Byte.stringToBytes "test\n")
val sock : Socket.active INetSock.stream_sock = INetSock.TCP.socket ()
val sentLen = Socket.sendVec (sock, buf) handle x => (print "exception\n"; 0)
val _ = print "done\n"
----------------------------------------------------------------------

The default signal handler on Linux for SIGPIPE cause the program to
terminate. 

Should we do the following in our basis library implementation to be
more compliant?

    let
       open MLton.Signal
    in
       setHandler (Posix.Signal.pipe, Handler.ignore)
    end