httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jeff Trawick <>
Subject Re: APR_EOF?
Date Thu, 22 Jun 2000 19:04:59 GMT
> From:
> Date: Thu, 22 Jun 2000 11:10:49 -0700 (PDT)
> > > Windows files are not the same as Windows sockets.  Ditto for OS/2 and
> > > BeOS.  Because Unix is the only platform that has files and sockets that
> > > are equivalent, it is not possible to combine the two types or any
> > > functions that have to deal with the two types.  Not possible is a bit
> > > strong, obviously it is possible, however it removes type checking at
> > > compile time, and is generally a bad idea.  This was all covered way back
> > > when, when APR was first designed and implemented.
> > 
> > This would be handled by Bill's os_read_with_timeout(), which knows
> > whether it is a pipe or file or socket and thus can use the correct
> > syscall. 
> How does it know?  Are we passing a void * in?  Are we combining the two
> types?  I sure hope we aren't even thinking about combining sockets and
> files in APR.  If we don't combine them, then this can't be
> done.  os_read_with_timeout can help us merge the ap_read code for unix
> and windows, but it can't help us merge files and sockets.

os_read_with_timeout() needs to know a few key pieces of
information in addition to normal parameters to a read:

. handle to pipe/file/socket/whatever
. indicator of whether it is pipe/file/socket/whatever
. timeout value (whether timeout is part of this info or part of
  parmlist to os_read_with_timeout() is not so important to the
  overall discussion)
. eof indicator (if this is here, then os_read_with_timeout() can take
  care of that detail)

At this point, os_read_with_timeout() can handle sockets, files, and

Move up a level to where ap_read() and ap_recv() (and buffering
and ungetc) live...

If you add ungetchar and the buffering information to the key
file/pipe/socket representation (whether or not buffered, ptr to
buffer, offset within buffer, buffer lock, direction), then ap_read()
and ap_recv() could be shims which call a common read function (call
it common_read for now) which can handle buffering and ungetchar but
which doesn't have to know about timeouts and whether it is socket or
pipe or file or what syscall is used to read from them.

ap_file_t and ap_socket_t would embed this other structure.

Note that adding buffering here in common_read implies we do the same
cleanup for write operations, because a buffered read when we've been
writing needs to flush the buffer first.

Besides less code, this would help ensure common semantics across
platforms as well as among files, pipes, and sockets.  It would
provide buffered reading of sockets in APR and ungetc on sockets too
(no claim that this is important).

Jeff Trawick | | PGP public key at web site:
          Born in Roswell... married an alien...

View raw message