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

SCM Repository

[smlnj] Annotation of /sml/branches/primop-branch/src/system/Basis/Implementation/Sockets/unix-details.sml
ViewVC logotype

Annotation of /sml/branches/primop-branch/src/system/Basis/Implementation/Sockets/unix-details.sml

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1470 - (view) (download)

1 : mblume 1389 (* unix-details.sml
2 :     *
3 :     * Check for would-block error condition on Unix sockets.
4 :     *
5 :     * Copyright (c) 2003 by The Fellowship of SML/NJ
6 :     *
7 :     * Author: Matthias Blume (blume@tti-c.org)
8 :     *)
9 :     structure OpsysDetails : sig
10 :     val mkIODesc : int -> PreOS.IO.iodesc
11 :     val wrapNB_o : ('a -> 'b) -> ('a -> 'b option)
12 :     val wrapNB_b : ('a -> unit) -> ('a -> bool)
13 :     end = struct
14 :    
15 :     val mkIODesc = PreOS.IO.IODesc
16 :    
17 :     (* The following is essentially lifted from the CML implementation's
18 :     * handling of non-blocking socket I/O. I am not sure whether
19 :     * conflating EINPROGRESS, EAGAIN, and EWOULDBLOCK is exactly
20 :     * the right thing, though... *)
21 :     val blockErrors =
22 :     case Posix.Error.syserror "wouldblock" of
23 :     NONE => [Posix.Error.again, Posix.Error.inprogress]
24 :     | SOME e => [e, Posix.Error.again, Posix.Error.inprogress]
25 :    
26 :     fun blockErr (OSImp.SysErr(_, SOME err)) =
27 :     List.exists (fn err' => err = err') blockErrors
28 :     | blockErr _ = false
29 :    
30 :     fun wrapNB_o f x = SOME (f x)
31 :     handle ex => if blockErr ex then NONE else raise ex
32 :    
33 :     fun wrapNB_b f x = (f x; true)
34 :     handle ex => if blockErr ex then false else raise ex
35 :     end

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0