Sockets again

Glynn Clements
Thu, 1 May 2003 04:28:44 +0100

C.Reinke wrote:

> > More generally, many of the higher-level I/O functions have been
> > over-simplified to the point where they're unsuitable for real-world
> > use.
> would it be possible (i.e., would you or someone else who's
> already been through the problems be willing;-) to document the
> known problems with the high-level network functions? 

I wasn't referring to network functions specifically, but I/O
functions generally.

One key problem with the higher-level I/O functions (including
networking) is the use of the Handle type (which seems to be roughly
analogous to ANSI C's "FILE*").

While this is portable, it's too limited to be of use to non-trivial
programs. ANSI I/O is fine for simple programs (read file, write
file), but once you start getting into writing interactive programs or
complex networking daemons, you tend to have to start using low-level
features (tty control, buffering, select(), signal handling etc).

The main problem with high-level interfaces (generally, not just in
Haskell) is that they're fine so long as they do everything that you
require. But as soon as you need to do something which the interface
doesn't allow for, not only do you have to find the appropriate
low-level interface but, unless you can avoid the high-level interface
altogether, you also need to acquire a thorough understanding of
exactly how the two relate to each other.

E.g. using both an ANSI stream (FILE*) and its descriptor in the same
program is likely to produce unexpected (and undesirable) behaviour
unless you have a reasonable understanding of exactly how the ANSI I/O
stuff works internally. If you find that you have to use descriptors
for at least some operations, it's often simpler to just not use the
ANSI interface at all.

Glynn Clements <>