Import Debian changes 20180207-1
[hcoop/debian/mlton.git] / basis-library / net / generic-sock.sml
CommitLineData
7f918cf1
CE
1(* Copyright (C) 2002-2006, 2008 Henry Cejtin, Matthew Fluet, Suresh
2 * Jagannathan, and Stephen Weeks.
3 *
4 * MLton is released under a BSD-style license.
5 * See the file MLton-LICENSE for details.
6 *)
7
8structure GenericSock : GENERIC_SOCK =
9 struct
10 structure Prim = PrimitiveFFI.Socket.GenericSock
11 structure PE = Posix.Error
12 structure PESC = PE.SysCall
13
14 fun socket' (af, st, p) =
15 (Socket.fromRep o PESC.simpleResult)
16 (fn () => Prim.socket (Net.AddrFamily.toRep af,
17 Socket.SOCKExtra.toRep st,
18 C_Int.fromInt p))
19
20 fun socketPair' (af, st, p) =
21 let
22 val a : C_Sock.t array = Array.array (2, C_Sock.fromInt 0)
23 val get = fn i => Socket.fromRep (Array.sub (a, i))
24 in
25 PESC.syscall
26 (fn () => (Prim.socketPair (Net.AddrFamily.toRep af,
27 Socket.SOCKExtra.toRep st,
28 C_Int.fromInt p,
29 a),
30 fn _ => (get 0, get 1)))
31 end
32
33 fun socket (af, st) = socket' (af, st, 0)
34
35 fun socketPair (af, st) = socketPair' (af, st, 0)
36 end