[MLton-commit] r6935

Vesa Karvonen vesak at mlton.org
Tue Oct 14 09:58:19 PDT 2008


Reduce duplication.

----------------------------------------------------------------------

U   mltonlib/trunk/org/mlton/vesak/rpc-lib/unstable/detail/socket-events.sml

----------------------------------------------------------------------

Modified: mltonlib/trunk/org/mlton/vesak/rpc-lib/unstable/detail/socket-events.sml
===================================================================
--- mltonlib/trunk/org/mlton/vesak/rpc-lib/unstable/detail/socket-events.sml	2008-10-14 15:14:59 UTC (rev 6934)
+++ mltonlib/trunk/org/mlton/vesak/rpc-lib/unstable/detail/socket-events.sml	2008-10-14 16:58:16 UTC (rev 6935)
@@ -59,35 +59,27 @@
     (*fun iodEvt ? = mk id ?*)
    end
 
-   fun recv fullSlice =
-       recur fullSlice (fn lp =>
-          fn slice =>
-             if Word8ArraySlice.isEmpty slice
-             then return fullSlice
-             else sockEvt OS.IO.pollIn >>= (fn socket =>
-                  case Socket.recvArrNB (socket, slice)
-                   of NONE   => error (Fail "impossible")
-                    | SOME 0 => error Closed
-                    | SOME n =>
-                      lp (Word8ArraySlice.subslice (slice, n, NONE))))
-
    local
-      fun mk isEmpty subslice sendNB slice =
+      fun mk isEmpty subslice poll operNB result slice =
           recur slice (fn lp =>
              fn slice =>
                 if isEmpty slice
-                then return ()
-                else sockEvt OS.IO.pollOut >>= (fn socket =>
-                     case sendNB (socket, slice)
+                then return result
+                else sockEvt poll >>= (fn socket =>
+                     case operNB (socket, slice)
                       of NONE   => error (Fail "impossible")
                        | SOME 0 => error Closed
                        | SOME n =>
                          lp (subslice (slice, n, NONE))))
    in
-      val sendArr : Word8ArraySlice.t -> (Unit.t, Socket.active) monad =
-          mk Word8ArraySlice.isEmpty Word8ArraySlice.subslice Socket.sendArrNB
-
-      val sendVec : Word8VectorSlice.t -> (Unit.t, Socket.active) monad =
-          mk Word8VectorSlice.isEmpty Word8VectorSlice.subslice Socket.sendVecNB
+      fun recv slice =
+          mk Word8ArraySlice.isEmpty Word8ArraySlice.subslice
+             OS.IO.pollIn Socket.recvArrNB slice slice
+      fun sendArr slice =
+          mk Word8ArraySlice.isEmpty Word8ArraySlice.subslice
+             OS.IO.pollOut Socket.sendArrNB () slice
+      fun sendVec slice =
+          mk Word8VectorSlice.isEmpty Word8VectorSlice.subslice
+             OS.IO.pollOut Socket.sendVecNB () slice
    end
 end




More information about the MLton-commit mailing list