From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludovic.courtes@laas.fr (=?iso-8859-1?q?Ludovic_Court=E8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: Exposing common type wrapping/unwrapping methods Date: Tue, 14 Jun 2005 18:38:38 +0200 Organization: LAAS-CNRS Message-ID: <87k6kwopv5.fsf@laas.fr> References: <87oecutxox.fsf@laas.fr> <87vf58cxxq.fsf@zagadka.de> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: sea.gmane.org 1118767055 5575 80.91.229.2 (14 Jun 2005 16:37:35 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 14 Jun 2005 16:37:35 +0000 (UTC) Cc: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Jun 14 18:37:33 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1DiEOY-0000YD-VT for guile-user@m.gmane.org; Tue, 14 Jun 2005 18:36:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DiETa-0003Sl-9O for guile-user@m.gmane.org; Tue, 14 Jun 2005 12:41:22 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1DiERo-0002oA-CC for guile-user@gnu.org; Tue, 14 Jun 2005 12:39:33 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1DiERi-0002ln-TM for guile-user@gnu.org; Tue, 14 Jun 2005 12:39:27 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1DiERi-0002kK-5U for guile-user@gnu.org; Tue, 14 Jun 2005 12:39:26 -0400 Original-Received: from [140.93.0.15] (helo=laas.laas.fr) by monty-python.gnu.org with esmtp (TLS-1.0:DHE_RSA_3DES_EDE_CBC_SHA:24) (Exim 4.34) id 1DiEQ9-0006g5-Ig for guile-user@gnu.org; Tue, 14 Jun 2005 12:37:49 -0400 Original-Received: by laas.laas.fr (8.13.1/8.13.1) with SMTP id j5EGaKGL018078; Tue, 14 Jun 2005 18:36:25 +0200 (CEST) Original-To: Marius Vollmer X-URL: http://www.laas.fr/~lcourtes/ X-Revolutionary-Date: 26 Prairial an 213 de la =?iso-8859-1?q?R=E9volution?= X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: powerpc-unknown-linux-gnu In-Reply-To: <87vf58cxxq.fsf@zagadka.de> (Marius Vollmer's message of "Tue, 24 May 2005 20:53:53 +0300") User-Agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux) X-Spam-Score: 0 () X-Scanned-By: MIMEDefang at CNRS-LAAS X-MIME-Autoconverted: from 8bit to quoted-printable by laas.laas.fr id j5EGaKGL018078 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:4629 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:4629 Hi, Marius Vollmer writes: > ludovic.courtes@laas.fr (Ludovic Court=E8s) 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=E8s * 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 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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. */ =20 -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 =20 +/* 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 ma= y be + freed using `free ()'. */ +struct sockaddr * +scm_to_sockaddr (int family, SCM address, SCM args) +{ + size_t size; + struct sockaddr *soka; + + soka =3D 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 =20 /* Put the components of a sockaddr into a new SCM vector. */ -static SCM -scm_addr_vector (const struct sockaddr *address, int addr_size,=20 +static SCM_C_INLINE_KEYWORD SCM +_scm_from_sockaddr (const struct sockaddr *address, unsigned addr_size, const char *proc) { short int fam =3D address->sa_family; @@ -953,8 +969,10 @@ break; #endif default: + result =3D 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; } =20 +/* 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 =3D=3D -1) SCM_SYSERROR; newsock =3D SCM_SOCK_FD_TO_PORT (newfd); - address =3D scm_addr_vector (addr, addr_size, FUNC_NAME); + address =3D _scm_from_sockaddr (addr, addr_size, FUNC_NAME); return scm_cons (newsock, address); } #undef FUNC_NAME @@ -1031,7 +1057,7 @@ fd =3D SCM_FPORT_FDES (sock); if (getsockname (fd, addr, &addr_size) =3D=3D -1) SCM_SYSERROR; - return scm_addr_vector (addr, addr_size, FUNC_NAME); + return _scm_from_sockaddr (addr, addr_size, FUNC_NAME); } #undef FUNC_NAME =20 @@ -1053,7 +1079,7 @@ fd =3D SCM_FPORT_FDES (sock); if (getpeername (fd, addr, &addr_size) =3D=3D -1) SCM_SYSERROR; - return scm_addr_vector (addr, addr_size, FUNC_NAME); + return _scm_from_sockaddr (addr, addr_size, FUNC_NAME); } #undef FUNC_NAME =20 @@ -1207,7 +1233,7 @@ if (rv =3D=3D -1) SCM_SYSERROR; if (addr->sa_family !=3D AF_UNSPEC) - address =3D scm_addr_vector (addr, addr_size, FUNC_NAME); + address =3D _scm_from_sockaddr (addr, addr_size, FUNC_NAME); else address =3D SCM_BOOL_F; =20 Index: socket.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D 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, S= CM args_and_flags); SCM_API void scm_init_socket (void); =20 +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 a= rgs); + #endif /* SCM_SOCKET_H */ =20 /* _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user