libzt icon indicating copy to clipboard operation
libzt copied to clipboard

Python non-blocking recv exception.

Open linsomniac opened this issue 4 years ago • 2 comments

I'm trying to poll the ZT socket by using nonblocking recv (either setblocking, or the flag to recv), but the recv() is throwing an exception and I can't catch it. The syscall recv() will fail with errno=11 (EAGAIN) in the case of a non-blocking I/O but no data ready to read. I presume lwip_recv() behaves similarly.

In libzt Python wrappers, I get: Exception("ZTS_ERR_SOCKET (-1)") with libzt.errno()=11 (EAGAIN). To catch this you need to catch Exception and then check the string in args:

if ex.args[0] == 'ZTS_ERR_SOCKET (-1)' and libzt.errno() == libzt.ZTS_EAGAIN:

I'd like to propose that we behave similarly to the Python socket module, which raises: "BlockingIOError: [errno=11] Resource temporarily unavailable"

As you can probably tell, I'm a bit of a fan of having libzt match the Python socket semantics. I'm open to other alternatives though, so please provide feedback.

linsomniac avatar Mar 20 '21 03:03 linsomniac

Took me a while to get to this but I agree. Hopefully this: 81d03c3692af183e7619dba5d961dba9078fbdef + e7eaeadaeeee31b30ae4d8e9d0377d839366f392 helps. This change is included in the latest release.

joseph-henry avatar May 20 '21 05:05 joseph-henry

I'll try to get some time tonight to play around with the current version and see if I can get my head back in the game here. Thanks!

linsomniac avatar May 20 '21 15:05 linsomniac