From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id TAA04275; Thu, 23 Aug 2001 19:22:16 +0200 (MET DST) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id TAA04255 for ; Thu, 23 Aug 2001 19:22:14 +0200 (MET DST) Received: from smtpout.mac.com (smtpout.mac.com [204.179.120.89]) by nez-perce.inria.fr (8.11.1/8.10.0) with ESMTP id f7NHMDX03068 for ; Thu, 23 Aug 2001 19:22:13 +0200 (MET DST) Received: by smtpout.mac.com; Thu, 23 Aug 2001 10:19:57 -0700 (PDT) Message-Id: <200108231719.KAA15162@smtpout.mac.com> Received: from asmtp01.mac.com ([10.13.10.65]) by smtp-relay01.mac.com (Netscape Messaging Server 4.15 relay01 Jun 21 2001 23:53:48) with ESMTP id GIJ6T500.3GK for ; Thu, 23 Aug 2001 10:19:53 -0700 Received: from localhost ([17.206.25.144]) by asmtp01.mac.com (Netscape Messaging Server 4.15 asmtp01 Jun 21 2001 23:53:48) with ESMTP id GIJ6T500.RH1; Thu, 23 Aug 2001 10:19:53 -0700 Date: Thu, 23 Aug 2001 10:19:51 -0700 From: j h woodyatt Reply-To: jhw@wetware.com Content-Type: text/plain; format=flowed; charset=us-ascii Subject: Re: [Caml-list] Unix.socket_option in ocaml-3.0.2 Cc: caml-list@inria.fr To: "Ohad Rodeh" X-Mailer: Apple Mail (2.388) In-Reply-To: Mime-Version: 1.0 (Apple Message framework v388) Content-Transfer-Encoding: 7bit Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk On Thursday, August 23, 2001, at 12:02 , Ohad Rodeh wrote: > > A few comments about the new socket interface: > > [...] > 4. Why not use a simple sum type for socket options. Here's what we do > in > Ensemble: > > (* Options passed to setsockopt. > *) > type socket_option = > | Nonblock of bool > | Reuse > | Join of inet > | Leave of inet > | Ttl of int > | Loopback of bool > | Sendbuf of int > | Recvbuf of int > | Bsdcompat of bool > > (* Set one of the above options on a socket. > *) > val setsockopt : socket -> socket_option -> unit I thought of this. It makes getsockopt a pain to use. Sure, you *could* use a pair of similar variant types, e.g.-- type getsockopt_t = [ `Reuse | `Join | `Leave (* | ... *) ] type setsockopt_t = [ `Reuse | `Join of inet | `Leave of inet (* | ... *) ] val getsockopt: socket -> getsockopt_t -> setsockopt_t val setsockopt: socket -> setsockopt_t -> unit ...but then you have to do a pattern match on the result of getsockopt and that seems overly messy to me. And, if you're like me and you want to communicate with weird Darwin NKE's, it's difficult to add new socket options. With my proposal, you get to write code that looks like this: let acceptconn = Unix.SO_ACCEPTCONN.get socket in f acceptconn As opposed to: match Unix.getsockopt socket `Unix.SO_ACCEPTCONN with | `Unix.SO_ACCEPTCONN yes -> f yes | _ -> assert false Adding a new socket option is a simple thing. Define a new module with the type of the option, and the values of the level and the name. Then use the functorial. (Though, the more I think about it, I suspect the 'external' interface semantics are going to make it easier if the the input signature contains the external functions for the specified type. This is an extra complication, but not one that can't be managed, I think.) > Anyway, have fun with caml. Loving it. I never want to go back to C++ or Perl again. -- j h woodyatt "You're standing on sacred ground. Many strange and wonderful things have transpired right where you're standing." --unattributable ------------------- Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/ To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr