[Snek] [PATCH v2] snekserver: allow network connections to a snigle Snek instance

Keith Packard keithp at keithp.com
Sun Apr 12 12:30:00 PDT 2020


Mikhail Gusarov <dottedmag at dottedmag.net> writes:

> This functionality ought to be implemented in inetd, systemd or socat, but none
> of them provide "replace old client with new one" option.

This looks like a good solution, and may be useful in other environments
where snek is running on Linux in an embedded environment. If that
happens, we can move snekserver out of the EV3 directory so it can be
shared.

I think you'll want to add SIGINT handling in snek-main.c to set
snek-abort, and then have snekserver send SIGINT when it passes ^C to
the client.

I wonder if that will require adding buffering so that when snek isn't
reading, snekserver will still be able to see the ^C from the user?

> +		close_noeintr(0);
> +		dup2_noeintr(stdin_fd[0], 0);

You don't really need to call close here -- dup2 automatically does
that.

> +		if (fds[FD_STDOUT].revents & POLLIN) {
> +			char c;
> +			if (read_noeintr(subproc_stdout, &c, 1) == 1) {
> +				if (connected_socket != -1) {
> +					stdout_buf = c;
> +				}
> +				// else discard, a-la serial port
> +			}
> +			// read errors will be handled on the next poll() iteration
> +			continue;
> +		}

This seems a bit unusual to me; I'd expect no error on this FD when the
client exits, the only FD I'd expect to see an error on is the stdin
socket when we attempt to write. I'd suggest putting the shutdown code
into a separate function and calling that when you get an EOF indication
on any FD connected to snek. Alternatively, you could simply close the
sockets you received EOF on; that would reliably generate an error from
poll.

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <http://keithp.com/pipermail/snek/attachments/20200412/0ba0cb97/attachment.sig>


More information about the Snek mailing list