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.

This commit is contained in:
goldsimon 2007-11-27 21:15:44 +00:00
parent b4741332e0
commit 03777ccb21
5 changed files with 34 additions and 27 deletions

View File

@ -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).

View File

@ -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;
}

View File

@ -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

View File

@ -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. */

View File

@ -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. */