caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Robert Roessler <roessler@rftp.com>
To: Caml-list <caml-list@inria.fr>
Subject: Re: [Caml-list] Re: Select on channels (again)
Date: Wed, 23 Aug 2006 10:35:44 -0700	[thread overview]
Message-ID: <44EC91F0.3020103@rftp.com> (raw)
In-Reply-To: <26EB47FDD566A7469FC862DAF373792F018CF5F4@kaiserslautern1.lmsintl.com>

Christoph Bauer wrote:
>>> ...
>>> I did this, but on windows with two programs communicating 
>> over a pipe 
>>> this isn't enough. select on windows and on a pipe doesn't work. 
>>> Therefore I wrote a stub for PeekNamedPipe():
>> "Select on windows" certainly does work... and why not use a 
>> socket pair, just as one might on a *nix system?  That way, 
>> it will work on both.
> 
> Select doesn't work on window pipes. In retrospect sockects
> would be the better choice. I stumbled in a strange dead lock
> with theses pipes, because under windows the pipe buffer
> is set to 1024 bytes (otherlibs/win32unix/pipe.c) and will then
> block til the reader reads the contents. IMO this
> value (SIZEBUF) should be zero to let the system choose the best
> buffer size. [1] 
> 
>> And the fact that socketpair has been left out of the Windows 
>> version of the Unix module is not an impediment - it is easy 
>> to write a useful implementation in OCaml (I can supply one 
>> if needed).
> 
> Please supply one.

Here is what I use:

open Unix
module U2 = struct
   let socketpair af typ proto =
     let listener = socket af typ proto in
     let listener_addr = ADDR_INET(inet_addr_loopback, 0) in
     bind listener listener_addr;
     listen listener 1;
     let listener_name = getsockname listener in
     let connector = socket af typ proto in
     connect connector listener_name;
     let acceptor_full = accept listener in
     close listener;
     (* assert ((getsockname connector) = (snd acceptor_full)); *)
     (connector, (fst acceptor_full))
end

... and then select this socketpair or the one from the Unix module at 
runtime.

Robert Roessler
roessler@rftp.com
http://www.rftp.com


  reply	other threads:[~2006-08-24 15:48 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-08-23  8:29 Christoph Bauer
2006-08-23 17:35 ` Robert Roessler [this message]
2006-08-24  8:18 ` Robert Roessler
  -- strict thread matches above, loose matches on Subject: below --
2006-08-15  0:46 Nathaniel Gray
2006-08-21 22:47 ` Nathaniel Gray
2006-08-22  0:42   ` [Caml-list] " Jonathan Roewen
2006-08-22  6:27     ` Nathaniel Gray
2006-08-22  6:41       ` Jonathan Roewen
2006-08-22  8:15         ` skaller
2006-08-22 21:15           ` Mike Lin
2006-08-23  5:12         ` Nathaniel Gray
2006-08-22  8:10       ` Olivier Andrieu
2006-08-23  5:27         ` Nathaniel Gray
2006-08-22  8:21       ` Jacques Garrigue
2006-08-23  5:16         ` Nathaniel Gray
2006-08-23  6:35           ` skaller
2006-08-23 19:31             ` Nathaniel Gray
2006-08-24  5:37               ` skaller
2006-08-24 19:06                 ` Nathaniel Gray
2006-08-25  1:55                   ` skaller
2006-08-25 22:19                     ` Nathaniel Gray

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=44EC91F0.3020103@rftp.com \
    --to=roessler@rftp.com \
    --cc=caml-list@inria.fr \
    /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).