unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: ludovic.courtes@laas.fr (Ludovic Courtès)
Cc: guile-user@gnu.org
Subject: Re: Exposing common type wrapping/unwrapping methods
Date: Tue, 14 Jun 2005 18:38:38 +0200	[thread overview]
Message-ID: <87k6kwopv5.fsf@laas.fr> (raw)
In-Reply-To: <87vf58cxxq.fsf@zagadka.de> (Marius Vollmer's message of "Tue, 24 May 2005 20:53:53 +0300")

Hi,

Marius Vollmer <mvo@zagadka.de> writes:

> ludovic.courtes@laas.fr (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  <ludovic.courtes@laas.fr>

	* 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
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2005-06-14 16:38 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-04-04 14:37 Exposing common type wrapping/unwrapping methods Ludovic Courtès
2005-05-24 17:53 ` Marius Vollmer
2005-06-14 16:38   ` Ludovic Courtès [this message]
2005-08-19  7:57     ` Ludovic Courtès
2005-08-20  6:01       ` Ken Raeburn
2005-08-20 12:40         ` Marius Vollmer
2005-08-20 13:53           ` Ken Raeburn
2005-09-04 22:17             ` Marius Vollmer
2005-09-07  4:17               ` Rob Browning
2005-09-04 22:09     ` Marius Vollmer
2005-09-07  9:49       ` Ludovic Courtès
2005-09-21  9:16         ` Ludovic Courtès
2005-09-22  0:14           ` Kevin Ryde
2005-09-22 13:46             ` Ludovic Courtès
2005-09-22 21:30               ` Kevin Ryde
2005-09-26  9:37                 ` Ludovic Courtès
2005-09-28 21:30               ` Kevin Ryde
2005-10-04 14:08                 ` Socket API improvement, patch #6 Ludovic Courtès
2005-10-17 10:55                   ` Ludovic Courtès
2005-10-17 21:43                     ` Kevin Ryde
2005-10-18  7:45                       ` Ludovic Courtès
2005-10-18 20:17                         ` Marius Vollmer
2005-10-24 11:35                           ` Ludovic Courtès
2005-10-24 21:42                             ` Kevin Ryde
2005-10-25 21:24                               ` Marius Vollmer
2005-10-27  1:06                                 ` Kevin Ryde
2005-10-27  8:49                                   ` Ludovic Courtès
2005-10-28 23:00                                     ` Kevin Ryde
2005-10-29 17:45                                       ` Marius Vollmer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k6kwopv5.fsf@laas.fr \
    --to=ludovic.courtes@laas.fr \
    --cc=guile-user@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).