1(* 2 Title: Standard Basis Library: Unix socket structure and signature. 3 Author: David Matthews 4 Copyright David Matthews 2000, 2005, 2016 5 6 This library is free software; you can redistribute it and/or 7 modify it under the terms of the GNU Lesser General Public 8 License version 2.1 as published by the Free Software Foundation. 9 10 This library is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 Lesser General Public License for more details. 14 15 You should have received a copy of the GNU Lesser General Public 16 License along with this library; if not, write to the Free Software 17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18*) 19 20signature UNIX_SOCK = 21sig 22 type unix 23 type 'sock_type sock = (unix, 'sock_type) Socket.sock 24 type 'mode stream_sock = 'mode Socket.stream sock 25 type dgram_sock = Socket.dgram sock 26 type sock_addr = unix Socket.sock_addr 27 val unixAF : Socket.AF.addr_family 28 val toAddr : string -> sock_addr 29 val fromAddr : sock_addr -> string 30 structure Strm : 31 sig 32 val socket : unit -> 'mode stream_sock 33 val socketPair : unit -> 'mode stream_sock * 'mode stream_sock 34 end 35 structure DGrm : 36 sig 37 val socket : unit -> dgram_sock 38 val socketPair : unit -> dgram_sock * dgram_sock 39 end 40end; 41 42structure UnixSock : UNIX_SOCK = 43struct 44 abstype unix = ABSTRACT with end; 45 type 'sock_type sock = (unix, 'sock_type) Socket.sock 46 type 'mode stream_sock = 'mode Socket.stream sock 47 type dgram_sock = Socket.dgram sock 48 type sock_addr = unix Socket.sock_addr 49 50 val unixAF : Socket.AF.addr_family = 51 case Socket.AF.fromString "UNIX" of 52 NONE => raise OS.SysErr("Missing address family", NONE) 53 | SOME s => s 54 55 local 56 val doCall: int * string -> sock_addr 57 = RunCall.rtsCallFull2 "PolyNetworkGeneral" 58 in 59 fun toAddr s = doCall(56, s) 60 end 61 62 local 63 val doCall: int * sock_addr -> string 64 = RunCall.rtsCallFull2 "PolyNetworkGeneral" 65 in 66 fun fromAddr s = doCall(57, s) 67 end 68 69 structure Strm = 70 struct 71 fun socket() = GenericSock.socket(unixAF, Socket.SOCK.stream) 72 fun socketPair() = GenericSock.socketPair(unixAF, Socket.SOCK.stream) 73 end 74 structure DGrm = 75 struct 76 fun socket() = GenericSock.socket(unixAF, Socket.SOCK.dgram) 77 fun socketPair() = GenericSock.socketPair(unixAF, Socket.SOCK.dgram) 78 end 79 80end; 81