From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Marko Rauhamaa Newsgroups: gmane.lisp.guile.user Subject: Re: Guile: passing a file descriptor Date: Sun, 12 Oct 2014 01:20:36 +0300 Message-ID: <87k3462qq3.fsf@elektro.pacujo.net> References: <877g073v5o.fsf@elektro.pacujo.net> <87r3yeijxl.fsf@yeeloong.lan> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1413066064 1278 80.91.229.3 (11 Oct 2014 22:21:04 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 11 Oct 2014 22:21:04 +0000 (UTC) Cc: guile-user@gnu.org To: Mark H Weaver Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Oct 12 00:20:57 2014 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Xd521-0000cz-4q for guile-user@m.gmane.org; Sun, 12 Oct 2014 00:20:57 +0200 Original-Received: from localhost ([::1]:55430 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xd520-0006w2-LB for guile-user@m.gmane.org; Sat, 11 Oct 2014 18:20:56 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:37852) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xd51o-0006vm-N5 for guile-user@gnu.org; Sat, 11 Oct 2014 18:20:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Xd51k-0005BQ-4B for guile-user@gnu.org; Sat, 11 Oct 2014 18:20:44 -0400 Original-Received: from pacujo.net ([83.150.83.132]:45634) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Xd51j-0005BK-Rk for guile-user@gnu.org; Sat, 11 Oct 2014 18:20:40 -0400 Original-Received: from elektro.pacujo.net (192.168.1.200) by elektro.pacujo.net; Sun, 12 Oct 2014 01:20:36 +0300 Original-Received: by elektro.pacujo.net (sSMTP sendmail emulation); Sun, 12 Oct 2014 01:20:36 +0300 In-Reply-To: <87r3yeijxl.fsf@yeeloong.lan> (Mark H. Weaver's message of "Sat, 11 Oct 2014 13:40:38 -0400") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 83.150.83.132 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:11577 Archived-At: Mark H Weaver : > Marko Rauhamaa writes: > >> A PF_UNIX socket can be used to pass an open file descriptor between >> processes. However, the relevant control message seems to be missing >> in Guile's POSIX facilities (send only accepts a data message). > > Indeed, we lack that functionality in core Guile. > >> Am I mistaken, and are there any plans to add control message support to >> Guile's library? > > I'm not aware of any plans to add it, but if we can agree on an API > and someone contributed a suitable implementation, I don't see why we > couldn't add it. The C API is really messy. However, after looking at it from different angles, I'm thinking one shouldn't deviate too far from it. Here is the germ of a Guile API proposal: sendmsg NAME BYTEVECTOR-INPUT-PORT [CMSG-LIST [flags]] => integer NAME is a placeholder and should be set to #f. BYTEVECTOR-INPUT-PORT may be #f. It captures the idea of the gather array. CMSG-LIST may be #f. Otherwise, it is a list or lists. The member lists have three elements: level, type, bytevector. To support creating the CMSG-LIST elements portably, auxiliary functions are provided: cmsghdr:make-socket-rights list-of-ports-and/or-fds => bytevector cmsghdr:make-credentials pid uid gid => bytevector For example: (sendmsg #f #f (list (list SOL_SOCKET SCM_RIGHTS (cmsghdr:make-socket-rights (list input-fd))))) For the other direction: recvmsg [BYTEVECTOR-OUTPUT-PORT [flags]] => values COUNT NAME CMSG-LIST BYTEVECTOR-OUTPUT-PORT may be #f. It represents the scatter array. NAME is a number or #f. CMSG-LIST may be #f. Otherwise, it is as above. To support interpreting the CMSG-LIST elements portably, auxiliary functions are provided: cmsghdr:socket-rights bytevector => list-of-fds cmsghdr:socket-credentials bytevector => values pid uid gid For example: (call-with-values recvmsg (lambda (count name cmsg-list) (let loop ((cmsgs cmsg-list) (fds '())) (if (null? cmsgs) fds (loop (cdr cmsgs) (let ((cmsg (car cmsgs))) (if (and (= SOL_SOCKET (car cmsg)) (= SCM_RIGHTS (cadr cmsg))) (append fds (cmsghdr:socket-rights (caddr cmsg))))) fds))))) Marko