BSD Sockets like API: prototyping report #1
Paul Sokolovsky
Hello,
I appreciate wide feedback the RFC for BSD Sockets (like) API received. There were different kinds of suggestions/issues raised, some affecting general course of implementation, some which will be pertinent for later stage when refactoring a prototype into something suitable for mainline. Here I'd like to progress made so far, as well as questions of immediate importance for next steps of elaborating the prototype, any feedback on them is welcome (and I'm going to open separate discussions on them a bit later if needed). What's done: 1. A MicroPython "usockets" (microsockets, to differentiate it from standard Python's "socket" module which is somewhat bloated) with initial implementation of functions: socket(), close(), bind(), connect(), send(), recv() - effectively a client-side API, for both UDP and TCP, (also IPv4 and IPv6, thought I didn't yet test IPv6). All this seem to work reasonably well (for something which of a age of few days), so I merged it to master to get the wider coverage and the benefit of CI testing done on it. Here's a transcript, an interactive MicroPython session running in qemu_x86 and making an HTTP request to Apache on my host machine: MicroPython v1.8.7-560-g4c392243a on 2017-04-03; zephyr-qemu_x86 with ia32 Type "help()" for more information. paste mode; Ctrl-C to cancel, Ctrl-D to finish === import socket === s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) === s.connect(("192.0.2.2", 80)) # Non-existent URL is used on purpose, to get shorter reply === s.send(b"GET /foo HTTP/1.0\r\n\r\n") === s.recv(1000) === 21 b'HTTP/1.1 404 Not Found\r\nDate: Mon, 03 Apr 2017 15:26:50 GMT\r\nServer: Apach' b'e/2.4.7 (Ubuntu)\r\nContent-Length: 275\r\nConnection: close\r\nContent-Type: text/html; charset=iso-8859-1\r\n\r\n<!DOCTYPE HTML PUBLIC "'s.recv(1000) b'-//IETF//DTD HTML 2.0//EN">\n<html><head>\n<title>404 Not Found</title>\n</head><body>\n<h1>Not Found</h1>\n<p>The requested URL /foo's.recv(1000) b' was not found on this server.</p>\n<hr>\n<address>Apache/2.4.7 (Ubuntu) Server at 127.0.1.1 Port 80</address>\n</body></html>\n's.recv(1000) # EOFs.recv(1000) b'' # always EOFs.recv(1000) b'' Traceback (most recent call last):s.close() File "<stdin>", in <module> OSError: [Errno 9] EBADF As you can see, the implementation enjoys short read possibility offered by POSIX (that calls like recv(), read() may return less data than requested): maximum one data fragment is returned (which is freed at once to allow to receive more data from network). As this message is already long, let me send the list of issues in the next one. -- Best Regards, Paul Linaro.org | Open source software for ARM SoCs Follow Linaro: http://www.facebook.com/pages/Linaro http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog
|
|