diff --git a/CHANGELOG b/CHANGELOG index 2221c25c..60edb330 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -499,6 +499,11 @@ HISTORY ++ Bug fixes: + 2007-11-27 Simon Goldschmidt + * err.h, api_lib.c, api_msg.c, sockets.c: Changed error handling: ERR_MEM, ERR_BUF + and ERR_RTE are seen as non-fatal, all other errors are fatal. netconns and + sockets block most operations once they have seen a fatal error. + 2007-11-27 Simon Goldschmidt * udp.h, udp.c, dhcp.c: Implemented new function udp_sendto_if which takes the netif to send as an argument (to be able to send on netifs that are down). diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 6fd5e92c..1d96fe21 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -355,18 +355,21 @@ netconn_recv(struct netconn *conn) if (conn->recvmbox == SYS_MBOX_NULL) { if ((conn->recvmbox = sys_mbox_new()) == SYS_MBOX_NULL) { + /* @todo: should calling netconn_recv on a TCP listen conn be fatal?? */ + /* TCP listen conn don't have a recvmbox! */ conn->err = ERR_CONN; return NULL; } } - if (conn->err != ERR_OK) { + if (ERR_IS_FATAL(conn->err)) { return NULL; } if (conn->type == NETCONN_TCP) { #if LWIP_TCP if (conn->state == NETCONN_LISTEN) { + /* @todo: should calling netconn_recv on a TCP listen conn be fatal?? */ conn->err = ERR_CONN; return NULL; } diff --git a/src/api/api_msg.c b/src/api/api_msg.c index d8260642..fd402c67 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -546,7 +546,7 @@ do_delconn(struct api_msg_msg *msg) void do_bind(struct api_msg_msg *msg) { - if (msg->conn->err == ERR_OK) { + if (!ERR_IS_FATAL(msg->conn->err)) { if (msg->conn->pcb.tcp != NULL) { switch (NETCONNTYPE_GROUP(msg->conn->type)) { #if LWIP_RAW @@ -596,7 +596,7 @@ do_connected(void *arg, struct tcp_pcb *pcb, err_t err) } conn->err = err; - if (conn->type == NETCONN_TCP && err == ERR_OK) { + if ((conn->type == NETCONN_TCP) && (err == ERR_OK)) { setup_tcp(conn); } conn->state = NETCONN_NONE; @@ -676,7 +676,7 @@ void do_listen(struct api_msg_msg *msg) { #if LWIP_TCP - if (msg->conn->err == ERR_OK) { + if (!ERR_IS_FATAL(msg->conn->err)) { if (msg->conn->pcb.tcp != NULL) { if (msg->conn->type == NETCONN_TCP) { if (msg->conn->pcb.tcp->state == CLOSED) { @@ -715,7 +715,7 @@ do_listen(struct api_msg_msg *msg) void do_send(struct api_msg_msg *msg) { - if (msg->conn->err == ERR_OK) { + if (!ERR_IS_FATAL(msg->conn->err)) { if (msg->conn->pcb.tcp != NULL) { switch (NETCONNTYPE_GROUP(msg->conn->type)) { #if LWIP_RAW @@ -754,7 +754,7 @@ void do_recv(struct api_msg_msg *msg) { #if LWIP_TCP - if (msg->conn->err == ERR_OK) { + if (!ERR_IS_FATAL(msg->conn->err)) { if (msg->conn->pcb.tcp != NULL) { if (msg->conn->type == NETCONN_TCP) { tcp_recved(msg->conn->pcb.tcp, msg->msg.r.len); @@ -828,10 +828,9 @@ do_writemore(struct netconn *conn) conn->write_delayed = 1; #endif } else { - /* if ERR_MEM, we wait for sent_tcp or poll_tcp to be called */ + /* if ERR_MEM, we wait for sent_tcp or poll_tcp to be called + on other errors we don't try writing any more */ conn->err = err; - /* since we've had an error (except temporary running out of memory, - we don't try writing any more */ write_finished = 1; } @@ -863,7 +862,7 @@ do_writemore(struct netconn *conn) void do_write(struct api_msg_msg *msg) { - if (msg->conn->err == ERR_OK) { + if (!ERR_IS_FATAL(msg->conn->err)) { if ((msg->conn->pcb.tcp != NULL) && (msg->conn->type == NETCONN_TCP)) { #if LWIP_TCP msg->conn->state = NETCONN_WRITE; @@ -937,7 +936,7 @@ do_getaddr(struct api_msg_msg *msg) #endif /* LWIP_TCP */ } } else { - msg->conn->err =ERR_CONN; + msg->conn->err = ERR_CONN; } TCPIP_APIMSG_ACK(msg); } @@ -974,7 +973,7 @@ do_close(struct api_msg_msg *msg) void do_join_leave_group(struct api_msg_msg *msg) { - if (msg->conn->err == ERR_OK) { + if (!ERR_IS_FATAL(msg->conn->err)) { if (msg->conn->pcb.tcp != NULL) { if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_UDP) { #if LWIP_UDP diff --git a/src/api/sockets.c b/src/api/sockets.c index 87dcc11a..fc5d56cc 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -127,13 +127,13 @@ static const int err_to_errno_table[] = { 0, /* ERR_OK 0 No error, everything OK. */ ENOMEM, /* ERR_MEM -1 Out of memory error. */ ENOBUFS, /* ERR_BUF -2 Buffer error. */ - ECONNABORTED, /* ERR_ABRT -3 Connection aborted. */ - ECONNRESET, /* ERR_RST -4 Connection reset. */ - ESHUTDOWN, /* ERR_CLSD -5 Connection closed. */ - ENOTCONN, /* ERR_CONN -6 Not connected. */ - EINVAL, /* ERR_VAL -7 Illegal value. */ - EIO, /* ERR_ARG -8 Illegal argument. */ - EHOSTUNREACH, /* ERR_RTE -9 Routing problem. */ + EHOSTUNREACH, /* ERR_RTE -3 Routing problem. */ + ECONNABORTED, /* ERR_ABRT -4 Connection aborted. */ + ECONNRESET, /* ERR_RST -5 Connection reset. */ + ESHUTDOWN, /* ERR_CLSD -6 Connection closed. */ + ENOTCONN, /* ERR_CONN -7 Not connected. */ + EINVAL, /* ERR_VAL -8 Illegal value. */ + EIO, /* ERR_ARG -9 Illegal argument. */ EADDRINUSE, /* ERR_USE -10 Address in use. */ -1, /* ERR_IF -11 Low-level netif error */ -1, /* ERR_ISCONN -12 Already connected. */ diff --git a/src/include/lwip/err.h b/src/include/lwip/err.h index d0b63bd3..cf104db0 100644 --- a/src/include/lwip/err.h +++ b/src/include/lwip/err.h @@ -45,18 +45,18 @@ typedef s8_t err_t; #define ERR_OK 0 /* No error, everything OK. */ #define ERR_MEM -1 /* Out of memory error. */ #define ERR_BUF -2 /* Buffer error. */ +#define ERR_RTE -3 /* Routing problem. */ +#define ERR_IS_FATAL(e) ((e) < ERR_TIMEOUT) -#define ERR_ABRT -3 /* Connection aborted. */ -#define ERR_RST -4 /* Connection reset. */ -#define ERR_CLSD -5 /* Connection closed. */ -#define ERR_CONN -6 /* Not connected. */ +#define ERR_ABRT -4 /* Connection aborted. */ +#define ERR_RST -5 /* Connection reset. */ +#define ERR_CLSD -6 /* Connection closed. */ +#define ERR_CONN -7 /* Not connected. */ -#define ERR_VAL -7 /* Illegal value. */ +#define ERR_VAL -8 /* Illegal value. */ -#define ERR_ARG -8 /* Illegal argument. */ - -#define ERR_RTE -9 /* Routing problem. */ +#define ERR_ARG -9 /* Illegal argument. */ #define ERR_USE -10 /* Address in use. */