From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: =?UTF-8?B?SmFuIFN5bsOhxI1law==?= Newsgroups: gmane.lisp.guile.devel Subject: Re: Reading data from a file descriptor Date: Mon, 9 Nov 2015 08:25:05 +0100 Message-ID: References: <87a8qpx2kg.fsf@elephant.savannah> <874mgxx1y3.fsf@elephant.savannah> <87fv0h1ic2.fsf@delenn.home.rotty.xx.vu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: multipart/alternative; boundary=001a1145a8b80395d50524167e42 X-Trace: ger.gmane.org 1447053919 12178 80.91.229.3 (9 Nov 2015 07:25:19 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Mon, 9 Nov 2015 07:25:19 +0000 (UTC) Cc: guile-devel@gnu.org To: Andreas Rottmann Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Nov 09 08:25:15 2015 Return-path: Envelope-to: guile-devel@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 1ZvgpE-0000lZ-NN for guile-devel@m.gmane.org; Mon, 09 Nov 2015 08:25:12 +0100 Original-Received: from localhost ([::1]:50600 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZvgpD-0008Au-Nh for guile-devel@m.gmane.org; Mon, 09 Nov 2015 02:25:11 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44465) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvgp9-00086R-Um for guile-devel@gnu.org; Mon, 09 Nov 2015 02:25:08 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zvgp8-0002im-Mu for guile-devel@gnu.org; Mon, 09 Nov 2015 02:25:07 -0500 Original-Received: from mail-wm0-x233.google.com ([2a00:1450:400c:c09::233]:38592) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zvgp8-0002i2-Ew for guile-devel@gnu.org; Mon, 09 Nov 2015 02:25:06 -0500 Original-Received: by wmec201 with SMTP id c201so60163532wme.1 for ; Sun, 08 Nov 2015 23:25:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=QiE/Z2eDIKzcAIruUN8FZ2acHp1zZJhoZbCnW8mUXKU=; b=dBf0xnZzOGGEfDv2CJ9I6aKd1xUaYJO/hDoUZtDZFlQBqj6KvCHayoT8NVocAPzDtW 1lpc6MwxYFFcq2jxmS1g4EUZ+FVrtejiqwPMoEEBZZvMd+8M/qXJH5A4zGfsH5txzfsP YOtbWa3O6NsGdP+r1+1eWWrB4jsMxiJn+N4v3d6L7zIXay7nCsoe3tx7asbXit6rQwKu 4Ooz332lROPIL0BOVsc+5gpzHeLjLHM+7Dg0LSfSCOH2MMmp936s5xGtbZdFIXp4L7kZ aIrYDU11OS1jutEv24S+DGOlS5pJRAe7WI+jPS/0Ff1ZhBTBpSIWnknX+xTRxTk8b7+r xRiQ== X-Received: by 10.28.213.12 with SMTP id m12mr25550891wmg.26.1447053905595; Sun, 08 Nov 2015 23:25:05 -0800 (PST) Original-Received: by 10.27.91.209 with HTTP; Sun, 8 Nov 2015 23:25:05 -0800 (PST) In-Reply-To: <87fv0h1ic2.fsf@delenn.home.rotty.xx.vu> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c09::233 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:18014 Archived-At: --001a1145a8b80395d50524167e42 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Sun, Nov 8, 2015 at 12:49 AM, Andreas Rottmann wrote= : > Artyom Poptsov writes: > > > Oh sorry, there was a mistake in my previous mail. 'scm_i_fdes_to_port= ' > > is an internal procedure, but 'scm_fdes_to_port' is defined as Guile AP= I > > and should be available to Guile programs. Here's its definition: > > > > SCM > > scm_fdes_to_port (int fdes, char *mode, SCM name) > > > > And the commentary that I quoted really applies to 'scm_fdes_to_port', > > not to 'scm_i_fdes_to_port'. > > > Also note that if there's no requirement to actually implement this in > C, there's `fdes->inport' and `fdes->outport' on the Scheme level, so > something like the following would be analogous to the C example code > posted: > > (import (ice-9 binary-ports)) > > (define (process-fd fd) > (let ((port (fdes->inport fd))) > (display "read: ") > (display (get-bytevector-n port 100)) > (display "\n"))) > > (process-fd (acquire-valid-fd)) > This is something very similar that I ended up with. Just instead of get-byte-vector, I used read-string!/partial. > You could now just implement `acquire-valid-fd' in C and expose it to > Scheme, if that is even necessary. If you have the FD available via > e.g. an environment variable, `acquire-valid-fd' can be implemented in > Scheme as well. > > Regards, Rotty > -- > Andreas Rottmann -- > Thank you for all the responses! --=20 Jan Syn=C3=A1=C4=8Dek --001a1145a8b80395d50524167e42 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
On S= un, Nov 8, 2015 at 12:49 AM, Andreas Rottmann <a.rottmann@gmx.at> wrote:
Artyom Popt= sov <poptsov.artyom@gmail.co= m> writes:

> Oh sorry, there was a mistake in my previous mail.=C2=A0 'scm_i_fd= es_to_port'
> is an internal procedure, but 'scm_fdes_to_port' is defined as= Guile API
> and should be available to Guile programs.=C2=A0 Here's its defini= tion:
>
> SCM
> scm_fdes_to_port (int fdes, char *mode, SCM name)
>
> And the commentary that I quoted really applie= s to 'scm_fdes_to_port',
> not to 'scm_i_fdes_to_port'.
>
Also note that if there's no requirement to actually implement t= his in
C, there's `fdes->inport' and `fdes->outport' on the Sche= me level, so
something like the following would be analogous to the C example code
posted:

=C2=A0 =C2=A0 (import (ice-9 binary-ports))

=C2=A0 =C2=A0 (define (process-fd fd)
=C2=A0 =C2=A0 =C2=A0 (let ((port (fdes->inport fd)))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (display "read: ")
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (display (get-bytevector-n port 100))
=C2=A0 =C2=A0 =C2=A0 =C2=A0 (display "\n")))

=C2=A0 =C2=A0 (process-fd (acquire-valid-fd))

This is something very similar that I ended up with. Just instead of= get-byte-vector, I used read-string!/partial.
=C2=A0
You could now just implement `acquire-valid-fd' in C and expose it to Scheme, if that is even necessary. If you have the FD available via
e.g. an environment variable, `acquire-valid-fd' can be implemented in<= br> Scheme as well.

Regards, Rotty
--
Andreas Rottmann -- <http://rotty.xx.vu/>

Thank= you for all the responses!
--
Jan Sy= n=C3=A1=C4=8Dek
--001a1145a8b80395d50524167e42--