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: Ludovic Courtès
Subject: Re: Exposing common type wrapping/unwrapping methods
Date: Fri, 19 Aug 2005 09:57:32 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Hello,

It seems that the email below (<address@hidden>) got lost.  Can
someone comment on this?

Thanks,
Ludovic.

address@hidden (Ludovic Courtès) writes:

> Hi,
>
> Marius Vollmer <address@hidden> writes:
>
>> address@hidden (Ludovic Courtès) writes:
>>
>>> Obviously, the best solution would be to expose the relevant functions
>>> to the user.  :-)
>>
>> Yes, we should do that, following the scm_to and scm_from naming scheme.
>
> Following this discussion, I propose the following addition which
> exposes the wrapping/unwrapping functions of `sockaddr' objects.
>
> Thanks,
> Ludovic.
>
>
> 2005-06-14  Ludovic Courtès  <address@hidden>
>
>       * socket.c (scm_addr_vector):  Renamed to `_scm_from_sockaddr'
>       and made inline.
>       (scm_from_sockaddr):  New function.
>       (scm_to_sockaddr):  New function.
>       (scm_fill_sockaddr):  Made inline.
>
>       * socket.h (scm_from_sockaddr):  New declaration.
>       (scm_to_sockaddr):  New declaration.
>
>
> Index: socket.c
> ===================================================================
> RCS file: /cvsroot/guile/guile/guile-core/libguile/socket.c,v
> retrieving revision 1.114
> diff -u -B -b -r1.114 socket.c
> --- socket.c  5 Jun 2005 18:27:53 -0000       1.114
> +++ socket.c  14 Jun 2005 16:26:51 -0000
> @@ -664,7 +664,7 @@
>     proc is the name of the original procedure.
>     size returns the size of the structure allocated.  */
>  
> -static struct sockaddr *
> +static SCM_C_INLINE_KEYWORD struct sockaddr *
>  scm_fill_sockaddr (int fam, SCM address, SCM *args, int which_arg,
>                  const char *proc, int *size)
>  #define FUNC_NAME proc
> @@ -769,6 +769,22 @@
>  }
>  #undef FUNC_NAME
>    
> +/* Return a newly-allocated `sockaddr' structure that reflects ADDRESS, being
> +   an address of family FAMILY, with the family-specific parameters ARGS (see
> +   the description of `connect' for details).  The returned structure may be
> +   freed using `free ()'.  */
> +struct sockaddr *
> +scm_to_sockaddr (int family, SCM address, SCM args)
> +{
> +  size_t size;
> +  struct sockaddr *soka;
> +
> +  soka = scm_fill_sockaddr (family, address, &args, 1,
> +                         "scm_to_sockaddr", &size);
> +
> +  return soka;
> +}
> +
>  SCM_DEFINE (scm_connect, "connect", 3, 0, 1,
>              (SCM sock, SCM fam, SCM address, SCM args),
>           "Initiate a connection from a socket using a specified address\n"
> @@ -893,8 +909,8 @@
>  #undef FUNC_NAME
>  
>  /* Put the components of a sockaddr into a new SCM vector.  */
> -static SCM
> -scm_addr_vector (const struct sockaddr *address, int addr_size, 
> +static SCM_C_INLINE_KEYWORD SCM
> +_scm_from_sockaddr (const struct sockaddr *address, unsigned addr_size,
>                const char *proc)
>  {
>    short int fam = address->sa_family;
> @@ -953,8 +969,10 @@
>        break;
>  #endif
>      default:
> +      result = SCM_UNSPECIFIED;
>        scm_misc_error (proc, "Unrecognised address family: ~A",
>                     scm_list_1 (scm_from_int (fam)));
> +
>      }
>    return result;
>  }
> @@ -959,6 +977,14 @@
>    return result;
>  }
>  
> +/* The publicly-visible function.  Return a Scheme object representing
> +   ADDRESS, an address of ADDR_SIZE bytes.  */
> +SCM
> +scm_from_sockaddr (const struct sockaddr *address, unsigned addr_size)
> +{
> +  return (_scm_from_sockaddr (address, addr_size, "scm_from_sockaddr"));
> +}
> +
>  /* calculate the size of a buffer large enough to hold any supported
>     sockaddr type.  if the buffer isn't large enough, certain system
>     calls will return a truncated address.  */
> @@ -1009,7 +1035,7 @@
>    if (newfd == -1)
>      SCM_SYSERROR;
>    newsock = SCM_SOCK_FD_TO_PORT (newfd);
> -  address = scm_addr_vector (addr, addr_size, FUNC_NAME);
> +  address = _scm_from_sockaddr (addr, addr_size, FUNC_NAME);
>    return scm_cons (newsock, address);
>  }
>  #undef FUNC_NAME
> @@ -1031,7 +1057,7 @@
>    fd = SCM_FPORT_FDES (sock);
>    if (getsockname (fd, addr, &addr_size) == -1)
>      SCM_SYSERROR;
> -  return scm_addr_vector (addr, addr_size, FUNC_NAME);
> +  return _scm_from_sockaddr (addr, addr_size, FUNC_NAME);
>  }
>  #undef FUNC_NAME
>  
> @@ -1053,7 +1079,7 @@
>    fd = SCM_FPORT_FDES (sock);
>    if (getpeername (fd, addr, &addr_size) == -1)
>      SCM_SYSERROR;
> -  return scm_addr_vector (addr, addr_size, FUNC_NAME);
> +  return _scm_from_sockaddr (addr, addr_size, FUNC_NAME);
>  }
>  #undef FUNC_NAME
>  
> @@ -1207,7 +1233,7 @@
>    if (rv == -1)
>      SCM_SYSERROR;
>    if (addr->sa_family != AF_UNSPEC)
> -    address = scm_addr_vector (addr, addr_size, FUNC_NAME);
> +    address = _scm_from_sockaddr (addr, addr_size, FUNC_NAME);
>    else
>      address = SCM_BOOL_F;
>  
> Index: socket.h
> ===================================================================
> RCS file: /cvsroot/guile/guile/guile-core/libguile/socket.h,v
> retrieving revision 1.17
> diff -u -B -b -r1.17 socket.h
> --- socket.h  23 May 2005 19:57:21 -0000      1.17
> +++ socket.h  14 Jun 2005 16:26:51 -0000
> @@ -54,6 +54,11 @@
>  SCM_API SCM scm_sendto (SCM sockfd, SCM message, SCM fam, SCM address, SCM 
> args_and_flags);
>  SCM_API void scm_init_socket (void);
>  
> +struct sockaddr;
> +SCM_API SCM scm_from_sockaddr (const struct sockaddr *address,
> +                            unsigned addr_size);
> +SCM_API struct sockaddr *scm_to_sockaddr (int family, SCM address, SCM args);
> +
>  #endif  /* SCM_SOCKET_H */
>  
>  /*
>
>
> _______________________________________________
> Guile-user mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/guile-user




reply via email to

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