oldk1331 wrote:
>
> There is a bug to prevent you from quitting FriCAS when you
> issue 'CTRL-D' in the REPL.
>
> This is caused by "fgets" in "remote_stdio" in src/lib/sockio-c.c,
> used in binary "spadclient".
Actually the main problem is wrong architecture of interaction
with Hyperdoc. Namely all input and output from AXIOMsys
should go trough FriCAS functions. ATM part of I/O is
trough FriCAS functions, part is done by Lisp. This leads
to race conditions and bugs. I have written about this
few times in the past.
> I replaced it with "read", and try to exit when CTRL-D (EOF)
> is encountered. I'm not sure if my way to quit FriCAS is proper:
>
> swrite(sock, ")quit", 5, "quit");
>
EOF may appear in the middle of some date, so sending ")quit"
is not the correct way. Actually, with other bugs fixed
we propbably could remove 'remote_stdio'. And if you ask:
'sockio-c.c' is buggy, it should correctly handle long
pieces of data (ATM it would crash or loose data).
Simplest way of fixing bugs in 'sockio-c.c' is to change
communication protocol between Hyperdoc/graphics and
AXIOMsys. But that requires fixing architectural problems
first.
> I'm no C expert, so comments are welcomed.
>
> diff --git a/src/lib/sockio-c.c b/src/lib/sockio-c.c
> index 57163eb9..9a56719e 100644
> --- a/src/lib/sockio-c.c
> +++ b/src/lib/sockio-c.c
> @@ -805,14 +805,15 @@ remote_stdio(Sock *sock)
> return;
> }
> if (FD_ISSET(0, &rd)) {
> - fgets(buf,1024,stdin);
> - len = strlen(buf);
> - /*
> - gets(buf);
> - len = strlen(buf);
> - *(buf+len) = '\n';
> - *(buf+len+1) = '\0';
> - */
> + len = read(0, buf, 1024);
> + if (len == -1) {
> + perror("read from stdin");
> + return;
> + }
> + if (len == 0) {
> + /* EOF (CTRL-D) received, exit program */
> + swrite(sock, ")quit", 5, "quitting");
> + }
> swrite(sock, buf, len, "writing to remote stdin");
> }
> if (FD_ISSET(sock->socket, &rd)) {
>
> --
> You received this message because you are subscribed to the Google Groups
> "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at https://groups.google.com/group/fricas-devel.
> For more options, visit https://groups.google.com/d/optout.
>
--
Waldek Hebisch
--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/fricas-devel.
For more options, visit https://groups.google.com/d/optout.