Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Hackers of the world, unite!


devel / comp.unix.programmer / Re: Problems with stdio on TCP (IPV4) sockets

SubjectAuthor
* Problems with stdio on TCP (IPV4) socketsLew Pitcher
+- Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
+* Re: Problems with stdio on TCP (IPV4) socketsMarcel Mueller
|`* Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
| `* Re: Problems with stdio on TCP (IPV4) socketsLawrence D'Oliveiro
|  `- Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
+* Re: Problems with stdio on TCP (IPV4) socketsLawrence D'Oliveiro
|`- Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
+* Re: Problems with stdio on TCP (IPV4) socketsTim Rentsch
|+- Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
|`- Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
+* Re: Problems with stdio on TCP (IPV4) socketsNicolas George
|`* Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
| `* Re: Problems with stdio on TCP (IPV4) socketsNicolas George
|  `* Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
|   `- Re: Problems with stdio on TCP (IPV4) socketsNicolas George
+* Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
|`- Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
`* Re: Problems with stdio on TCP (IPV4) socketsBen Bacarisse
 +* Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
 |+- Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
 |`* Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
 | +* Re: Problems with stdio on TCP (IPV4) socketsLew Pitcher
 | |+- Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
 | |`* Re: Problems with stdio on TCP (IPV4) socketsTim Rentsch
 | | `- Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
 | `* Re: Problems with stdio on TCP (IPV4) socketsNicolas George
 |  `- Re: Problems with stdio on TCP (IPV4) socketsLawrence D'Oliveiro
 +* Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
 |`- Re: Problems with stdio on TCP (IPV4) socketsKeith Thompson
 `* Re: Problems with stdio on TCP (IPV4) socketsLawrence D'Oliveiro
  `* Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
   `* Re: Problems with stdio on TCP (IPV4) socketsLawrence D'Oliveiro
    `* Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
     `* Re: Problems with stdio on TCP (IPV4) socketsLawrence D'Oliveiro
      +- Re: Problems with stdio on TCP (IPV4) socketsRainer Weikusat
      `- Re: Problems with stdio on TCP (IPV4) socketsKaz Kylheku

Pages:12
Re: Problems with stdio on TCP (IPV4) sockets

<87sf1wnk9y.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11457&group=comp.unix.programmer#11457

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 21:09:45 +0000
Lines: 47
Message-ID: <87sf1wnk9y.fsf@doppelsaurus.mobileactivedefense.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqgjgg$288d0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 9qOvewm6l3ivmbfSBkXmmAZe1in5v7Ifi8yFJ7DH2DvytoQLY=
Cancel-Lock: sha1:w1eW5UUcDwhg+qIo+y80RFTR8Jk= sha1:0wgTP5y5BR8h6na1JfLFj5ezNiY= sha256:gd3ryUr6VKWuTX+RFnvT/LddLi4JNMmqc6LMVRZODgQ=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 13 Feb 2024 21:09 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Tue, 13 Feb 2024 12:54:23 +0000, Ben Bacarisse wrote:
>> (The only advice I'd question is that of using non-block I/O by default.
>> I would be surprised if that helps you in this project, and it might
>> make things more complicated.)
>
> This is why we have the “async” paradigm, a.k.a. the resurgence of
> coroutines.

From coroutines, it's usually one step until somebody again reimplements
cooperative userspace threading. Because of this, I'll take the liberty
here to give a brief (hopefully) abstract description of something I've
found useful for modelling complex asynchronous I/O operations¹. This is
in Perl but should be applicable to any language which supports
closures. It's structured around poll (entirely sufficient for small
numbers of file descriptors) but could be made to work with 'something
else' (eg, epoll) as well.

At the base of this is an I/O completion object I've called a 'want' (as
it describes something a program wants). This object contains a file
handle/ file descriptor, an event the program wants (input available or
output possible) and a continuation closure which should be invoked
after the even has occurred.

At the beginning of each iteration of the main event handling loop,
there's a set of current wants and a poll call is made waiting for any
of the I/O events indicated by these. After something happened and this
call returned, the code goes through the set of active wants and
construct a set of next wants as follows:

If the event a certain want wanted hasn't happened yet, add it to the
next set. If it has happened, call the continuation closure which
returns a possibly empty set of wants. If the set isn't empty, add all
of these to the set of next wants. After all active wants have been
dealt with in this way, make the next set the active set and start the
next iteration of the loop.

¹ Eg, to a REST request. This requires a DNS lookup, establishing a TCP
connection, doing a TLS handshake, sending the request and processing
the reply. This involves 2 different file descriptors and multiple I/O
event 'mode switches', waiting for a different kind of event for a file
descriptor than the last one. Establishing a TCP connection
asynchronously is a 'ready for write' event. The following TLS handshake
will at least need to wait for 'input available' but may need both of
them in some a priori unpredictable sequence.

Re: Problems with stdio on TCP (IPV4) sockets

<uqgmm5$28md6$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11459&group=comp.unix.programmer#11459

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 21:24:21 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <uqgmm5$28md6$3@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqgjgg$288d0$1@dont-email.me>
<87sf1wnk9y.fsf@doppelsaurus.mobileactivedefense.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 21:24:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="24b9a84a64cf4b4b69a117a024a5ec4b";
logging-data="2382246"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xPDHmKgPngM5yl0xG3xZl"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:ZIOxGqPjzz69DTcfv+ElfBFac7o=
 by: Lawrence D'Oliv - Tue, 13 Feb 2024 21:24 UTC

On Tue, 13 Feb 2024 21:09:45 +0000, Rainer Weikusat wrote:

> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>
>> This is why we have the “async” paradigm, a.k.a. the resurgence of
>> coroutines.
>
> From coroutines, it's usually one step until somebody again reimplements
> cooperative userspace threading.

That’s what “async” is all about. In Python asyncio, they use the term
“tasks” for these cooperative schedulable entities. They are wrappers
around Python coroutine objects.

> At the base of this is an I/O completion object I've called a 'want' (as
> it describes something a program wants). This object contains a file
> handle/ file descriptor, an event the program wants (input available or
> output possible) and a continuation closure which should be invoked
> after the even has occurred.

In the Python asyncio library, there is this concept of a “future”. In
JavaScript, they call it a “promise”. This is not tied in any way to
particular open files or anything else: think of it as a box, initially
empty, with a sign above it saying “watch this space”. At some point,
something should happen, and tasks can block on waiting for it. When
something appears in the box, they are woken up and can retrieve a copy of
the contents.

In Python asyncio, you can also set an exception on the future. So instead
of getting back a value, each waiting task gets the exception raised in
their context.

> At the beginning of each iteration of the main event handling loop,
> there's a set of current wants and a poll call is made waiting for any
> of the I/O events indicated by these.

Not just I/O events, you also want timers as well.

Re: Problems with stdio on TCP (IPV4) sockets

<87mss49h15.fsf@nosuchdomain.example.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11460&group=comp.unix.programmer#11460

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Keith.S....@gmail.com (Keith Thompson)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 13:43:34 -0800
Organization: None to speak of
Lines: 43
Message-ID: <87mss49h15.fsf@nosuchdomain.example.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<87eddgs727.fsf@doppelsaurus.mobileactivedefense.com>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="09942f338f1e7512b8b276971c0c198d";
logging-data="2370132"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/39UwZotmcoEUQIwqgg37C"
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux)
Cancel-Lock: sha1:v7teZKiATyAZicErTdmKZmVjR2k=
sha1://mlpc+mux23b+8XptNbfRMLqBU=
 by: Keith Thompson - Tue, 13 Feb 2024 21:43 UTC

Rainer Weikusat <rweikusat@talktalk.net> writes:
> Ben Bacarisse <ben.usenet@bsb.me.uk> writes:
>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>
> [...]
>
>>> IF I
>>>
>>> char vrm[16];
>>> fscanf(fd,"Asterisk Call Manager/%s\r\n",vrm);
>>>
>>> to extract the AMI version number that follows the text slash, my
>>> fscanf() hangs.
>
> [...]
>
>> The scanf functions are not intuitive -- you really have to read the
>> manual carefully. The trouble you are having is that space characters
>> are directives and are not treated literally. The \r directs fscanf to
>> read one or more space characters, and it won't stop trying until it
>> reads a non-space character.
>
> This is specifically demanded by the UNIX specification:
>
> ,----
> | A directive composed of one or more white-space characters shall be
> | executed by reading input until no more valid input can be read, or up
> | to the first byte which is not a white-space character, which remains
> | unread.
> `----

And by the ISO C standard:

A directive composed of white-space character(s) is executed by
reading input up to the first non-white-space character (which
remains unread), or until no more characters can be read. The
directive never fails.
[...]

--
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Medtronic
void Void(void) { Void(); } /* The recursive call of the void */

Re: Problems with stdio on TCP (IPV4) sockets

<87o7ckni1p.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11461&group=comp.unix.programmer#11461

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!rocksolid2!news.neodome.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 21:57:54 +0000
Lines: 51
Message-ID: <87o7ckni1p.fsf@doppelsaurus.mobileactivedefense.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqgjgg$288d0$1@dont-email.me>
<87sf1wnk9y.fsf@doppelsaurus.mobileactivedefense.com>
<uqgmm5$28md6$3@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 88dTf4maxlPmFW0oz1UEmwt8AE9CRUYCflOCG63K0SpzJqoeg=
Cancel-Lock: sha1:MhF08QLKOTPLLrgO7vykaq2JjWM= sha1:DylkRE8IBpGCWq+NliVljXvP9fY= sha256:jBAIUSwJ4TszEl2yHLPBTWnaJ1cOk+fMOEFFkMwAMmo=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 13 Feb 2024 21:57 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Tue, 13 Feb 2024 21:09:45 +0000, Rainer Weikusat wrote:
>
>> Lawrence D'Oliveiro <ldo@nz.invalid> writes:
>>
>>> This is why we have the “async” paradigm, a.k.a. the resurgence of
>>> coroutines.
>>
>> From coroutines, it's usually one step until somebody again reimplements
>> cooperative userspace threading.
>
> That’s what “async” is all about. In Python asyncio, they use the term
> “tasks” for these cooperative schedulable entities. They are wrappers
> around Python coroutine objects.

No, it's not. That's an overgeneralisation of a useful concept people
keep reinventing (I just found another one or two weeks ago).

>> At the base of this is an I/O completion object I've called a 'want' (as
>> it describes something a program wants). This object contains a file
>> handle/ file descriptor, an event the program wants (input available or
>> output possible) and a continuation closure which should be invoked
>> after the even has occurred.
>
> In the Python asyncio library, there is this concept of a “future”. In
> JavaScript, they call it a “promise”. This is not tied in any way to
> particular open files or anything else: think of it as a box, initially
> empty, with a sign above it saying “watch this space”. At some point,
> something should happen, and tasks can block on waiting for it. When
> something appears in the box, they are woken up and can retrieve a copy of
> the contents.

And that's another overgeneralization, see below.

[...]

>> At the beginning of each iteration of the main event handling loop,
>> there's a set of current wants and a poll call is made waiting for any
>> of the I/O events indicated by these.
>
> Not just I/O events, you also want timers as well.

On Linux, timers and - more generally - other signal-driven things are
I/O events. It's possible to receive signals on file descriptor via
signalfd which - in combination with setitimer, can be used to provide
arbitrary timer events. It's also possible to get timer events directly
via file descriptor by using 'timer' fds (=> timerfd_create and
friends). I haven't found a real use for these so far,
though. Programming alarms and using these to activate timers based on
some data structure for storing them (eg, a sorted linked list or a
more elaborate priority queue) has been sufficient for me so far.

Re: Problems with stdio on TCP (IPV4) sockets

<uqgoue$29928$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11462&group=comp.unix.programmer#11462

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 22:02:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <uqgoue$29928$1@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqgjgg$288d0$1@dont-email.me>
<87sf1wnk9y.fsf@doppelsaurus.mobileactivedefense.com>
<uqgmm5$28md6$3@dont-email.me>
<87o7ckni1p.fsf@doppelsaurus.mobileactivedefense.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 22:02:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="24b9a84a64cf4b4b69a117a024a5ec4b";
logging-data="2401352"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+NJmfo093Zihzx4kND4oEQ"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:GhO9jBGVaCF31zotG//e53OYI+M=
 by: Lawrence D'Oliv - Tue, 13 Feb 2024 22:02 UTC

On Tue, 13 Feb 2024 21:57:54 +0000, Rainer Weikusat wrote:

> That's an overgeneralisation of a useful concept people
> keep reinventing ...

If it really was a generalization, then there would be nothing to
“reinvent”. You only need to “reinvent” something if a prior concept was
not general enough.

TL;DR: “overgeneralization ... you keep using that word ... I do not think
it means what you think it means”.

Re: Problems with stdio on TCP (IPV4) sockets

<87jzn8nhmt.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11463&group=comp.unix.programmer#11463

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 22:06:50 +0000
Lines: 23
Message-ID: <87jzn8nhmt.fsf@doppelsaurus.mobileactivedefense.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqgjgg$288d0$1@dont-email.me>
<87sf1wnk9y.fsf@doppelsaurus.mobileactivedefense.com>
<uqgmm5$28md6$3@dont-email.me>
<87o7ckni1p.fsf@doppelsaurus.mobileactivedefense.com>
<uqgoue$29928$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 3Rh5AFCBe6Wb63b1F72R8wRZQRKw3jEtdCV9pIXT6y1sStuP4=
Cancel-Lock: sha1:TdYahGuIbQqFJndzcLO+qUdYXyc= sha1:ZGfKlFMMXgPU6AlkuXX7jfG6q5E= sha256:FHnZveXGfh/gOA60F1yMfneauo2mC5votwk6/2NAcO4=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 13 Feb 2024 22:06 UTC

Lawrence D'Oliveiro <ldo@nz.invalid> writes:
> On Tue, 13 Feb 2024 21:57:54 +0000, Rainer Weikusat wrote:
>
>> That's an overgeneralisation of a useful concept people
>> keep reinventing ...
>
> If it really was a generalization, then there would be nothing to
> “reinvent”. You only need to “reinvent” something if a prior concept was
> not general enough.

Surely, as someone who claims to have programmed something the past, you
must be aware that it's possible to reimplement or reprogram something
somebody else already implemented/ programmed in the past, ie, creating (yet
another) green threads implementation.

> TL;DR: “overgeneralization ... you keep using that word ... I do not think
> it means what you think it means”.

If you think that you're thinking, you're only thinking that you're
thinking.
Yes, this is silly. But so is becoming abusive within two posts for
absolutely no reason.

Re: Problems with stdio on TCP (IPV4) sockets

<20240213140607.333@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11464&group=comp.unix.programmer#11464

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 22:13:23 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <20240213140607.333@kylheku.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqgjgg$288d0$1@dont-email.me>
<87sf1wnk9y.fsf@doppelsaurus.mobileactivedefense.com>
<uqgmm5$28md6$3@dont-email.me>
<87o7ckni1p.fsf@doppelsaurus.mobileactivedefense.com>
<uqgoue$29928$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 22:13:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a025c68428803b098d0ddfe0e0453a6a";
logging-data="2402877"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18lQXeqO8s8uTm2XpHvRkPKSeIGXvFA0yw="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:G5scNE8gl6KNtzJMVOIBjkyyl8o=
 by: Kaz Kylheku - Tue, 13 Feb 2024 22:13 UTC

On 2024-02-13, Lawrence D'Oliveiro <ldo@nz.invalid> wrote:
> On Tue, 13 Feb 2024 21:57:54 +0000, Rainer Weikusat wrote:
>
>> That's an overgeneralisation of a useful concept people
>> keep reinventing ...
>
> If it really was a generalization, then there would be nothing to
> “reinvent”. You only need to “reinvent” something if a prior concept was
> not general enough.

Nope! How it works in computing is that people "reinvent" something if
they have no clue it existed before, and describe it using different
terminology.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Re: Problems with stdio on TCP (IPV4) sockets

<65cbecb2$0$11891$426a74cc@news.free.fr>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11465&group=comp.unix.programmer#11465

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!2.eu.feeder.erje.net!feeder.erje.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!cleanfeed1-b.proxad.net!nnrp3-1.free.fr!not-for-mail
Newsgroups: comp.unix.programmer
From: nicolas$...@salle-s.org (Nicolas George)
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Sender: george@phare.invalid (Nicolas George)
X-Newsreader: Flrn (0.9.20070704)
References: <uqehik$1mdue$4@dont-email.me> <65cb236b$0$29737$426a74cc@news.free.fr> <uqfsgu$23ni8$6@dont-email.me> <65cb9511$0$7525$426a74cc@news.free.fr> <uqg4tl$23ni8$10@dont-email.me>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=utf-8
Date: 13 Feb 2024 22:26:58 GMT
Lines: 5
Message-ID: <65cbecb2$0$11891$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 13 Feb 2024 23:26:58 CET
NNTP-Posting-Host: 129.199.129.80
X-Trace: 1707863218 news-2.free.fr 11891 129.199.129.80:42352
X-Complaints-To: abuse@proxad.net
 by: Nicolas George - Tue, 13 Feb 2024 22:26 UTC

Lew Pitcher , dans le message <uqg4tl$23ni8$10@dont-email.me>, a écrit :
> Indeed, I did. And your point is?

I am trying to determine if you belive that Usenet counts as “laboratory
conditions”.

Re: Problems with stdio on TCP (IPV4) sockets

<65cbeebc$0$5273$426a34cc@news.free.fr>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11466&group=comp.unix.programmer#11466

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed1-b.proxad.net!nnrp2-2.free.fr!not-for-mail
Newsgroups: comp.unix.programmer
From: nicolas$...@salle-s.org (Nicolas George)
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Sender: george@phare.invalid (Nicolas George)
X-Newsreader: Flrn (0.9.20070704)
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk> <uqfsae$23ni8$5@dont-email.me> <875xyspcmm.fsf@doppelsaurus.mobileactivedefense.com>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1
Date: 13 Feb 2024 22:35:41 GMT
Lines: 24
Message-ID: <65cbeebc$0$5273$426a34cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 13 Feb 2024 23:35:41 CET
NNTP-Posting-Host: 129.199.129.80
X-Trace: 1707863741 news-4.free.fr 5273 129.199.129.80:46170
X-Complaints-To: abuse@proxad.net
 by: Nicolas George - Tue, 13 Feb 2024 22:35 UTC

Rainer Weikusat , dans le message
<875xyspcmm.fsf@doppelsaurus.mobileactivedefense.com>, a écrit :
> The idea behind non-blocking I/O is usually that of a single-threaded
> program (or a single thread of a program) which needs to handle
> real-time input¹ on more than one file descriptor and thus, cannot block
> waiting for input on one of them as data might arrive at one of the
> others first.

While true, your statement is misleading by bringing threads into the
discussion: it seems to imply that threads would be a solution to use the
convenience of blocking I/O with real-time programs.

But the idea that threads solve I/O concurrency issues is a misconception.
The design POSIX thread API entirely ignores the file descriptor API, and
therefore instead of helping making fd I/O easier, it makes it harder.
People who try to solve concurrent I/O with threads achieve something first,
but as soon as they start implementing the necessary features like timeout
they realize they need to put an event-loop, poll()-based or other, in most
of their threads, while they hoped to avoid an event-loop in their
single-threaded program.

POSIX threads are useful for performance, but it is a mistake to think they
help for I/O. And that mistake is pervasive enough that we must be careful
not to amplify it.

Re: Problems with stdio on TCP (IPV4) sockets

<uqgreb$29lh3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11467&group=comp.unix.programmer#11467

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ldo...@nz.invalid (Lawrence D'Oliveiro)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 22:45:32 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <uqgreb$29lh3$1@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqfsae$23ni8$5@dont-email.me>
<875xyspcmm.fsf@doppelsaurus.mobileactivedefense.com>
<65cbeebc$0$5273$426a34cc@news.free.fr>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 22:45:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="24b9a84a64cf4b4b69a117a024a5ec4b";
logging-data="2414115"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192bbk3X34ubE8GBv+u5GUm"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:fnqlfFXxYkjrDU4fhVS+n/yi1nI=
 by: Lawrence D'Oliv - Tue, 13 Feb 2024 22:45 UTC

On 13 Feb 2024 22:35:41 GMT, Nicolas George wrote:

> POSIX threads are useful for performance, but it is a mistake to think
> they help for I/O. And that mistake is pervasive enough that we must be
> careful not to amplify it.

The 1990s were very much the “decade of threads”, weren’t they. The
concept was just starting to become pervasive across the OSes of the time,
and people wanted to use them for everything, even GUIs.

Multithreading in GUIs (e.g. Sun’s NeWS) turned out to be a mistake.

Re: Problems with stdio on TCP (IPV4) sockets

<86a5o32mxe.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11468&group=comp.unix.programmer#11468

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Wed, 14 Feb 2024 05:30:21 -0800
Organization: A noiseless patient Spider
Lines: 98
Message-ID: <86a5o32mxe.fsf@linuxsc.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk> <uqfsae$23ni8$5@dont-email.me> <875xyspcmm.fsf@doppelsaurus.mobileactivedefense.com> <uqg4rk$23ni8$9@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="7ed86d1e68cd1b7d292e9bbca25f610a";
logging-data="2805495"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1968JmEtpwdCwP3Q2HqqLUOXkC6nl3irvk="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:f5l6gXkwXUwrgwak7oDC1rCnv/c=
sha1:SXdarHXML9qgazHxQr81o9UdFBY=
 by: Tim Rentsch - Wed, 14 Feb 2024 13:30 UTC

Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> [..]
>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>>> On Tue, 13 Feb 2024 12:54:23 +0000, Ben Bacarisse wrote:
[...]

>>>> (The only advice I'd question is that of using non-block I/O by
>>>> default. I would be surprised if that helps you in this project,
>>>> and it might make things more complicated.)
>>>
>>> I've done less programming with non-blocking I/O than I've done
>>> with sockets. I have heard the advice to use non-blocking I/O,
>>> and will consider it, but I don't want to take on too much in one
>>> shot.
>> [...]
>
> For this mini-project, both client and server live on the same
> machine, and communicate through the loopback ("localhost").
> There won't be any significant latency issues or other
> communications interference.
>
> I'm only concerned with writing the client, and it will only
> interact over one channel in a simple request/reply type protocol.
> There doesn't seem to be a pressing need for nonblocking I/O.
>
> But, as it has been suggested here, I will look into nonblocking
> I/O. Perhaps I'm missing something that others have seen.

I guess I should expand on the idea that using non-blocking I/O
is a good idea.

First, my comment was offered as pragmatic advice following many
years of experience both with networking and with socket-level
programming. It is generic advice, given without taking into
account any of the specifics of your project. There is no question
that using non-blocking I/O means more work up front, and I expect
there is a good chance you could get something working without doing
any of the non-blocking stuff.

That said, here are some things to think about.

Although there is only one channel, there are two communication
paths: one for reading and one for writing. If there were really
only one path (e.g., reading a file and writing to a socket) then
using blocking I/O is probably good enough. But any more than
just a single path makes things more complicated.

There can be problems at the protocol level even if the transport
layer is working perfectly. Network programming has a lot in
common with inter-process synchronization, and is just as tricky
except in the cases where it's even trickier. How is the remote
process (which is Asterisk in this case) going to behave? That
can (and often does) matter.

(Incidentally, speaking of Asterisk, Asterisk is great! I've
been running my own home phone system on Asterisk for more than a
decade now, and I'd never give it up.)

As far as the transport layer goes, TCP is very reliable once it
gets going, but there is a little dance that happens at the start
to get things set up, and sometimes one of the partners steps on
the other's foot. I see this happen sporadically with programs
that have the same basic outline as your application (one socket
used for both reading and writing). Probably there is some sort
of interaction with what's going on at the protocol level, but
it's hard to know whether the problem is a protocol issue or
something in one of the network layers.

Assuming you do go ahead with using blocking I/O, and get things
working, there is still a fair chance that at some point down the
road (probably after the application has been deployed) the program
will be the victim of a network hiccup and go catatonic. If and
when that happens: one, it will be frustrating; two, the problem
will be non-reproducible; and three, you won't have any tools to
help diagnose what's going on to cause the problem, because all the
significant events are happening inside one of the blocking system
calls. Conversely, if all the socket I/O is non-blocking, the code
can be instrumented (whether before the fact or after) with various
sorts of logging, and the log information can be examined to see
what's going on.

Final point: probably the most important lesson here is that we
may expect that network system calls are going to fail, and should
program accordingly. When working with files it's easy to get
into the habit of thinking the calls will never fail, because they
almost never do. Network system calls are different. They might
not fail all the time, but they *are* going to fail, and it's
better to anticipate that, and program accordingly. Using
non-blocking I/O makes that easier, partly because "failures"
happen more often in the form of "operation would block", so one
gets into the habit of writing code that handles different kinds
of error returns. This means a little more work at the outset,
but ultimately less work (we hope!) overall.

I guess I should add that I'm not trying to persuade anyone, and
please go ahead as you think best. I thought it might be helpful
to explain some of the rationale underlying my suggestion, and
hence this response.

Re: Problems with stdio on TCP (IPV4) sockets

<871q9f842h.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=11469&group=comp.unix.programmer#11469

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Wed, 14 Feb 2024 15:21:10 +0000
Lines: 64
Message-ID: <871q9f842h.fsf@doppelsaurus.mobileactivedefense.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqfsae$23ni8$5@dont-email.me>
<875xyspcmm.fsf@doppelsaurus.mobileactivedefense.com>
<uqg4rk$23ni8$9@dont-email.me> <86a5o32mxe.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Te5WKvqM48qM4nXTxaUqMwPTCHM+kw3XHOOcf0u6Qzb2g0BkU=
Cancel-Lock: sha1:KA/vg2uhDoloxovIfBPiyGTGP5U= sha1:uHbyn2f2jXkWRNCP+O7MUEL3Q+Q= sha256:VdRf6ffrxubBh7yg2gk1JmNpvvgLrqcahNyMCljDY5o=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Wed, 14 Feb 2024 15:21 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:

[...]

> I guess I should expand on the idea that using non-blocking I/O
> is a good idea.
>
> First, my comment was offered as pragmatic advice following many
> years of experience both with networking and with socket-level
> programming. It is generic advice, given without taking into
> account any of the specifics of your project.

[...]

Ie, this is about using a certain model for handling I/O (specifically,
as originally suggested, busy-polling with interspersed sleeps)
regardless of the actual needs of an application.

[long general statement whose relevance I don't understand]

> Assuming you do go ahead with using blocking I/O, and get things
> working, there is still a fair chance that at some point down the
> road (probably after the application has been deployed) the program
> will be the victim of a network hiccup and go catatonic.

That's pretty much guaranteed to happen as all kinds of 'network
demolition devices' (commonly called firewalls) will silently cut off
perfectly working TCP connections, either because these have exceeded
some idle time their masters considered just too much or because they
have been rebooted or are malfunctioning. But this is only relevant for
long-running, non-interactive programs and will usually need some scheme
for periodic keepalive exchanges to detect connections which have
silenty gone bad.

> If and when that happens: one, it will be frustrating; two, the problem
> will be non-reproducible; and three, you won't have any tools to
> help diagnose what's going on to cause the problem, because all the
> significant events are happening inside one of the blocking system
> calls. Conversely, if all the socket I/O is non-blocking, the code
> can be instrumented (whether before the fact or after) with various
> sorts of logging, and the log information can be examined to see
> what's going on.

With non-blocking I/O, all significant events still happen inside the
kernel, it's just that the program is hammering the kernel with
avoidable system calls.

> Final point: probably the most important lesson here is that we
> may expect that network system calls are going to fail, and should
> program accordingly. When working with files it's easy to get
> into the habit of thinking the calls will never fail, because they
> almost never do. Network system calls are different. They might
> not fail all the time, but they *are* going to fail, and it's
> better to anticipate that, and program accordingly. Using
> non-blocking I/O makes that easier, partly because "failures"
> happen more often in the form of "operation would block", so one
> gets into the habit of writing code that handles different kinds
> of error returns. This means a little more work at the outset,
> but ultimately less work (we hope!) overall.

It's perfectly possible to implement handling for network errors without
introducing EAGAIN pseudo-errors in situations where they don't make
much sense (such as using a request-response protocol over a single TCP
connection).

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor