2005-06-19 · in Ideas · 273 words

For RMoX, it'd be nice to be able to make sockets look like the other vaguely-Unixy devices. This has been done by several Unix implementations in the past.

One possibility is to have a /dev/tcp device, with ioctls for "connect", "listen", and so on. (I'd rather see a mechanism other than ioctls in the future, but they're what we've got for now.) Doing "accept" is a bit more tricky, because it's got to return a new socket.

Another would be to implement a socket filesystem: open /dev/tcp/connect/ This'd avoid much of the ioctl mess, although doing more complex things (like setting the local address) would require adding more complexity to the filesystem. It also means generating strings from IP addresses if you want to programmatically open a connection, which is less than ideal. You could deal with incoming connections by repeatedly trying to open /dev/tcp/listen/80, and having each open return a new connection -- but it's then difficult for the OS to tell if there's something listening.

We really need a typesafe replacement for the ioctl mechanism. One option would be to break away from the Unix way of doing things: rather than having a standard IO stream type which has an way of performing control operations as part of its functionality, have a standard IO stream type which is just one of the things a socket includes; that allows the control channels to be separate.

  IO.CHANS io:
  SOCKET.CTL ctl!:

This needs a separate system call to open -- but that's what Unix does already anyway. It could be done using a system-provided tagged record type, but that makes extension difficult.