1 import Base 2 import ../StorageBytes.bend as StorageBytes 3 4 # Keeps a local socket endpoint within macOS and Linux sockaddr path limits. 5 type Decision is Data: 6 Endpoint{path: String} 7 PathTooLong{} 8 9 # Returns whether one complete endpoint path fits the conservative byte limit. 10 def admit_length(endpoint_bytes: Nat) -> Bool: 11 Nat.is_le(endpoint_bytes, 100n) 12 13 # Appends the fixed owner endpoint name only when the path remains bounded. 14 def endpoint.result(path: String, admitted: Bool) -> Decision: 15 match path: 16 case canonical: 17 match admitted: 18 case True{}: Endpoint{canonical ++ "/MYLSM.sock"} 19 case False{}: PathTooLong{} 20 21 # Builds one endpoint from a path already resolved by the filesystem layer. 22 def for_canonical_path(+canonical_path: String) -> Decision: 23 endpoint.result(canonical_path, 24 admit_length(Nat.add(StorageBytes.string_size(canonical_path), 11n)))