##- # Author: Brian Tiffin # Dedicated to the public domain # # Date: November 2016 # Modified: 2016-11-27/22:00-0500 ##+ # # filepair.icn, connected file streams # link ximage procedure main() pair := filepair() | stop("filepair failed: ", sys_errstr(&errno)) pid := fork() | stop("fork failed") if pid < 0 then stop("fork failed: ", pid) if pid = 0 then { close(pair[2]) child(pair[1]) } else { close(pair[1]) parent(pair[2]) } write("both: ", pid) end # # child, writer half # procedure child(out) write("Child ", image(out)) every i := 1 to 10 do { write(out, "this is filepair write test ", i) | stop("failed write") flush(out) } close(out) end # # parent, reader half # procedure parent(in) write("Parent ", image(in)) # needs to be a non-blocking read fcntl(in, "F", "d") limiter := 0 until (limiter +:=1) > 200 do { if result := ready(in) then { write("parent received: ", image(result)) break } else { delay(10) } } close(in) end