File: net.sml

package info (click to toggle)
mlton 20210117%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 58,464 kB
  • sloc: ansic: 27,682; sh: 4,455; asm: 3,569; lisp: 2,879; makefile: 2,347; perl: 1,169; python: 191; pascal: 68; javascript: 7
file content (76 lines) | stat: -rw-r--r-- 2,425 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(* Copyright (C) 2012 Matthew Fluet.
 * Copyright (C) 2002-2006, 2008 Henry Cejtin, Matthew Fluet, Suresh
 *    Jagannathan, and Stephen Weeks.
 *
 * MLton is released under a HPND-style license.
 * See the file MLton-LICENSE for details.
 *)

structure Net : NET =
   struct
      structure AddrFamily = MkAbsRepEq(type rep = C_Int.t)
      structure Sock = MkAbsRep(type rep = C_Sock.t)
      structure SockType = MkAbsRepEq(type rep = C_Int.t)

      structure Prim = PrimitiveFFI.Net

      structure Word32 =
         struct
            val hton = Prim.htonl
            val ntoh = Prim.ntohl
         end
      structure Word16 =
         struct
            val hton = Prim.htons
            val ntoh = Prim.ntohs
         end

      structure Int32 =
         struct
            val hton = 
               Primitive.IntWordConv.idFromWord32ToInt32 
               o Word32.hton 
               o Primitive.IntWordConv.idFromInt32ToWord32
            val ntoh = 
               Primitive.IntWordConv.idFromWord32ToInt32 
               o Word32.ntoh 
               o Primitive.IntWordConv.idFromInt32ToWord32
         end
      structure Int16 =
         struct
            val hton = 
               Primitive.IntWordConv.idFromWord16ToInt16 
               o Word16.hton 
               o Primitive.IntWordConv.idFromInt16ToWord16
            val ntoh = 
               Primitive.IntWordConv.idFromWord16ToInt16 
               o Word16.ntoh 
               o Primitive.IntWordConv.idFromInt16ToWord16
         end

      structure C_Int =
         struct
            local
               structure S =
                  C_Int_ChooseIntN
                  (type 'a t = 'a -> 'a
                   val fInt8 = fn _ => raise Fail "Net.C_Int.hton: fInt8"
                   val fInt16 = Int16.hton
                   val fInt32 = Int32.hton
                   val fInt64 = fn _ => raise Fail "Net.C_Int.hton: fInt64")
            in
               val hton = S.f
            end
            local
               structure S =
                  C_Int_ChooseIntN
                  (type 'a t = 'a -> 'a
                   val fInt8 = fn _ => raise Fail "Net.C_Int.ntoh: fInt8"
                   val fInt16 = Int16.ntoh
                   val fInt32 = Int32.ntoh
                   val fInt64 = fn _ => raise Fail "Net.C_Int.ntoh: fInt64")
            in
               val ntoh = S.f
            end
         end
   end