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

Reply via email to