File: UnixSock.sml

package info (click to toggle)
polyml 5.2.1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, wheezy
  • size: 19,692 kB
  • ctags: 17,567
  • sloc: cpp: 37,221; sh: 9,591; asm: 4,120; ansic: 428; makefile: 203; ml: 191; awk: 91; sed: 10
file content (84 lines) | stat: -rw-r--r-- 2,600 bytes parent folder | download | duplicates (2)
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
77
78
79
80
81
82
83
84
(*
    Title:      Standard Basis Library: Unix socket structure and signature.
    Author:     David Matthews
    Copyright   David Matthews 2000, 2005

	This library is free software; you can redistribute it and/or
	modify it under the terms of the GNU Lesser General Public
	License as published by the Free Software Foundation; either
	version 2.1 of the License, or (at your option) any later version.
	
	This library is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
	Lesser General Public License for more details.
	
	You should have received a copy of the GNU Lesser General Public
	License along with this library; if not, write to the Free Software
	Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
*)

(* G&R 2004 status: Checked.  No change except that it seems I'd commented out some of the
   type equivalences. *)

signature UNIX_SOCK =
sig
	type unix
	type 'sock_type sock = (unix, 'sock_type) Socket.sock
	type 'mode stream_sock = 'mode Socket.stream sock
	type dgram_sock = Socket.dgram sock
	type sock_addr = unix Socket.sock_addr
	val unixAF : Socket.AF.addr_family
	val toAddr : string -> sock_addr
	val fromAddr : sock_addr -> string
	structure Strm :
	sig
		val socket : unit -> 'mode stream_sock
		val socketPair : unit -> 'mode stream_sock * 'mode stream_sock
	end
	structure DGrm :
	sig
		val socket : unit -> dgram_sock
		val socketPair : unit -> dgram_sock * dgram_sock
	end
end;

structure UnixSock : UNIX_SOCK =
struct
	abstype unix = ABSTRACT with end;
	type 'sock_type sock = (unix, 'sock_type) Socket.sock
	type 'mode stream_sock = 'mode Socket.stream sock
	type dgram_sock = Socket.dgram sock
	type sock_addr = unix Socket.sock_addr

	val unixAF : Socket.AF.addr_family =
		case Socket.AF.fromString "UNIX" of
			NONE => raise OS.SysErr("Missing address family", NONE)
		|	SOME s => s

	local
		val doCall: int * string -> sock_addr
			= RunCall.run_call2 RuntimeCalls.POLY_SYS_network
	in
		fun toAddr s = doCall(56, s)
	end

	local
		val doCall: int * sock_addr -> string
			= RunCall.run_call2 RuntimeCalls.POLY_SYS_network
	in
		fun fromAddr s = doCall(57, s)
	end

	structure Strm =
	struct
		fun socket() = GenericSock.socket(unixAF, Socket.SOCK.stream)
		fun socketPair() = GenericSock.socketPair(unixAF, Socket.SOCK.stream)
	end
	structure DGrm =
	struct
		fun socket() = GenericSock.socket(unixAF, Socket.SOCK.dgram)
		fun socketPair() = GenericSock.socketPair(unixAF, Socket.SOCK.dgram)
	end

end;