guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Exposing common type wrapping/unwrapping methods


From: Marius Vollmer
Subject: Re: Exposing common type wrapping/unwrapping methods
Date: Mon, 05 Sep 2005 01:09:45 +0300
User-agent: Gnus/5.11 (Gnus v5.11) Emacs/22.0.50 (gnu/linux)

address@hidden (Ludovic Courtès) writes:

> Following this discussion, I propose the following addition which
> exposes the wrapping/unwrapping functions of `sockaddr' objects.

Hmm, I think your patch mixes the two ways we have to express a socket
address: one way is an argument convention used by connect, bind, and
sendto; the other way is a vector with the relevant data inside, as
returned by accept, getsockname, getpeername, and recvfrom!.

The scm_from_ and scm_to_ functions are meant to convert between a C
representation and a Scheme representation of some value.  Thus, one
should be able to do things like

   scm_equal_p (OBJ, scm_from_sockaddr (scm_to_sockaddr (OBJ)))

for example, and ideally get #t.

Thus, I propose the following functions:

   - SCM scm_from_sockaddr (const struct sockaddr *addr, size_t addr_size);

   Return the SCM representation of ADDR, which is a vector ...

   - struct sockaddr *scm_to_sockaddr (SCM addr);

   Return a newly-allocated `sockaddr' structure that reflects ADDR,
   which is a SCM vector as returned by scm_from_sockaddr, scm_accept,
   etc.  The returned structure may be freed using `free ()'.

   - SCM scm_make_socket_address (SCM fam, SCM address, SCM args);

   Construct a socket address like connect would given the three
   arguments and return it.

   - struct sockaddr *scm_c_make_socket_address (SCM fam, SCM address,
                                                 SCM args);

   Equivalent to scm_to_sockaddr (scm_make_socket_address (...)).

Also, scm_connect, scm_bind, and scm_sendto should probably be changed
to accept a SCM representation of a socket address, so that you could
write, for example:

   (connect sock (make-socket-address ...))

That change should be backwards compatible, of course, which is a
little bit of pain because of the C API...

Ludovic, could you update your patch if you agree?

-- 
GPG: D5D4E405 - 2F9B BCCC 8527 692A 04E3  331E FAF8 226A D5D4 E405




reply via email to

[Prev in Thread] Current Thread [Next in Thread]