1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768(*---------------------------------------------------------------------------
Copyright (c) 2026 The affect programmers. All rights reserved.
SPDX-License-Identifier: ISC
---------------------------------------------------------------------------*)openAffect__baseopenAffect.Action.Private(* File descriptors *)moduleFd=structmoduletypeUNBLOCKER=sigtypetvalmake:unit->tvaldispose:t->unitvalis_empty:t->boolvaladd_wait_readable:t->Unix.file_descr->blocked:Action.Blocked.Value.t->unitvaladd_wait_writable:t->Unix.file_descr->blocked:Action.Blocked.Value.t->unitvalunblock:t->timeout_ns:Affect_unix__timeline.mtime_span_nsoption->boolvalset_block_bypass:t->unitvalget_domain_local:unit->tvalset_domain_local:t->unitvalclear_domain_local:unit->unitendmoduleT=structtypet=Unix.file_descrletcompare=Repr.compareendmoduleMap=Map.Make(T)moduleSynchronized_map=Synchronized_map.Make(Map)endmoduleFlagfd=struct(* Thanks to MisterDA this should work cross-platform. But we
could plug platform specific stuff like [eventfd] here. *)typet={set:Unix.file_descr;(* send *)clear:Unix.file_descr;(* recv *)clear_buf:Bytes.t}letclear_buf_size=64letmake()=letset,clear=Unix.socketpair~cloexec:truePF_UNIXSOCK_STREAM0inletclear_buf=Bytes.makeclear_buf_size'\x00'inUnix.set_nonblockset;Unix.set_nonblockclear;{set;clear;clear_buf}letsetflag=tryignore(Unix.write_substringflag.set"1"01)with|Unix.Unix_error((EAGAIN|EWOULDBLOCK),_,_)->()letrecclearflag=tryletlen=Bytes.lengthflag.clear_bufinifUnix.readflag.clearflag.clear_buf0len=lenthenclearflagelse()with|Unix.Unix_error((EAGAIN|EWOULDBLOCK),_,_)->()letfdflag=flag.clearletclose_noerrfd=tryUnix.closefdwithUnix.Unix_error_->()letdisposeflag=close_noerrflag.set;close_noerrflag.clearend