Patch with new API for get/setsockopt

Bertram Felgenhauer bertram.felgenhauer at googlemail.com
Sun Sep 9 03:38:10 EDT 2007


Matthew Danish wrote:
> Russell O'Connor pointed out the other day that it is impossible to
> use the getSocketOption/setSocketOption functions on options which
> expect or provide a non-Int value.
> 
> I've concocted another API which allows values to be constructed from
> a specific disjoint union.  This should make it possible to use
> options like SendTimeOut which expect a struct timeval.
> 
> The attached darcs patch to the network package has the new functions
> setSockOpt/getSockOpt and SocketOptionValue.  Whether or not those
> will be the final names, I am not sure.  Also, I thought of some
> better possible interfaces, but on Ian's suggestion I stuck to
> Haskell'98 capabilities only.
> 
> I've tested it on Linux/x86-64 and run the validate script.  I'm new
> to GHC development, though, so I'm not sure if I should just go ahead
> and submit the patch.

I had a half finished patch for this problem last year that makes
getSocketOption and setSocketOption polymorphic, and with compile
time type checks [*] - see
  http://www.haskell.org/pipermail/libraries/2006-June/005468.html

Sadly I dropped the ball on this - the missing bit is marshalling
time_val stuff and I'm still unsure where that should go;
System.Posix.Time seems reasonable. Should I pick it up again?

The downside of this approach is that it does break backwards
compatibility for all options that don't take Int values. (This is
curable of course, by providing two interfaces, like you do.)

Bertram

[*] not completely secure but good enough to catch mistakes for
  reasonable uses. Better safety could be achieved with GADTs as
  pointed out by Simon Marlow in
      http://www.haskell.org/pipermail/libraries/2006-July/005534.html


More information about the Libraries mailing list