Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

A woman should have compassion. -- Kirk, "Catspaw", stardate 3018.2


devel / comp.lang.tcl / fileevent writable

SubjectAuthor
* fileevent writablepd
+- fileevent writableRich
`- fileevent writableHarald Oehlmann

1
fileevent writable

<361b0994-b580-4f50-a21b-8b6ddc30d2a5n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
X-Received: by 2002:a0c:e34c:0:b0:571:471:8925 with SMTP id a12-20020a0ce34c000000b0057104718925mr374939qvm.18.1676834639661;
Sun, 19 Feb 2023 11:23:59 -0800 (PST)
X-Received: by 2002:a25:f905:0:b0:86d:e2b9:a2bd with SMTP id
q5-20020a25f905000000b0086de2b9a2bdmr1356531ybe.421.1676834639246; Sun, 19
Feb 2023 11:23:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.tcl
Date: Sun, 19 Feb 2023 11:23:58 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=139.47.61.241; posting-account=fwjo5QoAAAAcS9TSqEAQL1VEl7b8nCOq
NNTP-Posting-Host: 139.47.61.241
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <361b0994-b580-4f50-a21b-8b6ddc30d2a5n@googlegroups.com>
Subject: fileevent writable
From: eukel...@gmail.com (pd)
Injection-Date: Sun, 19 Feb 2023 19:23:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 2072
 by: pd - Sun, 19 Feb 2023 19:23 UTC

It's not clear to me the concept of writable channel, documentation [1] says:

"A channel is considered to be writable if at least one byte of data can be written to the underlying file or device without blocking, or if an error condition is present on the underlying file or device."

But for my understanding a channel is always writable since you can always write to it, thinking in a file you can always add a line or byte, the same for a socket. Sure the key is without blocking but if you configure the channel to nonblocking then you always write to it without blocking.

One example I've found using 'writable' is [2] and I think the use there is to detect when a socket is ready to send bytes to it, for example when it's fully opened

But cannot find much mores examples, specially file event examples.

May you clarify the concept with an example or send me to some clear documentation?

Thanks in advance

[1] https://www.tcl-lang.org/man/tcl/TclCmd/fileevent.htm
[2] https://wiki.tcl-lang.org/page/Port+scanning+in+tcl

Re: fileevent writable

<tsu5ob$gkj0$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: ric...@example.invalid (Rich)
Newsgroups: comp.lang.tcl
Subject: Re: fileevent writable
Date: Sun, 19 Feb 2023 21:53:15 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <tsu5ob$gkj0$1@dont-email.me>
References: <361b0994-b580-4f50-a21b-8b6ddc30d2a5n@googlegroups.com>
Injection-Date: Sun, 19 Feb 2023 21:53:15 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="eb12652f9c514dfc93474687910d3724";
logging-data="545376"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+4ALS8j8snaAfQrICvjsFc"
User-Agent: tin/2.0.1-20111224 ("Achenvoir") (UNIX) (Linux/3.10.17 (x86_64))
Cancel-Lock: sha1:HW2x/cOFMVSXMVKkT16kpCLCuu4=
 by: Rich - Sun, 19 Feb 2023 21:53 UTC

pd <eukelade@gmail.com> wrote:
> But for my understanding a channel is always writable since you can
> always write to it, thinking in a file you can always add a line or
> byte, the same for a socket.

It is not correct to think a file can always be written into. Consider
a pipe between two processes (which is implemented as stdout of the
writer being the same file as stdin of the reader process).

A typical pipe buffer size is 4kib (4096 bytes).

If the reader consumes bytes at the rate of 1 byte per second, but the
writer writes bytes at the rate of 2 bytes per second, eventually the
4kib buffer will fill.

Once it is filled, the writer will only be able to write at the rate of
1 byte per second (same as the read rate of the reader).

What will happen at the "file interface" level for the writer is that 2
bytes before the buffer fills, a two byte write will complete
immediately. But once the buffer is full, a two byte write by the
writer will take two seconds to complete, and the writer will block in
the write() call for two seconds while the reader consumes two bytes.

> Sure the key is without blocking but if you configure the channel to
> nonblocking then you always write to it without blocking.

Tcl's 'nonblocking' is an abstraction [1] where Tcl hides the underlying
stdio interface from you and allows you to pretend to write as much as
you like. Reality is the Tcl runtime is buffering your writes up in
memory for you beind the scenes.

> One example I've found using 'writable' is [2] and I think the use
> there is to detect when a socket is ready to send bytes to it, for
> example when it's fully opened

Sockets can also block for the same reason as the pipe, the reader is
on a network that transmits 100 bytes per second, while the writer is
on a network that transmits 1000 bytes per second. If the writer
writes bytes at full speed, eventually it has to block to not overrun
the writer.

Note also, that even a disk file can block. If the disk is connected
via an interface capable of writing 1Mbyte/s, but the attached computer
CPU can write to the interface at 10Mbyte/s, eventually the CPU has to
be "blocked" from writing more data because the reader (the disk) can
not keep up.

[1] The C stdio interface provides "non-blocking" I/O by returning a
"status message" from the write() call that indicates: "blocked, try again
later" and it is up to the programmer to write the appropriate retry
loop. Tcl hides that 'retry' complexity inside the runtime and exposes
its "files can always be written" abstraction to the script level.

Re: fileevent writable

<tsvisk$o80r$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.tcl
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: wortka...@yahoo.com (Harald Oehlmann)
Newsgroups: comp.lang.tcl
Subject: Re: fileevent writable
Date: Mon, 20 Feb 2023 11:43:31 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <tsvisk$o80r$1@dont-email.me>
References: <361b0994-b580-4f50-a21b-8b6ddc30d2a5n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 20 Feb 2023 10:43:32 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="f4094052f7fd3f55ce7daf248c49e0f9";
logging-data="794651"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18cMxynXFnDAWm0aGNZSFZh"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.6.1
Cancel-Lock: sha1:tf2JXQEOC/cnHpiMI+aAMMObw3w=
In-Reply-To: <361b0994-b580-4f50-a21b-8b6ddc30d2a5n@googlegroups.com>
Content-Language: en-GB
 by: Harald Oehlmann - Mon, 20 Feb 2023 10:43 UTC

Am 19.02.2023 um 20:23 schrieb pd:
> It's not clear to me the concept of writable channel, documentation [1] says:
>
> "A channel is considered to be writable if at least one byte of data can be written to the underlying file or device without blocking, or if an error condition is present on the underlying file or device."
>
> But for my understanding a channel is always writable since you can always write to it, thinking in a file you can always add a line or byte, the same for a socket. Sure the key is without blocking but if you configure the channel to nonblocking then you always write to it without blocking.
>
> One example I've found using 'writable' is [2] and I think the use there is to detect when a socket is ready to send bytes to it, for example when it's fully opened
>
> But cannot find much mores examples, specially file event examples.
>
> May you clarify the concept with an example or send me to some clear documentation?
>
> Thanks in advance
>
> [1] https://www.tcl-lang.org/man/tcl/TclCmd/fileevent.htm
> [2] https://wiki.tcl-lang.org/page/Port+scanning+in+tcl

Hi PD,

thanks for the question.

A very common usage of writable events is an asynchoneous client socket
connection.
While the socket connects, it is not writable.

The result of the connect process may be a writable socket or an error.
Due to that, an asyncroneous socket often uses the following programming
scheme:

- connect asynchroneously: socket -async
- instal writable event
- in the writable event, do the following:
- check for error (fconfigure -error)
- install a readable event
- eventually send initial data
- remove the writable event. It has no use any more, as the socket is
now always writable.

An example is the http core package.

Harald


devel / comp.lang.tcl / fileevent writable

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor