2

The Computer Algebra System Maxima uses (open-socket) in order to connect to its frontend (wxMaxima or xMaxima). Afterwards it makes sure that all output is actually passed to the frontend:

(setq *standard-input* sock)
(setq *standard-output* sock)
(setq *error-output* sock)
(setq *terminal-io* sock)
(setq *trace-output* sock)
(format t "pid=~a~%" (getpid))
(force-output sock)
(setq *debug-io* sock))

This works fine (with the exceptions that out-of-memory conditions still might be signalled over stdout and that windows sometimes on out-of-memory doesn't want to send "connection lost" messages to the application maxima is connected to, but it is easy to work around this. Unfortunately if the network connection is lost this causes an error message - that (since the error output is bound to the network) causes an error message that causes...

Is there any way to catch a connection loss before this results in an endless loop?

Sorry to ask such a seemingly basic question. But I didn't find a solution for months now and I assume I need the help of an expert.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346
  • For anybody interested, the code is here: https://github.com/andrejv/maxima/blob/a7fedfafb146c1f33c42bdd71f421d559a8ca0be/archive/src/server.lisp#L11. I don't think there is such a callback. If I understand your problem correctly, what I would do is try to wrap the socket inside a custom stream object which would handle connection errors and provide maybe a fallback stream. – coredump Jun 23 '16 at 20:11
  • 1
    Leaving aside Lisp implementation, you need to understand that there is no such event *in TCP*. Unless you are actually engaged in a network operation: a read, a write, or a multiplexed select, there is no way for TCP to tell Lisp that the connection has dropped. – user207421 Jun 23 '16 at 23:03

1 Answers1

1

How a Common Lisp implementation deals with network errors is implementation specific.

Usually an error condition is signalled.

Thus you need to provide a condition handler, which is active while such a problem might appear. You would need to learn about the Common Lisp condition system and how to handle conditions. How this works with streams, sockets, network connections is very implementation specific.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346