Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Philogyny recapitulates erogeny; erogeny recapitulates philogyny.


devel / comp.unix.programmer / 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
Problems with stdio on TCP (IPV4) sockets

<uqehik$1mdue$4@dont-email.me>

  copy mid

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

  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: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 01:44:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <uqehik$1mdue$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 01:44:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="1783758"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+suOj9994Z0cooky4QpntbCwbCORFZCi4="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:1ZWg/d/zGxlnyd/3ghN9SUe/2ns=
 by: Lew Pitcher - Tue, 13 Feb 2024 01:44 UTC

I'm trying to write a client for an existing server (an Asterisk
"Call Manager" server) that converses in text over a bog-standard
bi-directional TCP connection. I haven't done much sockets programming
and need some advice.

I successfully establish my socket connection to the server using
getaddrinfo() (to build the IPV4 address, socket() (to establish
an AF_INET,SOCK_STREAM socket) and connect(). The protocol requires
me to read a text line from the socket before commencing my client
requests.

For the line read, I decided to try stdio, so I fdopen(,"r") using
the acquired socket. The next steps are the ones that are currently
causing me issues.

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.

BUT, if I

char buffer[1024], vrm[16];
fgets(buffer,sizeof buffer,fd);
sscanf(buffer,"Asterisk Call Manager/%s\r\n",vrm);

I manage to obtain the appropriate data. A dump of the
buffer array shows that I did indeed capture the introduction line
from the server.

So, why the difference in behaviour? Obviously, in the fscanf() version,
I've not set something up right. Any hints as to what I've done wrong
would be greatly appreciated.

Thanks in advance for your help
--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqesro$1mdue$5@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 04:57:28 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 208
Message-ID: <uqesro$1mdue$5@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 04:57:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="1783758"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/p4DsuA4MbI8P07Uwh2nyYD57/YBpOfNg="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:7DmQyv8uX6+hJAm7qyheol6lHhc=
 by: Lew Pitcher - Tue, 13 Feb 2024 04:57 UTC

On Tue, 13 Feb 2024 01:44:53 +0000, Lew Pitcher wrote:

> I'm trying to write a client for an existing server (an Asterisk
> "Call Manager" server) that converses in text over a bog-standard
> bi-directional TCP connection. I haven't done much sockets programming
> and need some advice.
[snip]

Here's the code, and some trial runs

First, the code. It embodies three different ways of using stdio to read
the incoming stream.

With no compile options, it dumps (as hex values and as ASCII characters)
the first 29 octets read from the socket. This should (and does) represent
the introduction text sent by the server.

With the -DUSE_FGETS compile option, it uses fgets() to retrieve the first
text line from the server, and sscanf() to parse it. This works.

With the -DUSE_FSCANF compile option, it uses fscanf() to retrieve and
parse the first text line from the server. This hangs.

8<-------------------- main.c -------------------------------------->8
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>

/*
** NB: compile with
** -DUSE_FSCANF for fscanf() parse of 1st input line, or
** -DUSE_FGETS for fgets()/sscanf() parse of 1st input line
** otherwise code will use fgetc() to read the first 29 bytes of input
*/

int netOpen(char *host, char *port);

int main(void)
{ int status = 1;
int s_ami; /* base socket from netOpen(), fd for amiIn */

if ((s_ami = netOpen("localhost","5038")) >= 0)
{
FILE *amiIn;

if (amiIn = fdopen(s_ami,"r"))
{
#ifdef USE_FSCANF
{ /* use fscanf() to retrieve and parse a full line */
char vrm[16];

if (fscanf(amiIn,"Asterisk Call Manager/%s\r\n",vrm) == 1)
{
printf("Got introduction: AMI %s\n",vrm);
status = 1;
}
else puts("Cant retrieve VRM");
}
#else
#ifdef USE_FGETS
{ /* use fgets() to retrieve a full line, then sscanf() to parse it */
char buffer[256], vrm[16];

if (fgets(buffer,sizeof buffer,amiIn))
{
if (sscanf(buffer,"Asterisk Call Manager/%s\r\n",vrm) == 1)
{
printf("Got introduction: AMI %s\n",vrm);
status = 1;
}
else puts("Cant retrieve VRM");
}
else puts("Cant get introduction");
}
#else
{ /* naive dump of the first 29 bytes of input */
int byte;

for (int count = 0; count < 29; ++count)
{
if ((byte = fgetc(amiIn)) == EOF) break;
byte &= 0x7f;
printf("0x%02.2x %c\n",byte,((byte < 32)||(byte == 127))?' ':byte);
}
status = 1;
}
#endif
#endif
}
fclose(amiIn);
}
else fprintf(stderr,"Cant open AMI connection\n");

return status;
}

int netOpen(char *host, char *port)
{ int Socket;
struct addrinfo hint,
*address;

/* prepare the address */
memset(&hint,0,sizeof hint);
hint.ai_family = AF_INET;
hint.ai_socktype = SOCK_STREAM;
hint.ai_protocol = 0;
hint.ai_flags = 0;

if (getaddrinfo(host,port,&hint,&address) == 0)
{
if ((Socket = socket(AF_INET,SOCK_STREAM,0)) != -1)
{
if (connect(Socket,address->ai_addr,address->ai_addrlen) != 0)
{
close(Socket);
Socket = -1; /* connect() failure */
}
freeaddrinfo(address);
}
}
else Socket = -1; /* getaddrinfo() failure */

return Socket;
}

8<-------------------- main.c -------------------------------------->8

Now for the tests.

First off, a telnet session showing telnet's view of the server interaction.
23:43 $ telnet localhost 5038
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
Asterisk Call Manager/7.0.0
^]
telnet> close
Connection closed.
23:43 $

The server sends "Asterisk Call Manager/7.0.0\r\n"

Next, the test program, compiled to dump the first 29 octets received
23:43 $ cc -o test1 main.c
23:44 $ ./test1
0x41 A
0x73 s
0x74 t
0x65 e
0x72 r
0x69 i
0x73 s
0x6b k
0x20
0x43 C
0x61 a
0x6c l
0x6c l
0x20
0x4d M
0x61 a
0x6e n
0x61 a
0x67 g
0x65 e
0x72 r
0x2f /
0x37 7
0x2e .
0x30 0
0x2e .
0x30 0
0x0d
0x0a

OK, so fgetc() can properly read the socket, and confirms the text including
the terminating \r\n combination.

Now, for the fgets()/sscanf() version:
23:44 $ cc -o test2 -DUSE_FGETS main.c
23:44 $ ./test2
Got introduction: AMI 7.0.0

That works as well.

Finally, the fscanf() version:
23:44 $ cc -o test3 -DUSE_FSCANF main.c
23:44 $ ./test3
^C
23:44 $ exit

Which hung. I let it sit for a few seconds, then killed it.

OK, you've seen the code, and you've seen the test results.

So, what did I do wrong in the fscanf() version? Any suggestions?

--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqf0fp$e72n$1@gwaiyur.mb-net.net>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.mb-net.net!open-news-network.org!.POSTED!not-for-mail
From: news.5.m...@spamgourmet.org (Marcel Mueller)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 06:59:21 +0100
Organization: MB-NET.NET for Open-News-Network e.V.
Message-ID: <uqf0fp$e72n$1@gwaiyur.mb-net.net>
References: <uqehik$1mdue$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 13 Feb 2024 05:59:21 -0000 (UTC)
Injection-Info: gwaiyur.mb-net.net;
logging-data="466007"; mail-complaints-to="abuse@open-news-network.org"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kZ8dWFfiE6AbaLe5w4sZKKmCy20= sha256:RqKZ2BY0mug9Kxfu9sOyDZZFDrob7kk9D1x/k14z4Jk=
sha1:Vwojy0pXmwIUAeVHSnHQ+vQ2O5w= sha256:Vo0FqrWtftaNfwxjCmUWKgIIg99ozXgW3W6F8jXmMTY=
Content-Language: de-DE, en-US
In-Reply-To: <uqehik$1mdue$4@dont-email.me>
 by: Marcel Mueller - Tue, 13 Feb 2024 05:59 UTC

Am 13.02.24 um 02:44 schrieb Lew Pitcher:
> For the line read, I decided to try stdio, so I fdopen(,"r") using
> the acquired socket. The next steps are the ones that are currently
> causing me issues.

You do not want to use the buffered FILE API for bidirectional sockets
with message based protocols. This API tries to fill its buffer before
any other processing. And if the other endpoint does not send more data
so far it will block. This is a deadlock if the other endpoint will not
send more unless it gets your response.

Use the low level API (read, write etc.) for sockets. It will simply
return partial data if no more is available for now. Then you can decide
whether you expect more or not.

Typically the best is to use an appropriate library for the protocol you
need.

Marcel

Re: Problems with stdio on TCP (IPV4) sockets

<uqf4au$1vsp3$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.network!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 07:05:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <uqf4au$1vsp3$2@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 07:05:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="24b9a84a64cf4b4b69a117a024a5ec4b";
logging-data="2093859"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KwX6No9ouU7eXCU0Yvqex"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:AWesvbTd2DCibtr9tvkjQ8BR8LU=
 by: Lawrence D'Oliv - Tue, 13 Feb 2024 07:05 UTC

On Tue, 13 Feb 2024 01:44:53 -0000 (UTC), Lew Pitcher wrote:

> For the line read, I decided to try stdio ...

Don’t. Your code is probably reading past the end of the response and
trying to get more.

Also, remember that Asterisk AMI terminates lines with CR/LF.

Sample Python code, from <https://gitlab.com/ldo/seaskirt/>, that
decodes responses properly:

while True :
endpos = self.buff.find(NL + NL)
if endpos >= 0 :
# got at least one complete response
resp = self.buff[:endpos + len(NL)] # include one NL at end
self.buff = self.buff[endpos + 2 * len(NL):]
response = {}
while True :
split, resp = resp.split(NL, 1)
if split != "" :
if split.endswith(":") :
keyword = split[:-1]
value = ""
else :
keyword, value = split.split(": ", 1)
#end if
if keyword in response :
response[keyword] += "\n" + value
else :
response[keyword] = value
#end if
if resp == "" :
break
#end if
#end while
break
#end if
# need more input
if self.EOF :
raise EOFError("Asterisk Manager connection EOF")
#end if
more = await self.sock.recv(IOBUFSIZE, timeout)
if more == None :
# timed out
break
self.buff += more.decode()
if len(more) == 0 :
self.EOF = True
#end if
#end while

Re: Problems with stdio on TCP (IPV4) sockets

<86eddg3j9r.fsf@linuxsc.com>

  copy mid

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

  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: Mon, 12 Feb 2024 23:39:28 -0800
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <86eddg3j9r.fsf@linuxsc.com>
References: <uqehik$1mdue$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="4e2a34a433c81c48b78df2e8e3f8eca2";
logging-data="2106663"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JQhSQ9EAL0VHmJ5DYZbMz5tNrn1w5Ljw="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:DIiaGWHrQO9ttVCr/03E21xXphQ=
sha1:/HdjZcYotsCr+442NdhdxI5g0mQ=
 by: Tim Rentsch - Tue, 13 Feb 2024 07:39 UTC

Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:

> I'm trying to write a client for an existing server (an Asterisk
> "Call Manager" server) that converses in text over a bog-standard
> bi-directional TCP connection. I haven't done much sockets
> programming and need some advice. [...]

I've done a fair amount of simple sockets programming. I wouldn't
call myself an expert but I'm certainly not a novice. I have
several bits of advice to offer.

Use read() and write() on any sockets. Avoid stdio.

Do the appropriate calls to make socket I/O non-blocking. At some
point you may want to get fancy and use select() or something
similar, but starting out it's probably good enough to do the
read()s and write()s in a loop, with a sleep for a hundredth of a
second in the loop so the program doesn't burn up cpu cycles.

Put all the calls to esoteric functions like getaddrinfo() in a
separate .c file, so the main body of code can be compiled with
options -std=c?? -pedantic, and only the one special .c file
needs all the special enabling to get non-standard functions.
(IIRC read() and write() do not need that kind of special
treatment, and can be mixed in with ISO conforming code with
no difficulty.)

Also, a general recommendation to avoid fscanf() altogether
and use sscanf() to do whatever scanning needs doing.

Re: Problems with stdio on TCP (IPV4) sockets

<65cb236b$0$29737$426a74cc@news.free.fr>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed2-a.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>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1
Date: 13 Feb 2024 08:08:11 GMT
Lines: 5
Message-ID: <65cb236b$0$29737$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 13 Feb 2024 09:08:11 CET
NNTP-Posting-Host: 129.199.129.80
X-Trace: 1707811691 news-1.free.fr 29737 129.199.129.80:49410
X-Complaints-To: abuse@proxad.net
 by: Nicolas George - Tue, 13 Feb 2024 08:08 UTC

Lew Pitcher , dans le message <uqehik$1mdue$4@dont-email.me>, a écrit :
> char vrm[16];
> fscanf(fd,"Asterisk Call Manager/%s\r\n",vrm);

And wham the security flaw.

Re: Problems with stdio on TCP (IPV4) sockets

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

  copy mid

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

  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 12:13:23 +0000
Lines: 29
Message-ID: <87h6icmujg.fsf@doppelsaurus.mobileactivedefense.com>
References: <uqehik$1mdue$4@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net SCrkHbh6I5HJa/l3d6XSPQwRXe6Bc0tf4wFHRvIbrNM5ff/mo=
Cancel-Lock: sha1:SCVQgSSLuhjfZmbsGNMBgkCmMG4= sha1:OJGmOtr4lSjeMWfrRHdL/tgLaik= sha256:56TQHB4/4G1EsDSKUOhw8pGbfopg3OD+5iZ4owqHC/Y=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 13 Feb 2024 12:13 UTC

Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> I'm trying to write a client for an existing server (an Asterisk
> "Call Manager" server) that converses in text over a bog-standard
> bi-directional TCP connection. I haven't done much sockets programming
> and need some advice.
>
> I successfully establish my socket connection to the server using
> getaddrinfo() (to build the IPV4 address, socket() (to establish
> an AF_INET,SOCK_STREAM socket) and connect(). The protocol requires
> me to read a text line from the socket before commencing my client
> requests.
>
> For the line read, I decided to try stdio, so I fdopen(,"r") using
> the acquired socket. The next steps are the ones that are currently
> causing me issues.

I did some tests with this with the built-in inetd echo server and the
fscanf, regardless of buffering mode the stream has been set to, simply
does another read immediately after the first which returned the
data. As no more data will be received, this other read just blocks
forever. fgets happens to work because the call returns after a complete
line has been read. But AFAIK, that's not mandated behaviour and a
different implementation may well hang in fgets, too.

The basic problem is that you're doing real-time I/O using an
I/O-facility not intended to operate in real-time. If real-time
operation is desired, which is generally the case for all kinds of
request-response protocol operations, you'll need to use read/write or
send/recv.

Re: Problems with stdio on TCP (IPV4) sockets

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

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!nntp.comgw.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 12:17:15 +0000
Lines: 40
Message-ID: <87cyt0mud0.fsf@doppelsaurus.mobileactivedefense.com>
References: <uqehik$1mdue$4@dont-email.me> <86eddg3j9r.fsf@linuxsc.com>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net DvX3BOoR14dEjRqxeeQuhAXkXRORasqiRG9yROzTbYTbz5ep8=
Cancel-Lock: sha1:ZvRKc4ZdkwfqnVLQGMYV2M5q+/M= sha1:RXQOoZrSVOTYaB0sqaH/WrhiA7o= sha256:l+8lfKwQVj5hSUGSg6UaQNne0OQMttYlM4hnJbvOkQY=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 13 Feb 2024 12:17 UTC

Tim Rentsch <tr.17687@z991.linuxsc.com> writes:
> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>
>> I'm trying to write a client for an existing server (an Asterisk
>> "Call Manager" server) that converses in text over a bog-standard
>> bi-directional TCP connection. I haven't done much sockets
>> programming and need some advice. [...]
>
> I've done a fair amount of simple sockets programming. I wouldn't
> call myself an expert but I'm certainly not a novice. I have
> several bits of advice to offer.
>
> Use read() and write() on any sockets. Avoid stdio.
>
> Do the appropriate calls to make socket I/O non-blocking.

Non-blocking I/O is supposed to be used in situation where a
single-threaded program (or a single thread of a multi-threaded one)
needs to deal with data from multiple sources/ file descriptors. It's
not some kind of magic fairy dust for socket programming.

> At some
> point you may want to get fancy and use select() or something
> similar, but starting out it's probably good enough to do the
> read()s and write()s in a loop, with a sleep for a hundredth of a
> second in the loop so the program doesn't burn up cpu cycles.

BSD terrorcoding at its finest. Never do anything properly, that's way
to much efforts! But hide the deficienies of your code well, they might
find you out otherwise!

If the program doesn't have anything else to do, it should block waiting
for something to do.

> Put all the calls to esoteric functions like getaddrinfo() in a
> separate .c file, so the main body of code can be compiled with
> options -std=c?? -pedantic, and only the one special .c file
> needs all the special enabling to get non-standard functions.

getaddrinfo is a standard function, just not an ISO-C standard function.

Re: Problems with stdio on TCP (IPV4) sockets

<8734twmsn4.fsf@bsb.me.uk>

  copy mid

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

  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: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 12:54:23 +0000
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <8734twmsn4.fsf@bsb.me.uk>
References: <uqehik$1mdue$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain
Injection-Info: dont-email.me; posting-host="7afb96008295e9afd859ffb3bddfc990";
logging-data="2208128"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RFOsldF4SLjm3ndwCv2rL+vGs2uqof0U="
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:IZiMOz/NNR8cd/WdFmazQ07hVxk=
sha1:0gB7mMmHBXoztrRP84POJDL+bBY=
X-BSB-Auth: 1.1bc93af6b21bc3fe92b2.20240213125423GMT.8734twmsn4.fsf@bsb.me.uk
 by: Ben Bacarisse - Tue, 13 Feb 2024 12:54 UTC

Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:

> I'm trying to write a client for an existing server (an Asterisk
> "Call Manager" server) that converses in text over a bog-standard
> bi-directional TCP connection. I haven't done much sockets programming
> and need some advice.
>
> I successfully establish my socket connection to the server using
> getaddrinfo() (to build the IPV4 address, socket() (to establish
> an AF_INET,SOCK_STREAM socket) and connect(). The protocol requires
> me to read a text line from the socket before commencing my client
> requests.
>
> For the line read, I decided to try stdio, so I fdopen(,"r") using
> the acquired socket. The next steps are the ones that are currently
> causing me issues.
>
> 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.
>
> BUT, if I
>
> char buffer[1024], vrm[16];
> fgets(buffer,sizeof buffer,fd);
> sscanf(buffer,"Asterisk Call Manager/%s\r\n",vrm);
>
> I manage to obtain the appropriate data. A dump of the
> buffer array shows that I did indeed capture the introduction line
> from the server.
>
> So, why the difference in behaviour?

You've had some good advice, but no one has answered the question.

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. That's more reading than you want in a
protocol stream.

Though you might be able to fix it (you could read exactly two single
characters and check that they are \r and \n) it's generally better to
read a response and use sscanf if that suits the application

(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.)

> Obviously, in the fscanf() version,
> I've not set something up right. Any hints as to what I've done wrong
> would be greatly appreciated.

--
Ben.

Re: Problems with stdio on TCP (IPV4) sockets

<uqfr3f$23ni8$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 13:33:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <uqfr3f$23ni8$1@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <86eddg3j9r.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 13:33:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hGsSbATADVy2WfjtOysYAmPYb8UhFJS8="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:mTZXS7SSgUSVRmtide7o+kpKjgQ=
 by: Lew Pitcher - Tue, 13 Feb 2024 13:33 UTC

On Mon, 12 Feb 2024 23:39:28 -0800, Tim Rentsch wrote:

> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>
>> I'm trying to write a client for an existing server (an Asterisk
>> "Call Manager" server) that converses in text over a bog-standard
>> bi-directional TCP connection. I haven't done much sockets
>> programming and need some advice. [...]
>
> I've done a fair amount of simple sockets programming. I wouldn't
> call myself an expert but I'm certainly not a novice. I have
> several bits of advice to offer.

[snip very good advice]

Thanks, Tim, for the advice; I'll be sure to take it. It matches with
advice that I've seen from other sources, while I've been researching
this little problem.

The general impression that I've got is that stdio on sockets is...
tricky. (in my uniformed opinion, it /shouldn't/ be tricky; it is
very similar to stdio on a terminal device, in that there's no
lookahead, no unget, and must wait for it's input, just like a
terminal stream. But.... stdio on sockets /is/ tricky.

Looks like I'll have to use other means to access this socket stream.

Thanks again for the advice.
--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqfr9o$23ni8$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 13:36:56 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <uqfr9o$23ni8$2@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me>
<87h6icmujg.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 13:36:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198MTf9eQYu7zF/Rv5ffIytGLJ/sGjZ+88="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:l2Slm8cNOIcWqLDQO7xIBVzLBWc=
 by: Lew Pitcher - Tue, 13 Feb 2024 13:36 UTC

On Tue, 13 Feb 2024 12:13:23 +0000, Rainer Weikusat wrote:

> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>> I'm trying to write a client for an existing server (an Asterisk
>> "Call Manager" server) that converses in text over a bog-standard
>> bi-directional TCP connection. I haven't done much sockets programming
>> and need some advice.
>>
>> I successfully establish my socket connection to the server using
>> getaddrinfo() (to build the IPV4 address, socket() (to establish
>> an AF_INET,SOCK_STREAM socket) and connect(). The protocol requires
>> me to read a text line from the socket before commencing my client
>> requests.
>>
>> For the line read, I decided to try stdio, so I fdopen(,"r") using
>> the acquired socket. The next steps are the ones that are currently
>> causing me issues.
>
> I did some tests with this with the built-in inetd echo server and the
> fscanf, regardless of buffering mode the stream has been set to, simply
> does another read immediately after the first which returned the
> data. As no more data will be received, this other read just blocks
> forever. fgets happens to work because the call returns after a complete
> line has been read. But AFAIK, that's not mandated behaviour and a
> different implementation may well hang in fgets, too.
>
> The basic problem is that you're doing real-time I/O using an
> I/O-facility not intended to operate in real-time. If real-time
> operation is desired, which is generally the case for all kinds of
> request-response protocol operations, you'll need to use read/write or
> send/recv.

Thanks, Rainer

As I suspected, stdio on sockets is tricky, and not the correct interface
to use. But, I had to try :-)

Thanks again for your help
--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqfrg8$23ni8$3@dont-email.me>

  copy mid

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

  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: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 13:40:25 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <uqfrg8$23ni8$3@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <uqf4au$1vsp3$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 13:40:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YhpIIo08GES4Z+FO1xeCLlb+70hbb2rs="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:ffVCkAMeD1r5PJSsQsLO25jGOHk=
 by: Lew Pitcher - Tue, 13 Feb 2024 13:40 UTC

On Tue, 13 Feb 2024 07:05:03 +0000, Lawrence D'Oliveiro wrote:

> On Tue, 13 Feb 2024 01:44:53 -0000 (UTC), Lew Pitcher wrote:
>
>> For the line read, I decided to try stdio ...
>
> Don’t. Your code is probably reading past the end of the response and
> trying to get more.

Thanks, Lawrence

That's what I suspect, as well.

> Also, remember that Asterisk AMI terminates lines with CR/LF.

I know this all too well. But, thanks for the reminder

> Sample Python code, from <https://gitlab.com/ldo/seaskirt/>, that
> decodes responses properly:
[snip python code]

Thanks for that sample; I'll spend some time getting to know it.

Thanks again for your advice and help
--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqfrq0$23ni8$4@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.samoylyk.net!newsfeed.xs3.de!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 13:45:36 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <uqfrq0$23ni8$4@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me>
<uqf0fp$e72n$1@gwaiyur.mb-net.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 13:45:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/sEmA6LbuNPCBIKQ20EvhAjbQXn5wM2X0="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:Gl2DKwjUkfBE2rt45BQVgGM2JUo=
 by: Lew Pitcher - Tue, 13 Feb 2024 13:45 UTC

On Tue, 13 Feb 2024 06:59:21 +0100, Marcel Mueller wrote:

> Am 13.02.24 um 02:44 schrieb Lew Pitcher:
>> For the line read, I decided to try stdio, so I fdopen(,"r") using
>> the acquired socket. The next steps are the ones that are currently
>> causing me issues.
>
> You do not want to use the buffered FILE API for bidirectional sockets
> with message based protocols.
[snip]
> Typically the best is to use an appropriate library for the protocol you
> need.

Thanks, Marcel, for the advice.

However, outside of a couple of out of maintenance, 3rd-party projects from
Asterisk users trying to do the same thing as I am, there's /no/ official
"library for the protocol" available, that I can find.

So, I either adapt one of those 3rd-party projects to my needs, or I roll
my own. And, since I need something to do, and something to learn, I decided
to roll my own protocol. :-)

Thanks again for the advice.
--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqfsae$23ni8$5@dont-email.me>

  copy mid

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

  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: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 13:54:22 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <uqfsae$23ni8$5@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 13:54:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dIesb5YPqtUGvX5dyCDXgj8+hqdRpvqw="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:JuY8dQYKsbh9EBaT/0JS4tk/lDQ=
 by: Lew Pitcher - Tue, 13 Feb 2024 13:54 UTC

On Tue, 13 Feb 2024 12:54:23 +0000, Ben Bacarisse wrote:

> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>
>> I'm trying to write a client for an existing server (an Asterisk
>> "Call Manager" server) that converses in text over a bog-standard
>> bi-directional TCP connection. I haven't done much sockets programming
>> and need some advice.
>>
>> I successfully establish my socket connection to the server using
>> getaddrinfo() (to build the IPV4 address, socket() (to establish
>> an AF_INET,SOCK_STREAM socket) and connect(). The protocol requires
>> me to read a text line from the socket before commencing my client
>> requests.
>>
>> For the line read, I decided to try stdio, so I fdopen(,"r") using
>> the acquired socket. The next steps are the ones that are currently
>> causing me issues.
>>
>> 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.
[snip]
>> So, why the difference in behaviour?
>
> You've had some good advice, but no one has answered the question.
>
> 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. That's more reading than you want in a
> protocol stream.

AHA! That makes sense. Thanks, Ben, for the clarification. I had forgotten
that fscanf() treats \r and \n as whitespace. And, that explains why the
sscanf() doen't fail; it encounters the end-of-string and treats it as
the equivalent of an EOF or non-space character. And so, doesn't hang.

> Though you might be able to fix it (you could read exactly two single
> characters and check that they are \r and \n) it's generally better to
> read a response and use sscanf if that suits the application

Again, that makes sense. A good suggestion.

> (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. So,
for now, I'll stick with blocking I/O and a foreknowledge of what
is (or should be) coming down the wire. To me, at this time,
non-blocking I/O is like adding a regex to the mix ("And, now you
have /two/ problems." :-) )

Thanks for the advice. It certainly explains the differences between
the three trial programs, and gives me something to think about wrt
how I handle this sockets I/O.

--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqfsgu$23ni8$6@dont-email.me>

  copy mid

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

  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: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 13:57:50 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <uqfsgu$23ni8$6@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me>
<65cb236b$0$29737$426a74cc@news.free.fr>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 13:57:50 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Apetq+LX5Dvdbta8ZXB6/wkN08D12KbQ="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:pgZz9bwiAagvfks2/SYNQ2Fwb0U=
 by: Lew Pitcher - Tue, 13 Feb 2024 13:57 UTC

On Tue, 13 Feb 2024 08:08:11 +0000, Nicolas George wrote:

> Lew Pitcher , dans le message <uqehik$1mdue$4@dont-email.me>, a écrit :
>> char vrm[16];
>> fscanf(fd,"Asterisk Call Manager/%s\r\n",vrm);
>
> And wham the security flaw.

I suspect that you mean "buffer overflow" flaw.

Yes, in the wild, it would be.

But, this is an experiment (acknowledged as an experiment) under
laboratory conditions, where I /know/that the buffer is big enough
for the data (the string extracted will, in this case, /always/ be
"7.0.0", 6 octets, including the end-of-string character).

I will, however, fix this if and when my experiment grows into
something more useful.

Thanks for the catch.
--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqftvt$23ni8$7@dont-email.me>

  copy mid

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

  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: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 14:22:53 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <uqftvt$23ni8$7@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqfsae$23ni8$5@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 14:22:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+SWrNpby+qURfp+bY+3Nv6o1TU43s7ilo="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:5VMreQrNirpQTb/xz6oloDu+bV4=
 by: Lew Pitcher - Tue, 13 Feb 2024 14:22 UTC

On Tue, 13 Feb 2024 13:54:22 +0000, Lew Pitcher wrote:

> On Tue, 13 Feb 2024 12:54:23 +0000, Ben Bacarisse wrote:
>
>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>>
>>> I'm trying to write a client for an existing server (an Asterisk
>>> "Call Manager" server) that converses in text over a bog-standard
>>> bi-directional TCP connection. I haven't done much sockets programming
>>> and need some advice.
>>>
>>> I successfully establish my socket connection to the server using
>>> getaddrinfo() (to build the IPV4 address, socket() (to establish
>>> an AF_INET,SOCK_STREAM socket) and connect(). The protocol requires
>>> me to read a text line from the socket before commencing my client
>>> requests.
>>>
>>> For the line read, I decided to try stdio, so I fdopen(,"r") using
>>> the acquired socket. The next steps are the ones that are currently
>>> causing me issues.
>>>
>>> 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.
> [snip]
>>> So, why the difference in behaviour?
>>
>> You've had some good advice, but no one has answered the question.
>>
>> 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. That's more reading than you want in a
>> protocol stream.
>
> AHA! That makes sense. Thanks, Ben, for the clarification. I had forgotten
> that fscanf() treats \r and \n as whitespace. And, that explains why the
> sscanf() doen't fail; it encounters the end-of-string and treats it as
> the equivalent of an EOF or non-space character. And so, doesn't hang.

And BINGO, when I change the line from
fscanf(amiIn,"Asterisk Call Manager/%s\r\n",vrm)
to
fscanf(amiIn,"Asterisk Call Manager/%s",vrm)
I get the expected results, and confirm Ben's observation.

Thanks again, Ben
That solved my puzzle.

And, now on to reworking my design, based on the advice I've seen here.

Thanks, all, for the help.
--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

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

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.chmurka.net!weretis.net!feeder8.news.weretis.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 15:44:00 +0000
Lines: 50
Message-ID: <87eddgs727.fsf@doppelsaurus.mobileactivedefense.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 6VsSgYivUFciXq5kc2qchwOqM8GYux6SUtBk8sFFdKLWX8VIs=
Cancel-Lock: sha1:WyrVsP9fXS0jtpoJluM2LNEqGyM= sha1:519Ys35Av4j0BvCkAZss7X0PUq0= sha256:C25Bnr3Dp2+AQcGh2itI3TmNnv9voJsiy2ZNXeXMuRI=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 13 Feb 2024 15:44 UTC

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.
`----

OTOH, the stream may be fully buffered or line buffered (unspecified)
and - AFAICT - no specific behaviour is manadated for input from either
a fully buffered or a line buffered stream. Eg, the implementation is
free to do readahead to whatever degree someone considers useful. Even
for an unbuffered stream, it's just said that

,----
| bytes are intended to appear from the source or at the destination as
| soon as possible;
`----

which means setting a stream to unbuffered is basically a hint to the
implementation: If that's deemed possible, please send the data now or, for
input, return as soon as enough the call can complete successfully and
the implementation is totally free to take a Kinderwille ist Dreck!¹
stance on that.

¹ German for "Children may wish for anything. Doesn't mean they'll get
it!"

Re: Problems with stdio on TCP (IPV4) sockets

<875xyspcmm.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.bbs.nz!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 16:12:01 +0000
Lines: 29
Message-ID: <875xyspcmm.fsf@doppelsaurus.mobileactivedefense.com>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
<uqfsae$23ni8$5@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net B+aqpe7E5tE1dX/N0dGyzQmG1dA/jhi/M5NaBON/n1i2hdFss=
Cancel-Lock: sha1:98Qgb77ss3/HcGhXSPibY+TJkI8= sha1:kzNVfsrJj/1EiQCXZv93nAYge4Y= sha256:6PxJc6L59tNXfYX2ve0CuSi9lYFbPXi8VNzBcKrczuM=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 13 Feb 2024 16:12 UTC

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

[...]

>> (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.

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. Hence, it'll set all to non-blocking and then blocks
select/ poll/ epoll etc so that it gets notified when input is available
on any of them.

A somewhat simpler use case is I/O on only one file descriptor but with
a need to impose timeouts to cope with unreliable communication
partners, although there are other options available for this (like
alarm signals or socket read timeouts).

¹ Principally also to avoid blocking for buffer space to become
available to complete an output operations but that's a rare case.

Re: Problems with stdio on TCP (IPV4) sockets

<65cb9511$0$7525$426a74cc@news.free.fr>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!nntp-feed.chiark.greenend.org.uk!ewrotcd!nntp.terraraq.uk!news.gegeweb.eu!gegeweb.org!usenet-fr.net!proxad.net!feeder1-2.proxad.net!cleanfeed3-b.proxad.net!nnrp6-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>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1
Date: 13 Feb 2024 16:13:05 GMT
Lines: 5
Message-ID: <65cb9511$0$7525$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 13 Feb 2024 17:13:05 CET
NNTP-Posting-Host: 129.199.129.80
X-Trace: 1707840785 news-1.free.fr 7525 129.199.129.80:60768
X-Complaints-To: abuse@proxad.net
 by: Nicolas George - Tue, 13 Feb 2024 16:13 UTC

Lew Pitcher , dans le message <uqfsgu$23ni8$6@dont-email.me>, a écrit :
> But, this is an experiment (acknowledged as an experiment) under
> laboratory conditions

You posted it on Usenet.

Re: Problems with stdio on TCP (IPV4) sockets

<uqg4rk$23ni8$9@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 16:20:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <uqg4rk$23ni8$9@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 16:20:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H4bP1/BVwZb6HD5SYtavH5RpNMh4JkBo="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:UKIqeJ07RA4T6yFyaUvAScxln5Y=
 by: Lew Pitcher - Tue, 13 Feb 2024 16:20 UTC

On Tue, 13 Feb 2024 16:12:01 +0000, Rainer Weikusat wrote:

> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>> On Tue, 13 Feb 2024 12:54:23 +0000, Ben Bacarisse wrote:
>>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>
> [...]
>
>>> (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.
>
> 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.
[snip]
> A somewhat simpler use case is I/O on only one file descriptor but with
> a need to impose timeouts to cope with unreliable communication
> partners
[snip]

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.

--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

<uqg4tl$23ni8$10@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 16:21:09 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uqg4tl$23ni8$10@dont-email.me>
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 16:21:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hDa93eHsGAok15rrpD6eeLAvReBY1PW4="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:Smc1vnV6Pl+mwHZ+Ds0LbcnuZuM=
 by: Lew Pitcher - Tue, 13 Feb 2024 16:21 UTC

On Tue, 13 Feb 2024 16:13:05 +0000, Nicolas George wrote:

> Lew Pitcher , dans le message <uqfsgu$23ni8$6@dont-email.me>, a écrit :
>> But, this is an experiment (acknowledged as an experiment) under
>> laboratory conditions
>
> You posted it on Usenet.

Indeed, I did. And your point is?

--
Lew Pitcher
"In Skills We Trust"

Re: Problems with stdio on TCP (IPV4) sockets

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

  copy mid

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

  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 16:40:45 +0000
Lines: 43
Message-ID: <871q9gpbaq.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>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
X-Trace: individual.net 0PWY9XFdqynDXuxq/TwtYwq3ZIgnrlt5n96n+DbAl8C6hhoeU=
Cancel-Lock: sha1:CbapcJjV6f3MBc+5rNXqhBOCSXg= sha1:j5qi8JKPM5Qnb1Z2hrDkWrYSOjM= sha256:Gm7824mSJ3DXxPph0gGGLxgUYj08nUgNRkCKxx1lbos=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Tue, 13 Feb 2024 16:40 UTC

Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
> On Tue, 13 Feb 2024 16:12:01 +0000, Rainer Weikusat wrote:
>
>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>>> On Tue, 13 Feb 2024 12:54:23 +0000, Ben Bacarisse wrote:
>>>> Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
>>
>> [...]
>>
>>>> (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.
>>
>> 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.
> [snip]
>> A somewhat simpler use case is I/O on only one file descriptor but with
>> a need to impose timeouts to cope with unreliable communication
>> partners
> [snip]
>
> 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.

If you don't want to implement I/O timeouts, non-blocking I/O is uselees
for your case. I think it's often just being (mis-)used because it exists and
the idea of a program which just waits until woken up by the kernel
instead of Doing Someting[tm] make many people nervous.

Re: Problems with stdio on TCP (IPV4) sockets

<uqgjgg$288d0$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.niel.me!news.gegeweb.eu!gegeweb.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 20:30:08 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <uqgjgg$288d0$1@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <8734twmsn4.fsf@bsb.me.uk>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 20:30:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="24b9a84a64cf4b4b69a117a024a5ec4b";
logging-data="2367904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193TqN+GvQ1sjAVSgdi0PLK"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:mBERpKrYgnCCRT79eCjioTnoGEA=
 by: Lawrence D'Oliv - Tue, 13 Feb 2024 20:30 UTC

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. It leads to fewer race conditions than threads, and works well
where the bottleneck is network I/O (or, in a GUI app, the user
interaction), rather than the CPU.

Re: Problems with stdio on TCP (IPV4) sockets

<uqgjra$288d0$2@dont-email.me>

  copy mid

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

  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 20:35:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <uqgjra$288d0$2@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me> <uqf0fp$e72n$1@gwaiyur.mb-net.net>
<uqfrq0$23ni8$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 20:35:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="24b9a84a64cf4b4b69a117a024a5ec4b";
logging-data="2367904"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/POJsSY8uO45N4blzlzCnY"
User-Agent: Pan/0.155 (Kherson; fc5a80b8)
Cancel-Lock: sha1:nN0G2VGwQETnqOxaeVzKEezAXaE=
 by: Lawrence D'Oliv - Tue, 13 Feb 2024 20:35 UTC

On Tue, 13 Feb 2024 13:45:36 -0000 (UTC), Lew Pitcher wrote:

> However, outside of a couple of out of maintenance, 3rd-party projects
> from Asterisk users trying to do the same thing as I am, there's /no/
> official "library for the protocol" available, that I can find.

My Python library, Seaskirt (link posted elsewhere) is the only one I know
of that covers AMI, AGI, Async-AGI, ARI and even the console interface. It
offers both synchronous and asynchronous (async/await) versions of all the
main API classes, and even allows for SSL/TLS connections where Asterisk
will accept these.

Re: Problems with stdio on TCP (IPV4) sockets

<uqgk3l$23ni8$14@dont-email.me>

  copy mid

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

  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: lew.pitc...@digitalfreehold.ca (Lew Pitcher)
Newsgroups: comp.unix.programmer
Subject: Re: Problems with stdio on TCP (IPV4) sockets
Date: Tue, 13 Feb 2024 20:40:21 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <uqgk3l$23ni8$14@dont-email.me>
References: <uqehik$1mdue$4@dont-email.me>
<uqf0fp$e72n$1@gwaiyur.mb-net.net> <uqfrq0$23ni8$4@dont-email.me>
<uqgjra$288d0$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 13 Feb 2024 20:40:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="aa13a1720caaa2205b64b7adad483cd2";
logging-data="2219592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX191B2s5jTHdYr91GSjc3jDS4SMvS2nQK+Q="
User-Agent: Pan/0.139 (Sexual Chocolate; GIT bf56508
git://git.gnome.org/pan2)
Cancel-Lock: sha1:239qJIjRrcCs1q3+Y27HFJBtqf8=
 by: Lew Pitcher - Tue, 13 Feb 2024 20:40 UTC

On Tue, 13 Feb 2024 20:35:54 +0000, Lawrence D'Oliveiro wrote:

> On Tue, 13 Feb 2024 13:45:36 -0000 (UTC), Lew Pitcher wrote:
>
>> However, outside of a couple of out of maintenance, 3rd-party projects
>> from Asterisk users trying to do the same thing as I am, there's /no/
>> official "library for the protocol" available, that I can find.
>
> My Python library, Seaskirt (link posted elsewhere) is the only one I know
> of that covers AMI, AGI, Async-AGI, ARI and even the console interface. It
> offers both synchronous and asynchronous (async/await) versions of all the
> main API classes, and even allows for SSL/TLS connections where Asterisk
> will accept these.

I will check it out. Thanks

--
Lew Pitcher
"In Skills We Trust"

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor