- 的輸入參數是用四個字段的記錄,所以你的代碼應該是這個樣子:
Socket.select {
rds = readSocketDescs,
wrs = writeSocketDescs,
exs = exnSocketDescs,
timeout = SOME (Time.fromSeconds 10)
}
- 呀,不知道,可能你需要使用列表來保存映射。效率不高,但我看不出你還能做什麼。
(**
* Produces a list of all the pairs in `listPair`, whose keys are present
* in `whiteList`. Example:
*
* ```sml
* - filterListPair op= [(1,"a"), (2,"b"), (3,"c")] [2,3];
* val it = [(2,"b"),(3,"c")] : (int * string) list
* ```
*)
fun filterListPair eq listPair whiteList =
let
fun recur listPair whiteList result =
case (listPair, whiteList) of
([], _) => result
| (_, []) => result
| ((x, y) :: xs, k :: ks) =>
if eq (x, k)
then recur xs ks ((x, y) :: result)
else recur xs whiteList result
in
List.rev (recur listPair whiteList [])
end
val sockets = [ (* what have you *) ]
val descsToSockets = List.map (fn s => (Socket.sockDesc s, s)) sockets
val { rds, wrs, exs } = Socket.select {
rds = readSocketDescs,
wrs = writeSocketDescs,
exs = exnSocketDescs,
timeout = SOME (Time.fromSeconds 10)
}
(*
* The contract of Socket.select ensures that the order in input lists
* is preserved in the output lists, so we can use `filterListPair`.
*)
val selectedReadSockets =
filterListPair Socket.sameDesc descsToSockets rds