From 3e1cca65bd289497c9f2bb0bc69f8688341f6cdb Mon Sep 17 00:00:00 2001 From: goldsimon Date: Sun, 17 Jan 2010 18:28:56 +0000 Subject: [PATCH] task #10102: "netconn: clean up conn->err threading issues" by adding error return value to struct api_msg_msg --- CHANGELOG | 4 ++++ src/include/lwip/api.h | 20 ++++++++++++++++---- src/include/lwip/api_msg.h | 2 ++ 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 486f3ba5..ffb9a9b2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -50,6 +50,10 @@ HISTORY ++ Bugfixes: + 2010-01-17: Simon Goldschmidt + * api_lib.c, api_msg.c, (api_msg.h, api.h, sockets.c, tcpip.c): + task #10102: Netconn: clean up conn->err threading issues + 2010-01-17: Simon Goldschmidt * api.h, api_lib.c, sockets.c: Changed netconn_recv() and netconn_accept() to return err_t (bugs #27709 and #28087) diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h index 14e79493..d4197f1a 100644 --- a/src/include/lwip/api.h +++ b/src/include/lwip/api.h @@ -101,6 +101,7 @@ struct tcp_pcb; struct udp_pcb; struct raw_pcb; struct netconn; +struct api_msg_msg; /** A callback prototype to inform about events for a netconn */ typedef void (* netconn_callback)(struct netconn *, enum netconn_evt, u16_t len); @@ -119,7 +120,7 @@ struct netconn { struct raw_pcb *raw; } pcb; /** the last error this netconn had */ - err_t err; + err_t last_err; /** sem that is used to synchroneously execute functions in the core context */ sys_sem_t op_completed; /** mbox where received packets are stored until they are fetched @@ -142,8 +143,9 @@ struct netconn { s16_t recv_avail; #if LWIP_TCP /** TCP: when data passed to netconn_write doesn't fit into the send buffer, - this temporarily stores the message. */ - struct api_msg_msg *write_msg; + this temporarily stores the message. + Also used during connect and close. */ + struct api_msg_msg *current_msg; /** TCP: when data passed to netconn_write doesn't fit into the send buffer, this temporarily stores how much is already sent. */ size_t write_offset; @@ -158,11 +160,21 @@ struct netconn { netconn_callback callback; }; -/* Register an Network connection event */ +/** Register an Network connection event */ #define API_EVENT(c,e,l) if (c->callback) { \ (*c->callback)(c, e, l); \ } +/** Set conn->last_err to err but don't overwrite fatal errors */ +#define NETCONN_SET_SAFE_ERR(conn, err) do { \ + SYS_ARCH_DECL_PROTECT(lev); \ + SYS_ARCH_PROTECT(lev); \ + if (!ERR_IS_FATAL((conn)->last_err)) { \ + (conn)->last_err = err; \ + } \ + SYS_ARCH_UNPROTECT(lev); \ +} while(0); + /* Network connection functions: */ #define netconn_new(t) netconn_new_with_proto_and_callback(t, 0, NULL) #define netconn_new_with_callback(t, c) netconn_new_with_proto_and_callback(t, 0, c) diff --git a/src/include/lwip/api_msg.h b/src/include/lwip/api_msg.h index d3b04568..845decc8 100644 --- a/src/include/lwip/api_msg.h +++ b/src/include/lwip/api_msg.h @@ -58,6 +58,8 @@ struct api_msg_msg { /** The netconn which to process - always needed: it includes the semaphore which is used to block the application thread until the function finished. */ struct netconn *conn; + /** The return value of the function executed in tcpip_thread. */ + err_t err; /** Depending on the executed function, one of these union members is used */ union { /** used for do_send */