MLton.Socket improvement

Stephen Weeks MLton@sourcelight.com
Mon, 17 Dec 2001 15:41:01 -0800


How about going to the following signature.  This includes 4 changes:

1. Adding addr to the Host type.
2. Creating a new SocketAddress type.
3. Adding connect', which allows a from address to be specified.
4. Combining listen and listenAt into a single function that takes
   the two options you talked about.


signature SOCKET =
   sig
      structure Address:
	 sig
	    type t = word
	 end
      
      structure Host:
	 sig
	    type t = {address: Address.t,
		      name: string}

	    val getByAddress: Address.t -> t option
	    val getByName: string -> t option
	 end

      structure Port:
	 sig
	    type t = int
	 end
      
      structure SocketAddress:
	 sig
	    type t = {address: Address.t,
		      port: Port.t}
	 end

      type t (* the type of sockets *)

      val accept: t -> SocketAddress.t * TextIO.instream * TextIO.outstream
      val connect: SocketAddress.t -> TextIO.instream * TextIO.outstream
      val connect': {from: SocketAddress.t option,
		     to: SocketAddress.t} -> TextIO.instream * TextIO.outstream
      val listen: Address.t option * Port.t option -> SocketAddress.t * t
      val shutdownRead: TextIO.instream -> unit
      val shutdownWrite: TextIO.outstream -> unit
   end


Since this is a high level interface, an orthogonal change is to
eliminate the socket type completely, eliminate accept, and fold
accept into listen.

      val listen:
	 Address.t option * Port.t option
	 -> {accept: unit -> {from: SocketAddress.t,
			      ins: TextIO.instream,
			      out: TextIO.outstream},
	     to: SocketAddress.t}

But that's probably a bad idea since at some time we would like to
expose setsockopt and the like.  Actually, what we'd really like is to
have (a subset of) the SML/NJ socket interface, so that we're
compatible.  If you want to implement theirs, and build our new thing
on top, that would be great.