-
Notifications
You must be signed in to change notification settings - Fork 218
esp32/modsocket.c: fix error handling on addrinfo for #31 #35
esp32/modsocket.c: fix error handling on addrinfo for #31 #35
Conversation
|
Running CPython with |
|
Yeah, I think there's a bunch of special rules around parsing addresses which may be dotted quads or their decimal equivalents: you can see this elsewhere in unix: I've only allowed for |
|
Closing this: the important bit of the change was done in 1365f7f |
The unix port needs quite a bit of fixing up around |
|
As noted above, the standard BSD stuff has some specific behaviours
around not-quite-dotted-quads and getaddrinfo (see `man inet_aton`)
which made sense on the early internet.
We *could* replicate that exact behaviour and pull , but I have seen
addresses like `127.66051` used exactly never.
|
|
I was more referring to this: CPython, and µPy ESP32>>> socket.getaddrinfo('0.0.0.0', 80)
[(2, 1, 6, '', ('0.0.0.0', 80)), (2, 2, 17, '', ('0.0.0.0', 80)), (2, 3, 0, '', ('0.0.0.0', 80))]µPy Unixsocket.getaddrinfo('0.0.0.0', 80)
[(2, 1, 6, None, bytearray(b'\x02\x00\x00P\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')), (2, 2, 17, None, bytearray(b'\x02\x00\x00P\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00')), (2, 3, 0, None, bytearray(b'\x02\x00\x00P\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'))]I know there was a recent discussion around why this is, but I don't think having a single µPy port that behaves very differently (from other µPy ports, and even CPython) for |
|
Oh, right, I hadn't seen that one. Thanks for clarifying.
I'd agree, the Unix port should come into line with the other
MicroPython ports, so it is useful for testing libraries etc.
Also, the ports should be as close to CPython 3 as practical.
|
|
For the case of getaddrinfo: the returned values (or at least the 5th entry in the tuple) is considered an opaque address. It can be passed to socket methods to specify an address but otherwise should be considered port/system dependent. Taking that point of view, the ports are all consistent including consistency with CPython. @MrSurly what kind of compatible code is hard to write in this sense? |
|
[Long rant about code compatibility ahead] Short Version: I should be able to copy-paste µPy code between ports, with a reasonable assurance that it will just work. CPython3 socket examples should just work. Long Version: I've been doing a lot of prototyping of socket code lately, and I would expect that doing so would be easier on the Unix port before moving it to the target device. So I compiled the Unix port, aimed it at my code that worked on the ESP32 and ... it didn't work. However, It did work in CPython3. I don't think it's too much to assume that µPy ESP32 code should be 100% compatible (barring HW specifics) with µPy Unix.
In the sense you've defined here, it's not hard, but there is a preponderance of "prior art" that doesn't fit that definition: Internet examples in generalThere is a ton a example code (particularly server code) out there with idioms such as:
The official Python 3 example codeThese examples are directly from the Python 3 Socket Programming HOWTO: # create an INET, STREAMing socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# now connect to the web server on port 80 - the normal http port
s.connect(("www.python.org", 80))# create an INET, STREAMing socket
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# bind the socket to a public host, and a well-known port
serversocket.bind((socket.gethostname(), 80))
# become a server socket
serversocket.listen(5)This is, frankly, super useful, and arguably Pythonic. The Python 3 documenation for
|
|
@MrSurly : You seem to be missing a lot what MicroPython is, even though it's documented and shown to every contributor on first (and every) contribution: https://github.com/micropython/micropython/wiki/ContributorGuidelines . MicroPython is not CPython, nor there's even an aim to be one. Need CPython? Use CPython. All the other misunderestandings stem from not understanding that. There're separate APIs for MicroPython, representing minimal'ish subset of CPython APIs, living in separate modules (starting with "u"). Whoever wants to go beyond that, writes a CPython compatible module. The unix port is the reference port of MicroPython, showing how to do it right. However, other ports add more things to themselves, initially thought to be "conveniences", but has long became "misconveniences", as they confuse people who aren't prepared to read the documentation. These include things like any function beyond core MicroPython API, symbolic addresses accepted by socket functions beyond getaddrinfo(), module symlinks, etc. All these lead for careless newcomers to see the upside down picture of MicroPython world - that it's there to replace CPython for them or that Unix port lacks something. No, other ports have superfluous features. Don't like inconsistency? Feel free to start thinking about removing them. The same applies to features in general - the more you add, the harder you do it on yourself ("aimed it at my code that worked on the ESP32 and ... it didn't work."). Worse, you do it harder on the users. That's why adhoc port features are frowned upon in the mainline. |
Fix for #31 ... check return code of lwip_getaddrinfo and throw exceptions when appropriate.