Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

<sangr> home is where the highest bandwidth is


devel / comp.lang.tcl / Re: Using gets in nonblocking mode on a file not ending in a newline

SubjectAuthor
* Using gets in nonblocking mode on a file not ending in a newlineclt.to.davebr
`* Using gets in nonblocking mode on a file not ending in a newlineRalf Fassel
 `* Using gets in nonblocking mode on a file not ending in a newlinesaitology9
  `- Using gets in nonblocking mode on a file not ending in a newlineRalf Fassel

1
Using gets in nonblocking mode on a file not ending in a newline

<4001667841276@dlp>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10079&group=comp.lang.tcl#10079

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: clt.to.d...@dfgh.net
Newsgroups: comp.lang.tcl
Subject: Using gets in nonblocking mode on a file not ending in a newline
Date: Mon, 07 Nov 22 17:14:36 GMT
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <4001667841276@dlp>
Injection-Info: reader01.eternal-september.org; posting-host="82fc8318be6813634debeaeacf892607";
logging-data="3813201"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SQ0VZphTah71kuUv2ihwo"
Cancel-Lock: sha1:AgUf+rAgqH1T+lFYbuxL2hhjYFk=
 by: clt.to.d...@dfgh.net - Mon, 7 Nov 2022 17:14 UTC

>Are you reading from a pipe to the logger, or from a disk file which is
>in parallel updated by the logger?

I am reading from a file now, but might end up reading data over USB serial
from a Teensy LC or 3.2 microcontroller.

>Where do you see nonblocking mode in tcllib csv?
>I don't see any 'fconfigure' commands in the module, only
>
> while !eof
> if gets < 0 continue
>
>loops... (tcllib 1.20).

It's the same in tcllib 1.21 too.

My code to read one CSV record included:

while {-1 < [gets $ff line]} { ... }

which works fine reading a file in blocking mode.
In looking for why the library code might be different
I found my code did not work for nonblocking mode,
while the tcllib code works in blocking or nonblocking mode.

In retrospect the operation of [gets] makes sense, however
nothing in the documentation for gets (or fconfigure or open)
appears to explain this.

Dave B

Re: Using gets in nonblocking mode on a file not ending in a newline

<yga35au7ime.fsf@akutech.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10080&group=comp.lang.tcl#10080

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Using gets in nonblocking mode on a file not ending in a newline
Date: Mon, 07 Nov 2022 18:57:13 +0100
Lines: 42
Message-ID: <yga35au7ime.fsf@akutech.de>
References: <4001667841276@dlp>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net mD6IDG/D2qUDpZOg6IvbOwueewMrTVRLX16eY3hwnKbUv93YI=
Cancel-Lock: sha1:Wp4LwyLKuprRrM7wkppZiFAel1s= sha1:6KIlPM9AaPwr/29eaeiM0nJq+18=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Mon, 7 Nov 2022 17:57 UTC

* clt.to.davebr@dfgh.net
| My code to read one CSV record included:
>
| while {-1 < [gets $ff line]} { ... }
>
| which works fine reading a file in blocking mode.
| In looking for why the library code might be different
| I found my code did not work for nonblocking mode,
| while the tcllib code works in blocking or nonblocking mode.

Note that the TCLLIB code is

while !eof
if -1 < gets continue

i.e. in non-blocking mode it busy-waits for EOF.

This is quite different from

while -1 < gets
...

which in non-blocking mode stops at the first no-data-available.

I doubt that the Tcllib CSV code will work on input from a serial line,
blocking or not, since it waits for eof, which will never arrive on the
serial line (unless of course you remove the hardware).

Since the Tcllib code does not change the properties of the channel, it
completely depends on how the channel is configured by the caller. And
since it waits for eof, it implicitely requires a channel which will
ultimately 'send' eof.

| I am reading from a file now, but might end up reading data over USB
| serial from a Teensy LC or 3.2 microcontroller.

I *think* your best bet in this case would be to set up an fileevent
handler for the serial line, and read the data event-based as they come
in. Note however that you would need some indication when no more input
is to be expected from the serial line.

R'

Re: Using gets in nonblocking mode on a file not ending in a newline

<tkc0kn$ut9$1@gioia.aioe.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10084&group=comp.lang.tcl#10084

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.75.POSTED!not-for-mail
From: saitolo...@gmail.com (saitology9)
Newsgroups: comp.lang.tcl
Subject: Re: Using gets in nonblocking mode on a file not ending in a newline
Date: Mon, 7 Nov 2022 17:25:25 -0500
Organization: Aioe.org NNTP Server
Message-ID: <tkc0kn$ut9$1@gioia.aioe.org>
References: <4001667841276@dlp> <yga35au7ime.fsf@akutech.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="31657"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.3.2
Content-Language: en-US
X-Notice: Filtered by postfilter v. 0.9.2
 by: saitology9 - Mon, 7 Nov 2022 22:25 UTC

On 11/7/2022 12:57 PM, Ralf Fassel wrote:

>
> | I am reading from a file now, but might end up reading data over USB
> | serial from a Teensy LC or 3.2 microcontroller.
>
> I *think* your best bet in this case would be to set up an fileevent
> handler for the serial line, and read the data event-based as they come
> in. Note however that you would need some indication when no more input
> is to be expected from the serial line.
>
> R'

I think the behavior is more common than serial bus lines. I recall
dealing with output from R and having similar results. IRC, R has
"print" or "cat" and neither prints a newline character by default. So,
when the file closes without doing a newline, the fileevent handler
misses the data that was in the buffer.

Re: Using gets in nonblocking mode on a file not ending in a newline

<ygay1sl6b67.fsf@akutech.de>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10089&group=comp.lang.tcl#10089

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: Re: Using gets in nonblocking mode on a file not ending in a newline
Date: Tue, 08 Nov 2022 10:35:44 +0100
Lines: 42
Message-ID: <ygay1sl6b67.fsf@akutech.de>
References: <4001667841276@dlp> <yga35au7ime.fsf@akutech.de>
<tkc0kn$ut9$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net lxzKhk97dZhg1wIxrVGuhw+3JcZ8fzFs8WTQ8h9ZtJHCXbDEk=
Cancel-Lock: sha1:vVzREfESLZa/jtIOaClc8BMvV3E= sha1:X5UXu8BHR6xlZID1AB9mZvYa8UM=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
 by: Ralf Fassel - Tue, 8 Nov 2022 09:35 UTC

* saitology9 <saitology9@gmail.com>
| IRC, R has "print" or "cat" and neither prints a newline character by
| default. So, when the file closes without doing a newline, the
| fileevent handler misses the data that was in the buffer.

Cf 'gets' manpage:

This command reads the next line from channelId, returns everything in
the line up to (but not including) the end-of-line character(s), and
discards the end-of-line character(s).
--<snip-snip>--
If end of file occurs while scanning for an end of line, the command
returns whatever input is available up to the end of file.

If you're reading from a file, gets will return the last line of that
file regardless of whether there is a newline at the end or not:

set fd [open test.txt w]
puts $fd "line one"
puts -nonewline $fd "line two"
close $fd

exec od -tc test.txt
0000000 l i n e o n e \n l i n e t w
0000020 o
0000021

set fd [open test.txt r]
while {[gets $fd line] >= 0} {
puts "READ: {$line}"
}
close $fd
=>
READ: {line one}
READ: {line two}

The crucial part is 'EOF'. If you're reading from a serial line, there
is no EOF, so 'gets' keeps waiting for the newline to arrive (and does
*not* return the bytes which have already arrived). You need to plain
'read' in that case to get at the waiting bytes.

R'

1
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor