1 (* Copyright (C
) 2002-2006, 2008 Henry Cejtin
, Matthew Fluet
, Suresh
2 * Jagannathan
, and Stephen Weeks
.
4 * MLton is released under a BSD
-style license
.
5 * See the file MLton
-LICENSE for details
.
8 structure GenericSock
: GENERIC_SOCK
=
10 structure Prim
= PrimitiveFFI
.Socket
.GenericSock
11 structure PE
= Posix
.Error
12 structure PESC
= PE
.SysCall
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
,
20 fun socketPair
' (af
, st
, p
) =
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
))
26 (fn () => (Prim
.socketPair (Net
.AddrFamily
.toRep af
,
27 Socket
.SOCKExtra
.toRep st
,
30 fn _
=> (get
0, get
1)))
33 fun socket (af
, st
) = socket
' (af
, st
, 0)
35 fun socketPair (af
, st
) = socketPair
' (af
, st
, 0)