From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludovic.courtes@laas.fr (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.user Subject: Re: Exposing common type wrapping/unwrapping methods Date: Mon, 26 Sep 2005 11:37:31 +0200 Organization: LAAS-CNRS Message-ID: <87wtl4890k.fsf@laas.fr> References: <87oecutxox.fsf@laas.fr> <87vf58cxxq.fsf@zagadka.de> <87k6kwopv5.fsf@laas.fr> <87fysk7ady.fsf@zagadka.de> <87mzmpmcm2.fsf@laas.fr> <87aci6u6f4.fsf@laas.fr> <87psr22c2p.fsf@zip.com.au> <87irwtqkop.fsf@laas.fr> <871x3grdst.fsf@zip.com.au> 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 1127740714 28898 80.91.229.2 (26 Sep 2005 13:18:34 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Mon, 26 Sep 2005 13:18:34 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Sep 26 15:18:32 2005 Return-path: Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1EJssI-0005zD-K9 for guile-user@m.gmane.org; Mon, 26 Sep 2005 15:18:30 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EJssH-0005Bn-Va for guile-user@m.gmane.org; Mon, 26 Sep 2005 09:18:29 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1EJpds-0000oy-6i for guile-user@gnu.org; Mon, 26 Sep 2005 05:51:24 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1EJpcX-0000Ig-LB for guile-user@gnu.org; Mon, 26 Sep 2005 05:50:02 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1EJpUZ-0005Kj-Iz for guile-user@gnu.org; Mon, 26 Sep 2005 05:41:47 -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 1EJpRj-000826-Sq for guile-user@gnu.org; Mon, 26 Sep 2005 05:38:52 -0400 Original-Received: by laas.laas.fr (8.13.1/8.13.4) with SMTP id j8Q9cmYO014133; Mon, 26 Sep 2005 11:38:50 +0200 (CEST) Original-To: guile-user@gnu.org X-URL: http://www.laas.fr/~lcourtes/ X-Revolutionary-Date: 5 =?iso-8859-1?Q?Vend=E9miaire?= an 214 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 Mail-Followup-To: guile-user@gnu.org In-Reply-To: <871x3grdst.fsf@zip.com.au> (Kevin Ryde's message of "Fri, 23 Sep 2005 07:30:10 +1000") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) X-Spam-Score: 0.496 () MAILTO_TO_SPAM_ADDR X-Scanned-By: MIMEDefang at CNRS-LAAS X-MIME-Autoconverted: from 8bit to quoted-printable by laas.laas.fr id j8Q9cmYO014133 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:4772 Archived-At: Hi, Kevin Ryde writes: > ludovic.courtes@laas.fr (Ludovic Court=E8s) writes: >> >> Regarding `sendto', I tested it informally as follows: > > An AF_UNIX socket can probably exercise that. The attached patch does this (note that this patch only updated the test itself; for the code, you still need to apply the previous one, minus the `socket.test' part). Note that this makes the test quite large. What I fear is that this may behave completely differently on other Unices, making the test useless. So I'm not in favor of writing lots of test cases for networking -- although that's just what I've been doing. ;-) > Something using localhost would be good. I thought at one stage to > add "IN6ADDR_LOOPBACK" or something as a constant to match > INADDR_LOOPBACK, but never got around to it. When you do it, could you add a test yourself? > The build directory would be an option here, so there's no chance of > leaving garbage outside the tree. CLEANFILES in Makefile.am could > ensure it's removed, which may be easier than catches in the test > code. Yes. But we want the test to do its best to avoid EADDRINUSE errors. In that respect, I believe `tmpnam' is the best solution. BTW, for the sake of consistency, should we use `make-sockaddr' instead of `make-socket-address'? Or both? IOW, do you value readability more than consistency? ;-) Thanks, Ludovic. =0C --- orig/test-suite/tests/socket.test +++ mod/test-suite/tests/socket.test @@ -6,12 +6,12 @@ ;;;; modify it under the terms of the GNU Lesser General Public ;;;; License as published by the Free Software Foundation; either ;;;; version 2.1 of the License, or (at your option) any later version. -;;;;=20 +;;;; ;;;; This library is distributed in the hope that it will be useful, ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;;;; Lesser General Public License for more details. -;;;;=20 +;;;; ;;;; You should have received a copy of the GNU Lesser General Public ;;;; License along with this library; if not, write to the Free Software ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110= -1301 USA @@ -19,6 +19,7 @@ (define-module (test-suite test-numbers) #:use-module (test-suite lib)) =20 +=0C ;;; ;;; inet-ntop ;;; @@ -78,3 +79,177 @@ (eqv? #xF0 (inet-pton AF_INET6 "0000:0000:0000:0000:0000:0000:0000:00F0")))))) + +=0C +;;; +;;; make-socket-address +;;; + +(with-test-prefix "make-socket-address" + (if (defined? 'AF_INET) + (pass-if "AF_INET" + (let ((sa (make-socket-address AF_INET 123456 80))) + (and (=3D (sockaddr:fam sa) AF_INET) + (=3D (sockaddr:addr sa) 123456) + (=3D (sockaddr:port sa) 80))))) + + (if (defined? 'AF_INET6) + (pass-if "AF_INET6" + ;; Since the platform doesn't necessarily support `scopeid', we won't + ;; test it. + (let ((sa* (make-socket-address AF_INET6 123456 80 1)) + (sa+ (make-socket-address AF_INET6 123456 80))) + (and (=3D (sockaddr:fam sa*) (sockaddr:fam sa+) AF_INET6) + (=3D (sockaddr:addr sa*) (sockaddr:addr sa+) 123456) + (=3D (sockaddr:port sa*) (sockaddr:port sa+) 80) + (=3D (sockaddr:flowinfo sa*) 1))))) + + (if (defined? 'AF_UNIX) + (pass-if "AF_UNIX" + (let ((sa (make-socket-address AF_UNIX "/tmp/unix-socket"))) + (and (=3D (sockaddr:fam sa) AF_UNIX) + (string=3D? (sockaddr:path sa) "/tmp/unix-socket")))))) + + +=0C +;;; +;;; AF_UNIX sockets and `make-socket-address' +;;; + +(if (defined? 'AF_UNIX) + (with-test-prefix "AF_UNIX/SOCK_DGRAM" + + ;; testing `bind' and `sendto' and datagram sockets + + (let ((server-socket (socket AF_UNIX SOCK_DGRAM 0)) + (server-bound? #f) + (path (tmpnam))) + + (pass-if "bind" + (catch 'system-error + (lambda () + (bind server-socket AF_UNIX path) + (set! server-bound? #t) + #t) + (lambda args + (let ((errno (system-error-errno args))) + (cond ((=3D errno EADDRINUSE) (throw 'unresolved)) + (else (apply throw args))))))) + + (pass-if "bind/sockaddr" + (let* ((sock (socket AF_UNIX SOCK_STREAM 0)) + (path (tmpnam)) + (sockaddr (make-socket-address AF_UNIX path))) + (catch 'system-error + (lambda () + (bind sock sockaddr) + (false-if-exception (delete-file path)) + #t) + (lambda args + (let ((errno (system-error-errno args))) + (cond ((=3D errno EADDRINUSE) (throw 'unresolved)) + (else (apply throw args)))))))) + + (pass-if "sendto" + (if (not server-bound?) + (throw 'unresolved) + (let ((client (socket AF_UNIX SOCK_DGRAM 0))) + (> (sendto client "hello" AF_UNIX path) 0)))) + + (pass-if "sendto/sockaddr" + (if (not server-bound?) + (throw 'unresolved) + (let ((client (socket AF_UNIX SOCK_DGRAM 0)) + (sockaddr (make-socket-address AF_UNIX path))) + (> (sendto client "hello" sockaddr) 0)))) + + (false-if-exception (delete-file path))))) + + +(if (defined? 'AF_UNIX) + (with-test-prefix "AF_UNIX/SOCK_STREAM" + + ;; testing `bind', `listen' and `connect' on stream-oriented socke= ts + + (let ((server-socket (socket AF_UNIX SOCK_STREAM 0)) + (server-bound? #f) + (server-listening? #f) + (server-pid #f) + (path (tmpnam))) + + (pass-if "bind" + (catch 'system-error + (lambda () + (bind server-socket AF_UNIX path) + (set! server-bound? #t) + #t) + (lambda args + (let ((errno (system-error-errno args))) + (cond ((=3D errno EADDRINUSE) (throw 'unresolved)) + (else (apply throw args))))))) + + (pass-if "bind/sockaddr" + (let* ((sock (socket AF_UNIX SOCK_STREAM 0)) + (path (tmpnam)) + (sockaddr (make-socket-address AF_UNIX path))) + (catch 'system-error + (lambda () + (bind sock sockaddr) + (false-if-exception (delete-file path)) + #t) + (lambda args + (let ((errno (system-error-errno args))) + (cond ((=3D errno EADDRINUSE) (throw 'unresolved)) + (else (apply throw args)))))))) + + (pass-if "listen" + (if (not server-bound?) + (throw 'unresolved) + (begin + (listen server-socket 123) + (set! server-listening? #t) + #t))) + + (if server-listening? + (let ((pid (primitive-fork))) + ;; Spawn a server process. + (case pid + ((-1) (throw 'unresolved)) + ((0) ;; the kid: serve two connections and exit + (let serve ((conn + (false-if-exception (accept server-socket))) + (count 1)) + (if (not conn) + (exit 1) + (if (> count 0) + (serve (false-if-exception (accept server-socket)) + (- count 1))))) + (exit 0)) + (else ;; the parent + (set! server-pid pid) + #t)))) + + (pass-if "connect" + (if (not server-pid) + (throw 'unresolved) + (let ((s (socket AF_UNIX SOCK_STREAM 0))) + (connect s AF_UNIX path) + #t))) + + (pass-if "connect/sockaddr" + (if (not server-pid) + (throw 'unresolved) + (let ((s (socket AF_UNIX SOCK_STREAM 0))) + (connect s (make-socket-address AF_UNIX path)) + #t))) + + (pass-if "accept" + (if (not server-pid) + (throw 'unresolved) + (let ((status (cdr (waitpid server-pid)))) + (eq? 0 (status:exit-val status))))) + + (false-if-exception (delete-file path)) + + #t))) + _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://lists.gnu.org/mailman/listinfo/guile-user