socket closing --> OS.SysErr

David Eger <eger-oTNwCEtKUwI/[email protected]>
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
There is a semantic ambiguity that the Standard ML Basis
Definition that needs clearing up--According to the documentation at
http://www.standardml.org/Basis/socket.html, recvVec and recvVec' are
defined as follows:

> recvVec (sock, n)
> recvVec'(sock, n, {peek,oob})
>    These functions receive up to n bytes from the active stream socket
>    sock. The size of the resulting vector is the number of bytes that 
>    were successfully received, which may be less than n. If the 
>    connection has been closed at the other end (or if n is 0), then 
>    the empty vector will be returned.
>
>    In the second version, if peek is true, the data is received but 
>    not discarded from the connection. If oob is true, the data is 
>    received out-of-band, that is, before any other incoming data that 
>    may have been buffered.
>
>    These functions raise SysErr if the socket sock has been closed and 
>    they raise Size if n < 0 or n > Word8Vector.maxLen.

Now, when a socket closes, does recvVec return 0 bytes, or raise SysErr?

The current implementation returns 0 bytes.  If this is the intent, please
change the documentation.  If however, OS.SysErr should be raised, please 
apply the patch below.  Also, John, you can then change this section of 
eXene ;-) 

smlnj/src/eXene/lib/protocol/xio.sml:
>                  | read (n, vl) = let
>                      val v = Socket.recvVec(sock, n)
>                      in
>                        case (W8V.length v)
>(**** NOTE: we need a more graceful way to signal that the socket has closed!! ***)
>                         of 0 => raise Fail "Socket closed"
>                          | len => read (n - len, v::vl)
>                        (* end case *)


-David


--- smlnj/src/system/Basis/Implementation/Sockets/socket.sml.old	2004-11-06 15:33:32.182113600 -0500
+++ smlnj/src/system/Basis/Implementation/Sockets/socket.sml	2004-11-06 17:39:50.005109400 -0500
@@ -357,7 +357,10 @@
       fun recvV _ (_, 0, _, _) = W8V.fromList[]
 	| recvV getfd (sock, nbytes, peek, oob) =
 	    if nbytes < 0 then raise Size
-	    else recvV' (getfd sock, nbytes, peek, oob)
+	    else let val data = recvV' (getfd sock, nbytes, peek, oob)
+		 in if W8V.length(data) = 0 then raise OS.SysErr("Socket Closed", NONE)
+		    else data
+		 end
       val recvA : (int * w8array * int * int * bool * bool) -> int
 	    = sockFn "recvBuf"
     in


-------------------------------------------------------
This SF.Net email is sponsored by:
Sybase ASE Linux Express Edition - download now for FREE
LinuxWorld Reader's Choice Award Winner for best database on Linux.
http://ads.osdn.com/?ad_id=5588&alloc_id=12065&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.