From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Chris Vine Newsgroups: gmane.lisp.guile.devel Subject: Re: Reading data from a file descriptor Date: Tue, 17 Nov 2015 12:59:56 +0000 Message-ID: <20151117125956.4b2fc363@bother.homenet> References: <87a8qpx2kg.fsf@elephant.savannah> <874mgxx1y3.fsf@elephant.savannah> <87fv0h1ic2.fsf@delenn.home.rotty.xx.vu> <87h9kpvqw1.fsf@netris.org> <09b3d3156d439ce3dd7bedc48d84fd5b@hypermove.net> <20151117095319.GA7958@tuxteam.de> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1447765225 25218 80.91.229.3 (17 Nov 2015 13:00:25 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 17 Nov 2015 13:00:25 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Nov 17 14:00:13 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 1Zyfrp-0000ph-6f for guile-devel@m.gmane.org; Tue, 17 Nov 2015 14:00:13 +0100 Original-Received: from localhost ([::1]:58200 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zyfro-00052X-Lf for guile-devel@m.gmane.org; Tue, 17 Nov 2015 08:00:12 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:37950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zyfrf-0004rx-Rf for guile-devel@gnu.org; Tue, 17 Nov 2015 08:00:10 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Zyfrc-0007UB-K3 for guile-devel@gnu.org; Tue, 17 Nov 2015 08:00:03 -0500 Original-Received: from smtpout1.wanadoo.co.uk ([80.12.242.29]:32658 helo=smtpout.wanadoo.co.uk) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Zyfrc-0007R6-9z for guile-devel@gnu.org; Tue, 17 Nov 2015 08:00:00 -0500 Original-Received: from bother.homenet ([2.25.43.62]) by mwinf5d15 with ME id iczv1r00U1LUlWi03czv5Q; Tue, 17 Nov 2015 13:59:57 +0100 X-ME-Helo: bother.homenet X-ME-Date: Tue, 17 Nov 2015 13:59:57 +0100 X-ME-IP: 2.25.43.62 Original-Received: from bother.homenet (localhost [127.0.0.1]) by bother.homenet (Postfix) with ESMTP id AFBF684920 for ; Tue, 17 Nov 2015 12:59:56 +0000 (GMT) In-Reply-To: <20151117095319.GA7958@tuxteam.de> X-Mailer: Claws Mail 3.13.0 (GTK+ 2.24.28; i686-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-Received-From: 80.12.242.29 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:18028 Archived-At: On Tue, 17 Nov 2015 10:53:19 +0100 wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 >=20 > On Mon, Nov 16, 2015 at 11:54:33AM +0100, Amirouche Boubekki wrote: > > On 2015-11-13 21:41, Jan Syn=C3=A1=C4=8Dek wrote: =20 >=20 > [...] >=20 > > >I have an open fd to a unix socket and I want to read data from > > >it. I know that the data is going to be only strings, but I don't > > >know the length in advance. =20 > >=20 > > Do you know a delimiter? maybe it's the null char? > >=20 > > TCP is stream oriented, it's not structured at this layer into > > messages or segments. You need some knowledge about the byte stream > > to be able to split it into different meaningful piece for the > > upper layer. =20 >=20 > I think I "got" Jan's request, because I've been in a similar > situation before: delimiter is not (yet) part of it. What he's > looking for is an interface =C3=A0 la read(2), meaning "gimme as much > as there is in the queue, up to N bytes, and tell me how much > you gave me". Of course, putting stuff in a byte vector would > be preferable; the only functions I've seen[1] which "do" that > interface are read-string!/partial and write-string/partial > operate on strings, not byte arrays, alas. guile's R6RS implementation has get-bytevector-some, which will do that for you, with unix-read-like behaviour. You cannot use this for UTF-8 text by trying to convert the bytevector with utf8->string, because you could have received a partially formed utf-8 character. So for text, you should use line orientated reading, such as with ice-9 read-line or R6RS get-line. Chris