[MLton-commit] r4333

Matthew Fluet MLton@mlton.org
Mon, 30 Jan 2006 18:01:36 -0800


A temporary "fix" for the echo.sml regression failure.

The real bug runs much deeper, and is a consequence of the fact that
in HEAD, we are using ntohs and htons to handle network/host endian
conversions, which is completely wrong, as they have the signatures:

uint16_t ntohs(uint16_t);
uint16_t htons(uint16_t);

but we wrap/import them as

Int Net_htons (Int i) { return htons (i); }
Int Net_ntohs (Int i) { return ntohs (i); }

val htons = _import "Net_htons": int -> int;
val ntohs = _import "Net_ntohs": int -> int;

As a consequence, we are only endian converting the two lower bytes.
It's a wonder any of the networking works at all.


----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/basis-library/net/inet-sock.sml

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/basis-library/net/inet-sock.sml
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/basis-library/net/inet-sock.sml	2006-01-31 01:50:54 UTC (rev 4332)
+++ mlton/branches/on-20050822-x86_64-branch/basis-library/net/inet-sock.sml	2006-01-31 02:01:34 UTC (rev 4333)
@@ -18,16 +18,19 @@
       val inetAF = NetHostDB.intToAddrFamily PrimitiveFFI.Socket.AF.INET
 
       fun toAddr (in_addr, port) =
+         let val port = Net.htonl port
+         in
          if port < 0 orelse port >= 0x10000
             then PosixError.raiseSys PosixError.inval
          else
             let
                val (sa, salen, finish) = Socket.new_sock_addr ()
                val _ = Prim.toAddr (NetHostDB.inAddrToWord8Vector in_addr,
-                                    Net.htonl port, sa, salen)
+                                    port, sa, salen)
             in
                finish ()
             end
+         end
 
       fun any port = toAddr (NetHostDB.any (), port)