summaryrefslogtreecommitdiff
path: root/extmod/modlwip.c
AgeCommit message (Collapse)Author
2020-08-30extmod/modlwip: Fix error return for TCP recv when not connected.Damien George
This commit fixes the cases when a TCP socket is in STATE_NEW, STATE_LISTENING or STATE_CONNECTING and recv() is called on it. It now raises ENOTCONN instead of a random error code due to it previously indexing beyond the start of error_lookup_table[]. Signed-off-by: Damien George <damien@micropython.org>
2020-04-18all: Fix implicit floating point to integer conversions.stijn
These are found when building with -Wfloat-conversion.
2020-04-05all: Use MP_ERROR_TEXT for all error messages.Jim Mussared
2020-03-28all: Remove spaces inside and around parenthesis.Damien George
Using new options enabled in the uncrustify configuration.
2020-03-18extmod/modlwip: Properly handle non-blocking and timeout on UDP recv.Damien George
Fixes UDP non-blocking recv so it returns EAGAIN instead of ETIMEDOUT. Timeout waiting for incoming data is also improved by replacing 100ms delay with poll_sockets(), as is done in other parts of this module. Fixes issue #5759.
2020-03-18extmod/modlwip: Fix polling of UDP socket so it doesn't return HUP.Damien George
STATE_NEW will return HUP when polled so put active UDP sockets into a new state which is different to STATE_NEW. Fixes issue #5758.
2020-02-28all: Reformat C and Python source code with tools/codeformat.py.Damien George
This is run with uncrustify 0.70.1, and black 19.10b0.
2019-10-31extmod/modlwip: Unconditionally return POLLHUP/POLLERR when polling.Damien George
POSIX poll should always return POLLERR and POLLHUP in revents, regardless of whether they were requested in the input events flags. See issues #4290 and #5172.
2019-10-31extmod/modlwip: Make socket poll return POLLNVAL in case of bad file.Damien George
2019-10-31extmod/modlwip: Unconditionally return POLLHUP when polling new socket.Damien George
POSIX poll should always return POLLERR and POLLHUP in revents, regardless of whether they were requested in the input events flags. See issues #4290 and #5172.
2019-08-06extmod/modlwip: Implement raw sockets for lwIP.Damien George
Configurable via MICROPY_PY_LWIP_SOCK_RAW.
2019-07-03extmod/modlwip: Use mp_sched_schedule to schedule socket callbacks.Damien George
The helper function exec_user_callback executes within the context of an lwIP C callback, and the user (Python) callback to be scheduled may want to perform further TCP/IP actions, so the latter should be scheduled to run outside the lwIP context (otherwise it's effectively a "hard IRQ" and such callbacks have lots of restrictions).
2019-07-03extmod/modlwip: For TCP send keep trying tcp_write if it returns ERR_MEMDamien George
If tcp_write returns ERR_MEM then it's not a fatal error but instead means the caller should retry the write later on (and this is what lwIP's netconn API does). This fixes problems where a TCP send would raise OSError(ENOMEM) in situations where the TCP/IP stack is under heavy load. See eg issues #1897 and #1971.
2019-05-29extmod/modlwip: Register TCP close-timeout callback before closing PCB.Damien George
In d5f0c87bb985ae344014dc2041fbaad5c522f638 this call to tcp_poll() was added to put a timeout on closing TCP sockets. But after calling tcp_close() the PCB may be freed and therefore invalid, so tcp_poll() can not be used at that point. As a fix this commit calls tcp_poll() before closing the TCP PCB. If the PCB is subsequently closed and freed by tcp_close() or tcp_abort() then the PCB will not be on any active list and the callback will not be executed, which is the desired behaviour (the _lwip_tcp_close_poll() callback only needs to be called if the PCB remains active for longer than the timeout).
2019-05-29extmod/modlwip: Free any incoming bufs/connections before closing PCB.Damien George
Commit 2848a613ac61fce209962354c2698ee587a2c26a introduced a bug where lwip_socket_free_incoming() accessed pcb.tcp->state after the PCB was closed. The state may have changed due to that close call, or the PCB may be freed and therefore invalid. This commit fixes that by calling lwip_socket_free_incoming() before the PCB is closed.
2019-04-11extmod/modlwip: Abort TCP conns that didn't close cleanly in a while.Damien George
2019-04-03extmod/modlwip: Use correct listening socket object in accept callback.Damien George
Since commit da938a83b587c7387b8849f795f3497735d14267 the tcp_arg() that is set for the new connection is the new connection itself, and the parent listening socket is found in the pcb->connected entry.
2019-04-01extmod/modlwip: Free any stored incoming bufs/connections on TCP error.Damien George
2019-04-01extmod/modlwip: Protect socket.accept with lwIP concurrency lock.Damien George
This is needed now that the accept queue can have pending connections removed asynchronously.
2019-04-01extmod/modlwip: Handle case of accept callback called with null PCB.Damien George
2019-04-01extmod/modlwip: Handle case of connection closing while on accept queue.Damien George
In such a case the connection is aborted by lwIP and so must be removed from the pending accept queue.
2019-03-12extmod/modlwip: Fix case where concurrency lock isn't released on error.Damien George
2019-02-27extmod/modlwip: Don't require a port to define concurrency macros.Damien George
2019-02-26extmod/modlwip: Add concurrency protection macros.Damien George
Some users of this module may require the LwIP stack to run at an elevated priority, to protect against concurrency issues with processing done by the underlying network interface. Since LwIP doesn't provide such protection it must be done here (the other option is to run LwIP in a separate thread, and use thread protection mechanisms, but that is a more heavyweight solution).
2019-02-18extmod/modlwip: Fix bug when polling listening socket with backlog=1.Damien George
The bug polling for readability was: if alloc==0 and tcp.item==NULL then the code would incorrectly check tcp.array[iget] which is an invalid dereference when alloc==0. This patch refactors the code to use a helper function lwip_socket_incoming_array() to return the correct pointer for the incomming connection array. Fixes issue #4511.
2019-02-15extmod/modlwip: Change #ifdef to #if for check of MICROPY_PY_LWIP.Damien George
Otherwise this code will be included if MICROPY_PY_LWIP is defined to 0.
2019-01-31py/warning: Support categories for warnings.Paul Sokolovsky
Python defines warnings as belonging to categories, where category is a warning type (descending from exception type). This is useful, as e.g. allows to disable warnings selectively and provide user-defined warning types. So, implement this in MicroPython, except that categories are represented just with strings. However, enough hooks are left to implement categories differently per-port (e.g. as types), without need to patch each and every usage.
2019-01-31extmod/modlwip: Add support for polling UDP sockets for writability.Damien George
2018-12-03extmod/modlwip: Fix read-polling of listening socket with a backlog.Damien George
The recent implementation of the listen backlog meant that the logic to test for readability of such a socket changed, and this commit updates the logic to work again.
2018-12-01extmod/modlwip: Implement TCP listen/accept backlog.Damien George
Array to hold waiting connections is in-place if backlog=1, else is a dynamically allocated array. Incoming connections are processed FIFO style to maintain fairness.
2018-07-20extmod/modlwip: Deregister all lwIP callbacks when closing a socket.Damien George
Otherwise they may be called on a socket that no longer exists. For example, if the GC calls the finaliser on the socket and then reuses its heap memory, the "callback" entry of the old socket may contain invalid data. If lwIP then calls the TCP callback the code may try to call the user callback object which is now invalid. The lwIP callbacks must be deregistered during the closing of the socket, before all the pcb pointers are set to NULL.
2018-07-08extmod: Fix to support compiling with object representation D.Damien George
2018-05-21extmod/modlwip: Allow to compile with MICROPY_PY_LWIP disabled.Damien George
2018-05-17extmod/modlwip: Set POLLHUP flag for sockets that are new.Damien George
This matches CPython behaviour on Linux: a socket that is new and not listening or connected is considered "hung up". Thanks to @rkojedzinszky for the initial patch, PR #3457.
2018-05-17extmod/modlwip: Update to work with lwIP v2.0.Damien George
lwIP v2.0.3 has been tested with this lwip module and it works very well.
2018-05-04extmod/modlwip: In ioctl handle case when socket is in an error state.Damien George
Using MP_STREAM_POLL_HUP for ERR_RST state follows how *nix handles this case.
2018-04-23extmod/modlwip: Check if getaddrinfo() constraints are supported or not.Damien George
In particular don't issue a warning if the passed-in constraints are actually supported because they are the default values.
2018-04-10py/stream: Switch stream close operation from method to ioctl.Damien George
This patch moves the implementation of stream closure from a dedicated method to the ioctl of the stream protocol, for each type that implements closing. The benefits of this are: 1. Rounds out the stream ioctl function, which already includes flush, seek and poll (among other things). 2. Makes calling mp_stream_close() on an object slightly more efficient because it now no longer needs to lookup the close method and call it, rather it just delegates straight to the ioctl function (if it exists). 3. Reduces code size and allows future types that implement the stream protocol to be smaller because they don't need a dedicated close method. Code size reduction is around 200 bytes smaller for x86 archs and around 30 bytes smaller for the bare-metal archs.
2017-11-24extmod/modlwip: Commit TCP out data to lower layers if buffer gets full.Damien George
Dramatically improves TCP sending throughput because without an explicit call to tcp_output() the data is only sent to the lower layers via the lwIP slow timer which (by default) ticks every 500ms.
2017-10-24all: Use NULL instead of "" when calling mp_raise exception helpers.Damien George
This is the established way of doing it and reduces code size by a little bit.
2017-10-04all: Remove inclusion of internal py header files.Damien George
Header files that are considered internal to the py core and should not normally be included directly are: py/nlr.h - internal nlr configuration and declarations py/bc0.h - contains bytecode macro definitions py/runtime0.h - contains basic runtime enums Instead, the top-level header files to include are one of: py/obj.h - includes runtime0.h and defines everything to use the mp_obj_t type py/runtime.h - includes mpstate.h and hence nlr.h, obj.h, runtime0.h, and defines everything to use the general runtime support functions Additional, specific headers (eg py/objlist.h) can be included if needed.
2017-08-30all: Convert remaining "mp_uint_t n_args" to "size_t n_args".Damien George
This is to have consistency across the whole repository.
2017-08-13all: Raise exceptions via mp_raise_XXXJavier Candeira
- Changed: ValueError, TypeError, NotImplementedError - OSError invocations unchanged, because the corresponding utility function takes ints, not strings like the long form invocation. - OverflowError, IndexError and RuntimeError etc. not changed for now until we decide whether to add new utility functions.
2017-07-31extmod/modlwip: Implement setsockopt(IP_ADD_MEMBERSHIP).Paul Sokolovsky
Allows to join multicast groups.
2017-07-31extmod: Use MP_ROM_INT for int values in an mp_rom_map_elem_t.Damien George
2017-07-29extmod/mod{lwip,onewire,webrepl}: Convert to mp_rom_map_elem_t.Paul Sokolovsky
2017-06-04extmod/modlwip: accept: Fix error code for non-blocking mode.Paul Sokolovsky
In non-blocking mode, if no pending connection available, should return EAGAIN, not ETIMEDOUT.
2017-06-04extmod/modlwip: Fix error codes for duplicate calls to connect().Paul Sokolovsky
If socket is already connected, POSIX requires returning EISCONN. If connection was requested, but not yet complete (for non-blocking socket), error code is EALREADY. http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html
2017-06-03extmod/modlwip: connect: For non-blocking mode, return EINPROGRESS.Paul Sokolovsky
Instead of ETIMEDOUT. This is consistent with POSIX: http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html
2017-05-29various: Spelling fixesVille Skyttä