caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Xavier Leroy <xavier.leroy@inria.fr>
To: Christophe TROESTLER <debian00@tiscali.be>
Cc: "O'Caml Mailing List" <caml-list@inria.fr>
Subject: Re: [Caml-list] What's wrong with win32?
Date: Thu, 1 Apr 2004 15:32:21 +0200	[thread overview]
Message-ID: <20040401153221.A6842@pauillac.inria.fr> (raw)
In-Reply-To: <20040330.190949.63823938.debian00@tiscali.be>; from debian00@tiscali.be on Tue, Mar 30, 2004 at 07:09:49PM +0200

> >   let (ic, oc) = Unix.open_connection (Unix.ADDR_INET(addr, port)) in
> >
> > However, when I try to run it under windows 98 [...]
> >   Fatal error: exception Sys_error("Bad file descriptor")
> 
> Ok, the trouble comes from the fact that Unix.open_connection uses
> in_channel_of_descr of which the manual says
> 
>   in_channel_of_descr  does not work on sockets under Windows 95, 98, ME;
>                        works fine under NT and 2000
> 
> Well, I tried the program under Win 2000 Professional and got the same
> error...

As Loïc Correnson said, Unix.open_connection is broken under Windows
(all versions) in OCaml 3.07, while it works under NT/2000/XP in
earlier versions of 3.06.  This is a stupid coding error while fixing
another bug :-(  The patch against 3.07 sources is simply:

Index: csl/otherlibs/win32unix/unixsupport.c
diff -c csl/otherlibs/win32unix/unixsupport.c:1.18 csl/otherlibs/win32unix/unixsupport.c:1.19
*** csl/otherlibs/win32unix/unixsupport.c:1.18  Mon Jan  6 15:52:57 2003
--- csl/otherlibs/win32unix/unixsupport.c       Thu Apr  1 15:12:36 2004
***************
*** 61,66 ****
--- 61,67 ----
    value res = alloc_custom(&win_handle_ops, sizeof(struct filedescr), 0, 1);
    Socket_val(res) = s;
    Descr_kind_val(res) = KIND_SOCKET;
+   CRT_fd_val(res) = NO_CRT_FD;
    return res;
  }

> Anyway, it would be nice that (1) open_connection be
> mentionend in the manual as not working under win 9* 

Will do.

> or, even much better, to make that (2) Unix.open_connection actually
> works under win32!  IMHO it is quite unfortunate that
> in_channel_of_descr does not work under windows for sockets since it
> basically forces the programmer to reimplement input/output
> functions for these.

It does work (modulo the 3.07 bug) for the NT/2000/XP lineage of Windows.
Making it work under Windows 9x as well would require significant work
(see below), and I don't think it is worth it given that 9x is at
end-of-line.

> Is the current situation made for efficiency reasons (it is costly for
> in/out channels to carry their type with them) or is there a deeper
> problem with Win$ platforms?

It's not a question of efficiency, but rather of not reimplementing a
chunk of the C standard library.  More precisely:

- The buffered I/O channels of OCaml are implemented on top of the
Unix "file descriptor" abstraction and the Unix system calls open(),
read(), write(), lseek(), close().

- Under Windows, the C library provides an emulation of these Unix
idioms that encapsulate Win32 file handles as a Unix-style file
descriptor.  This emulation handles CRLF <-> LF conversion for files
opened in text modes, so it's not 100% trivial.

- In Windows NT/2000/XP, just like under Unix, socket handles (type
SOCKET) are compatible with file handles (type HANDLE), and basic
system calls that operate on the latter (ReadFile, etc) also work on
sockets.  Hence, wrapping a socket as a Unix-style file descriptor
(through the C lib API), then as a buffered I/O channel just works fine.

- In Windows 9x, socket handles are *not* compatible with file handles,
and ReadFile on a socket handle fails.  Therefore, the wrapping of
socket handles described above doesn't work.

- The Win32 implementation of the Unix library already maintains the
information "socket or file" on its file descriptors (type
Unix.filedescr), and arranges so that e.g. Unix.read calls ReadFile()
or recv() as appropriate.  However, to exploit this information at the
level of buffered I/O channels obtained with in_channel_of_descr
would require to throw away the C library emulation of read() et al,
and implement our own.  That's not completely trivial due to text mode
handling, and is in my opinion too much work for the purpose of
supporting Windows 9x, which is an horrible piece of software that
should die as quickly as possible.

Hope this answers your question.

- Xavier Leroy

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


  parent reply	other threads:[~2004-04-01 13:32 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-03-30 10:49 Christophe TROESTLER
2004-03-30 17:09 ` Christophe TROESTLER
2004-04-01  8:43   ` Correnson Loïc
2004-04-01 13:32   ` Xavier Leroy [this message]
2004-04-03 12:30     ` Christophe TROESTLER

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20040401153221.A6842@pauillac.inria.fr \
    --to=xavier.leroy@inria.fr \
    --cc=caml-list@inria.fr \
    --cc=debian00@tiscali.be \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).