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

Keith Packard keithp at keithp.com
Sat Apr 18 10:52:52 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.

Very cool. I'm thinking of doing a 1.4 release when you're happy with
the EV3 bits. I was hoping to test on an EV3 myself, but I haven't been
able to find one locally.

> +	struct sigaction act = {
> +		.sa_handler = on_sigint,
> +		.sa_flags = SA_RESTART,

Hrm. I *think* you don't want SA_RESTART here. With this, a ^C sent
while snek is waiting for I/O in the kernel will not interrupt the
syscall, and so snek will keep waiting forever. You should be able to
test this by sending ^C while snek is paused at the command prompt. That
should cause snek wake up and reset stuff.

I'll code up something similar for the regular posix version to compare.

> +static int
> +poll_noeintr(struct pollfd fds[], nfds_t nfds, int timeout)
> +{
> +	for (;;) {
> +		int ret = poll(fds, nfds, timeout);
> +		if (ret == -1 && (errno == EINTR || errno == EAGAIN))
> +			continue;

And here's where you'd want to test for snek_abort. Good catch including
EAGAIN in this list; the poll man page says that is correct! I'd check
*before* calling poll so that you don't block if it was already
set. That does leave a timing window open, but it's pretty small and
fixing it is a pain -- I usually do that by creating another pipe and
having the signal handler write a byte to that to ensure the poll wakes
up...

> +static int
> +recv_noeintr(int socket, void *buffer, size_t length, int flags)
> +{
> +	for (;;) {
> +		int ret = recv(socket, buffer, length, flags);
> +		if (ret == -1 && (errno == EINTR || errno == EAGAIN))
> +			continue;

This one shouldn't include EAGAIN as that only happens on non-blocking
sockets if there isn't any data to receive. You could also check for
snek_abort here if you like, but as you're not calling this until
there is data present, that's a pretty small race.

-- 
-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/20200418/a9d5fed0/attachment-0001.sig>


More information about the Snek mailing list