Close the master fd once input loop is done
Don't quit the read loop on end of script
Remove explicit flush calls, use format specifier
Pull write and read into function
Remove source differentiation in output
Use select to poll the master fd for output
Add a small timeout for letting input get processed