Socket Options
Carsten Schultz
carsten at codimi.de
Mon Jun 28 08:23:21 EDT 2004
Hi!
On Mon, Jun 28, 2004 at 02:08:29PM +0200, Martin Sjögren wrote:
> mån 2004-06-28 klockan 14.00 skrev Peter Simons:
> > Simon Marlow writes:
> >
> > > I'm tempted to replace the current setSocketOption with
> > > this version. Would anyone object?
> >
> > On the contrary. IMHO, the SockOption type should be
> > extended to contain the required parameter, for example:
> >
> > data SocketOption
> > = Debug Bool
> > | ReuseAddr Bool
> > | SendBuffer (Maybe Int) -- bytes
> > | RecvTimeOut (Maybe Int) -- milliseconds
> > | SendTimeOut (Maybe Int)
> > | [...]
> >
> > Then setSocketOption would even add the type-safety which
> > the original function call doesn't have, and it would be
> > more intuitive to use.
>
> Wouldn't that make
> getSocketOption :: Socket -> SocketOption -> IO Int
> a bit strange? How would you propose to change it?
Possible, but also possibly overkill, would be:
newtype Debug = Debug Bool
newtype SendBuffer = SendBuffer (Maybe Int)
[...]
class SocketOption a where [...]
instance SocketOption Debug [...]
instance SocketOption SendBuffer [...]
[...]
setSocketOption :: SocketOption a => Socket -> a -> IO ()
getSocketOption :: SockerOption a => Socket -> IO a
However, while quite clever :-), this would not be far from having a
seperate get/set-functions for every option (and could indeed be
implemented that way).
Greetings,
Carsten
--
Carsten Schultz (2:38, 33:47), FB Mathematik, FU Berlin
http://carsten.codimi.de/
PGP/GPG key on the pgp.net key servers,
fingerprint on my home page.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://www.haskell.org//pipermail/glasgow-haskell-users/attachments/20040628/376c41a6/attachment.bin
More information about the Glasgow-haskell-users
mailing list