Commit Graph

37 Commits

Author SHA1 Message Date
Paul Sokolovsky
5c1af60e19 extmod/modlwip: More debug messages for various edge conditions. 2016-04-15 00:37:12 +03:00
Paul Sokolovsky
44ab5c3ef1 extmod/modlwip: Start adding debug output. 2016-04-14 01:15:52 +03:00
Paul Sokolovsky
fef0d9818a extmod/modlwip: lwip_tcp_receive(): Properly handle EOF for non-blocking sock. 2016-04-14 00:59:09 +03:00
Paul Sokolovsky
7063210014 extmod/modlwip: Fix for loss of data in unaccepted incoming sockets.
When lwIP creates a incoming connection socket of a listen socket, it
sets its recv callback to one which discards incoming data. We set
proper callback only in accept() call, when we allocate Python-level
socket where we can queue incoming data. So, in lwIP accept callback
be sure to set recv callback to one which tells lwIP to not discard
incoming data.
2016-04-11 01:21:34 +03:00
Paul Sokolovsky
91031a75a1 extmod/modlwip: lwip_socket_setsockopt: Handle option value properly. 2016-03-25 20:53:52 +02:00
Paul Sokolovsky
4332d72fd8 extmod/modlwip: Add lwip->POSIX error map for lwIP 1.4.0.
Between 1.4.0 and 1.4.1, lwIP errors were renumbered.
2016-03-25 20:32:01 +02:00
Paul Sokolovsky
de0c84ebf1 extmod/modlwip: lwip_tcp_send: Handle properly send buffer full condition.
Per POSIX http://pubs.opengroup.org/onlinepubs/9699919799/functions/send.html :
"If space is not available at the sending socket to hold the message to be
transmitted, and the socket file descriptor does not have O_NONBLOCK set,
send() shall block until space is available. If space is not available at the
sending socket to hold the message to be transmitted, and the socket file
descriptor does have O_NONBLOCK set, send() shall fail [with EAGAIN]."
2016-03-25 18:38:13 +02:00
Paul Sokolovsky
5e75f335e6 extmod/modlwip: Implement setsocketopt(SO_REUSEADDR). 2016-03-25 17:44:24 +02:00
Paul Sokolovsky
8f1854ad2d extmod/modlwip: Add SOL_SOCKET and SO_REUSEADDR constants for setsockopt(). 2016-03-25 15:06:12 +02:00
Paul Sokolovsky
0779409d0d extmod/modlwip: lwip_tcp_receive: Properly map lwIP error to POSIX errno. 2016-03-12 11:42:15 +07:00
Paul Sokolovsky
ba8f7d5171 extmod/modlwip: Add socket.setblocking() method. 2016-03-12 10:52:50 +07:00
Paul Sokolovsky
09ed5bcbbb extmod/modlwip: Rework getaddrinfo() data passing.
The code is based on Damien George's implementation for esp8266 port,
avoids use of global variables and associated re-entrancy issues, and
fixes returning stale data in some cases.
2016-03-12 10:50:51 +07:00
Paul Sokolovsky
e5b047369b extmod/modlwip: Use MICROPY_EVENT_POLL_HOOK for event polling if defined.
Instead of just delaying 100ms if event isn't yet ready.

So far applies only to default, "infinite" socket timeout.
2016-03-11 09:32:07 +07:00
Paul Sokolovsky
43d497592f extmod/modlwip: Factor out "socket connected" check to a function.
Same code repeated for each send*() and recv*() function.
2016-03-09 12:43:09 +07:00
Paul Sokolovsky
fda874e406 extmod/modlwip: Support non-blocking recv(). 2016-03-09 12:39:33 +07:00
Paul Sokolovsky
7379be3673 extmod/modlwip: Add .write() stream method. 2016-03-09 12:35:43 +07:00
Damien George
4f64f6bfd3 extmod/modlwip: Still process remaining incoming data of a closed socket.
It can happen that a socket gets closed while the pbuf is not completely
drained by the application.  It can also happen that a new pbuf comes in
via the recv callback, and then a "peer closed" event comes via the same
callback (pbuf=NULL) before the previous event has been handled.  In both
cases the socket is closed but there is remaining data.  This patch makes
sure such data is passed to the application.
2016-03-09 12:31:25 +07:00
Damien George
6d2e9e70b3 extmod/modlwip: Check for state change during recv busy-wait loop.
For example, the peer may close the connection while recv is waiting for
incoming data.
2016-03-09 12:29:40 +07:00
Paul Sokolovsky
6185dc5f3d extmod/modlwip: Add stream .read() and .readline() methods. 2016-03-09 09:20:22 +07:00
Paul Sokolovsky
f1919b7c98 extmod/modlwip: Add dummy .makefile() method. 2016-03-09 09:14:45 +07:00
Paul Sokolovsky
c7fb87caff extmod/modlwip: Add stream protocol read method. 2016-03-09 09:12:32 +07:00
Paul Sokolovsky
ed593780bf extmod/modlwip: Implement dummy setsockopt(). 2016-03-08 14:24:49 +07:00
Paul Sokolovsky
f8d42da104 extmod/modlwip: Add .print() method. 2016-03-08 11:37:15 +07:00
Paul Sokolovsky
04a9ac7f38 extmod/modlwip: Update make_new() arguments for recent refactor. 2016-03-08 10:31:21 +07:00
Paul Sokolovsky
fb7b715b7b extmod/modlwip: Use _ERR_BADF instead of magic number. 2015-12-30 16:43:35 +02:00
Paul Sokolovsky
bc25545fbb extmod/modlwip: Avoid magic numeric values in memcpy(). 2015-12-30 16:40:23 +02:00
Paul Sokolovsky
722fb2d251 extmod/modlwip: User proper field name and value names for socket state. 2015-12-30 16:26:23 +02:00
Paul Sokolovsky
fff2dd2627 extmod/modlwip: Mark some lwip_socket_obj_t's fields as volatile.
Any fields changed by asynchronous callbacks must be volatile.
2015-12-29 21:02:02 +02:00
Paul Sokolovsky
a63d4a6cc2 extmod/modlwip: tcp_recv: Use more regular and responsive poll pattern.
Polling once in 100ms means dismal performance.

TODO: Propagate this pattern to other polling places.
2015-12-29 20:37:22 +02:00
Galen Hazelwood
af3e45419c extmod/lwip: Change void pointers to unions, include new mphal.h file 2015-11-04 23:24:04 +03:00
Paul Sokolovsky
4deb4936d5 extmod/modlwip: socket->incoming changed by async callbacks, must be volatile.
Otherwise for code like:

while (socket->incoming == NULL) {
    LWIP_DELAY(100);
}

a compiler may cache it in a register and it will be an infinite loop.
2015-10-31 19:51:23 +03:00
Paul Sokolovsky
404dae80a9 unix, stmhal: Introduce mp_hal_delay_ms(), mp_hal_ticks_ms().
These MPHAL functions are intended to replace previously used HAL_Delay(),
HAL_GetTick() to provide better naming and MPHAL separation (they are
fully equivalent otherwise).

Also, refactor extmod/modlwip to use them.
2015-10-27 23:31:42 +03:00
Paul Sokolovsky
858ed6d2f7 extmod/modlwip: Codestyle: no need for () when taking address of primary expr.
Like foo.bar or foo->bar.
2015-10-27 01:39:57 +03:00
Paul Sokolovsky
fa87e90cfa extmod/modlwip: lwip_tcp_send(): Common subexpression elimination, use MIN(). 2015-10-27 01:39:57 +03:00
Paul Sokolovsky
76217064ac extmod/modlwip.c: Codestyle whitespace changes.
With MicroPython codestyle, with pointer casts, "*" packs with primary type
without space. Few other similar changes too (git diff -b -w is null).
2015-10-27 01:39:57 +03:00
Paul Sokolovsky
e0d7740a22 extmod/modlwip: slip: Use stream protocol and be port-independent.
Based on the original patch by Galen Hazelwood:
https://github.com/micropython/micropython/pull/1517 .
2015-10-27 00:04:59 +03:00
Galen Hazelwood
805c6534f8 extmod/modlwip: Initial commit of the lwip network stack module 2015-10-23 19:30:02 +03:00