Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] View of /sml/trunk/src/system/Basis/Implementation/Sockets/unix-details.sml
ViewVC logotype

View of /sml/trunk/src/system/Basis/Implementation/Sockets/unix-details.sml

Parent Directory Parent Directory | Revision Log Revision Log

Revision 1389 - (download) (annotate)
Wed Sep 24 20:09:40 2003 UTC (16 years, 6 months ago) by mblume
File size: 1140 byte(s)
sync of socket implementation with Basis spec;
minor updates to Real64 code
(* unix-details.sml
 *   Check for would-block error condition on Unix sockets.
 * Copyright (c) 2003 by The Fellowship of SML/NJ
 * Author: Matthias Blume (blume@tti-c.org)
structure OpsysDetails : sig
    val mkIODesc : int -> PreOS.IO.iodesc
    val wrapNB_o : ('a -> 'b) -> ('a -> 'b option)
    val wrapNB_b : ('a -> unit) -> ('a -> bool)
end = struct

    val mkIODesc = PreOS.IO.IODesc

    (* The following is essentially lifted from the CML implementation's
     * handling of non-blocking socket I/O.  I am not sure whether
     * conflating EINPROGRESS, EAGAIN, and EWOULDBLOCK is exactly
     * the right thing, though... *)
    val blockErrors =
	case Posix.Error.syserror "wouldblock" of
	    NONE => [Posix.Error.again, Posix.Error.inprogress]
	  | SOME e => [e, Posix.Error.again, Posix.Error.inprogress]

    fun blockErr (OSImp.SysErr(_, SOME err)) =
	List.exists (fn err' => err = err') blockErrors
      | blockErr _ = false

    fun wrapNB_o f x = SOME (f x)
	handle ex => if blockErr ex then NONE else raise ex

    fun wrapNB_b f x = (f x; true)
	handle ex => if blockErr ex then false else raise ex

ViewVC Help
Powered by ViewVC 1.0.0