From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8591 invoked by alias); 21 Jan 2014 15:43:55 -0000 Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Received: (qmail 8580 invoked by uid 89); 21 Jan 2014 15:43:54 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=2.4 required=5.0 tests=AWL,BAYES_50,SEXUAL_BODY autolearn=no version=3.3.2 X-HELO: p02c11o142.mxlogic.net Received: from p02c11o142.mxlogic.net (HELO p02c11o142.mxlogic.net) (208.65.144.75) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 21 Jan 2014 15:43:53 +0000 Received: from unknown [12.218.215.72] (EHLO smtpauth1.linear.com) by p02c11o142.mxlogic.net(mxl_mta-7.2.2-0) with ESMTP id 7b59ed25.0.73043.00-234.188496.p02c11o142.mxlogic.net (envelope-from ); Tue, 21 Jan 2014 08:43:53 -0700 (MST) X-MXL-Hash: 52de95b93e93ee35-766682523819bd08b8331d912c0edf5ede540763 Received: from [10.186.3.241] (unknown [10.186.3.241]) by smtpauth1.linear.com (Postfix) with ESMTPSA id E981C740B1; Tue, 21 Jan 2014 07:43:48 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 6.6 \(1510\)) From: Michael Jones In-Reply-To: Date: Tue, 21 Jan 2014 15:43:00 -0000 Cc: ecos-discuss@ecos.sourceware.org Content-Transfer-Encoding: quoted-printable Message-Id: <98E57315-9D90-4364-BE15-EBAF40D08062@linear.com> References: <339C0166-75DA-47B6-B019-24F898B5324A@proclivis.com> To: Grant Edwards X-AnalysisOut: [v=2.0 cv=AfAG6QrG c=1 sm=1 a=glloKNylpeYNumXQcclYyA==:17 a] X-AnalysisOut: [=J5aGunMx9KwA:10 a=D2_GN2MmYMYA:10 a=BLceEmwcHowA:10 a=kj9] X-AnalysisOut: [zAlcOel0A:10 a=MqDINYqSAAAA:8 a=0a9APWPkDaEA:10 a=pGLkceIS] X-AnalysisOut: [AAAA:8 a=pZub0av_AAAA:8 a=CCpqsmhAAAAA:8 a=WoH5s1QRzlf1e7w] X-AnalysisOut: [AwJoA:9 a=CjuIK1q_8ugA:10 a=bDqfGn44ETEA:10 a=MSl-tDqOz04A] X-AnalysisOut: [:10 a=R29M9AGIJ3MA:10 a=FB0ZcsC-fiHzGu-A:21 a=FuVZoohLAg2H] X-AnalysisOut: [K1UW:21] X-Spam: [F=0.2000000000; CM=0.500; MH=0.500(2014012109); S=0.200(2010122901)] X-MAIL-FROM: X-IsSubscribed: yes Subject: Re: [ECOS] Advice on streams and bsd sockets X-SW-Source: 2014-01/txt/msg00020.txt.bz2 The lseek simply deals with the read buffer and sets position to 0. I tried= to swallow the error, but there is some strange artifact left over that ca= uses telnet to print a ^M. When I tracked that down, it was related telnet = failing to negotiate because writes were not working. I did not track down = how it broke write. I am guessing that the problem is just that no one expe= cted streams to be used with the networking and it probably needs more work= than I have time. I tried an alternate solution. I used two streams, one for read, and one fo= r write. This even worked well in the case where my telnetd was using the f= ile descriptor to handled telnet configuration and streams were used for lu= a. As long as lua is flushing, they coexist properly. But two streams sharing a file descriptor create a new problem. I need to c= lose both streams to release resources because in a telnet environment peop= le log out and log back in. When the streams use the same file descriptor, = the second close returns an error and resources are not freed. The error co= mes from the first close which also closes the file descriptor. I modified fclose to free resources even when there is an error, but that m= ay not be POSIX behavior or may have side effects. Does anyone know in general if streams can share a file descriptor in other= systems and all be closed properly? If this is the expected behavior, it i= s probably easier to modify fclose than to solve the seek problem. It is al= so a more natural solution because lua was already setup for stdin and stdo= ut and two streams match the way the code is structured. For those interested, my telnetd package with command line support includin= g lua will be available for others to use. It is part of my Cortex A9 work = for iMX6 SMP hal. Sooner or later someone will post the link on the ecos si= te. Mike On Jan 21, 2014, at 8:10 AM, Grant Edwards wrot= e: > On 2014-01-21, Michael Jones wrote: >> I am looking for some advice on using streams with sockets. I am using C= YGPKG_NET and taking the socket handle and creating a stream with fdopen().= =20 >>=20 >> A fwrite() eventually arrives in this code: >>=20 >> static int=20 >> bsd_lseek(struct CYG_FILE_TAG *fp, off_t *pos, int whence) >> { >> return ESPIPE; >> } >>=20 >> And this causes an error, but a second call to fwrite() works. It >> always happens when there is a fwrite() immediately after a fread(), >> as that triggers the seek. >>=20 >> I am looking for advice on how to handle this problem. >=20 > What I would do is first add a diag_printf() to bsd_lseek() to print > out the paramters so you can see exactly what sort of seek is being > attempted. You could add a bit of code to bsd_lseek() to check for > (and return success for) "noop" operations (e.g. seek to 0 offset from > current location). >=20 >> Of course I could not use streams, but I am working with lua 5.2.3 >> and it is based on streams, and don't want to modify it that much. I >> also can't turn off buffering, because lua relies on the ability to >> push bytes back into the stream after reading them. >>=20 >> Does anyone have a patch that works around the problem or know of >> some other way to create a stream that does not rely on seek? In the >> case where I use it, there is no need for seek anyway. I am using the >> stream in place of stdin and stdout so that lua can interact with a >> telnet session. >=20 > If the code works OK with stdin/stdout streams, then the lseek() calls > must not be actually doing anything, right? If that's the case, then > it should be easy enough to modify the the bsd_lseek() function to do > the same. >=20 > --=20 > Grant Edwards grant.b.edwards Yow! I haven't been ma= rried > at in over six years, but = we > gmail.com had sexual counseling e= very > day from Oral Roberts!! >=20 >=20 > --=20 > Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos > and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss >=20 -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss