From mboxrd@z Thu Jan 1 00:00:00 1970 Date: Sat, 5 Dec 2009 14:17:47 +1100 From: Sam Watkins To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Message-ID: <20091205031747.GA8759@nipl.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.13 (2006-08-11) Subject: [9fans] ideas for helpful system io functions Topicbox-Message-UUID: a7d8c766-ead5-11e9-9d60-3106f5b1d025 I have two ideas for io functions that I think would be helpful, they are alternative options to solve a simple problem really. I don't know if plan 9 has any functions like these already. For example, when starting a CGI script for a POST request, a httpd reads the http headers but typically also the first little bit of the POST data. I would like to be able to simply fork and exec the CGI script, but this missing POST data means this will not work. The httpd has to write the POST data to a temporary file, or else use a temporary "socketpair" or similar to communicate with the CGI script. Hopefully you know what I mean. Another example, a little server that allows connections on a single port 443 for https and ssh. Ideally after reading the "GET" or ssh banner, it can just exec whichever server is needed (or fork and exec something like netcat). but in fact due to this "already read some data" problem, it has to stay alive and copy the data in and out from the other server. I can see two possible solutions for this, both of which would be useful in my opinion: - an "unread" function, like ungetc, which allows a program to put back some data that was already read to the OS stdin buffer (not the stdio buffer). This might be problematic if there is a limit to the size of the buffers. - a "join" function (or something) which allows a process to unify/join its file descriptors (e.g. before exiting). For example join(0, 1) would connect STDIN directly to STDOUT. The OS might need to interpose a "sendfile"-like copy mechanism, or collapse a pipe or socket, to make this work nicely. This would allow a process to fork, write some data to STDOUT, join(0, 1) and exit, solving this problem I mentioned. what do you think? I doubt these ideas are original, but I think they would be useful and I don't know of any implementation in unix or any other OS. Sam