diff --git a/CHANGELOG b/CHANGELOG index 14ef1c8b..84021054 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,6 +19,10 @@ HISTORY ++ New features: + 2007-12-13 Frédéric Bernon + * api_msg.c, err.h, err.c, sockets.c, dns.c, dns.h: replace "enum dns_result" + by err_t type. Add a new err_t code "ERR_INPROGRESS". + 2007-12-12 Frédéric Bernon * dns.h, dns.c, opt.h: move DNS options to the "right" place. Most visibles are the one which have ram usage. diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 9c81819b..91171c82 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -1063,22 +1063,10 @@ do_dns_found(const char *name, struct ip_addr *ipaddr, void *arg) void do_gethostbyname(void *arg) { - DNS_RESULT res; struct dns_api_msg *msg = (struct dns_api_msg*)arg; - res = dns_gethostbyname(msg->name, msg->addr, do_dns_found, msg); - if (res != DNS_QUERY_QUEUED) { - /* If not queued, return to app thread directly */ - if (res == DNS_COMPLETE) { - /* name was already in octet notation or cached */ - *msg->err = ERR_OK; - } else if (res == DNS_ERR_MEM) { - /* memory allocation error */ - *msg->err = ERR_MEM; - } else { - /* some error occurred */ - *msg->err = ERR_ARG; - }; + *msg->err = dns_gethostbyname(msg->name, msg->addr, do_dns_found, msg); + if (*msg->err != ERR_INPROGRESS) { /* on error or immediate success, wake up the application * task waiting in netconn_gethostbyname */ sys_sem_signal(msg->sem); diff --git a/src/api/err.c b/src/api/err.c index 786dca4a..a803a729 100644 --- a/src/api/err.c +++ b/src/api/err.c @@ -41,20 +41,21 @@ #ifdef LWIP_DEBUG static const char *err_strerr[] = { - "Ok.", /* ERR_OK 0 */ - "Out of memory error.", /* ERR_MEM -1 */ - "Buffer error.", /* ERR_BUF -2 */ - "Routing problem.", /* ERR_RTE -3 */ - "Connection aborted.", /* ERR_ABRT -4 */ - "Connection reset.", /* ERR_RST -5 */ - "Connection closed.", /* ERR_CLSD -6 */ - "Not connected.", /* ERR_CONN -7 */ - "Illegal value.", /* ERR_VAL -8 */ - "Illegal argument.", /* ERR_ARG -9 */ - "Address in use.", /* ERR_USE -10 */ - "Low-level netif error.", /* ERR_IF -11 */ - "Already connected.", /* ERR_ISCONN -12 */ - "Timeout." /* ERR_TIMEOUT -13 */ + "Ok.", /* ERR_OK 0 */ + "Out of memory error.", /* ERR_MEM -1 */ + "Buffer error.", /* ERR_BUF -2 */ + "Routing problem.", /* ERR_RTE -3 */ + "Connection aborted.", /* ERR_ABRT -4 */ + "Connection reset.", /* ERR_RST -5 */ + "Connection closed.", /* ERR_CLSD -6 */ + "Not connected.", /* ERR_CONN -7 */ + "Illegal value.", /* ERR_VAL -8 */ + "Illegal argument.", /* ERR_ARG -9 */ + "Address in use.", /* ERR_USE -10 */ + "Low-level netif error.", /* ERR_IF -11 */ + "Already connected.", /* ERR_ISCONN -12 */ + "Timeout.", /* ERR_TIMEOUT -13 */ + "Operation in progress." /* ERR_INPROGRESS -14 */ }; /** diff --git a/src/api/sockets.c b/src/api/sockets.c index fc5d56cc..5cb73e2c 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -124,20 +124,21 @@ static sys_sem_t selectsem; /** Table to quickly map an lwIP error (err_t) to a socket error * by using -err as an index */ 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. */ - 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. */ - ETIMEDOUT /* ERR_TIMEOUT -13 Timeout */ + 0, /* ERR_OK 0 No error, everything OK. */ + ENOMEM, /* ERR_MEM -1 Out of memory error. */ + ENOBUFS, /* ERR_BUF -2 Buffer error. */ + 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. */ + ETIMEDOUT, /* ERR_TIMEOUT -13 Timeout */ + EINPROGRESS /* ERR_INPROGRESS -14 Operation in progress */ }; #define ERR_TO_ERRNO_TABLE_SIZE \ diff --git a/src/core/dns.c b/src/core/dns.c index 908f3878..f1499950 100644 --- a/src/core/dns.c +++ b/src/core/dns.c @@ -51,7 +51,7 @@ * checks for an IP address string first and converts it if it is valid. * gethostbyname() then does a dns_lookup() to see if the name is * already in the table. If so, the IP is returned. If not, a query is - * issued and the function returns with a DNS_QUERY_QUEUED status. The app + * issued and the function returns with a ERR_INPROGRESS status. The app * using the dns client must then go into a waiting state. * * Once a hostname has been resolved (or found to be non-existent), @@ -702,9 +702,9 @@ memerr1: * @param name the hostname that is to be queried * @param found a callback founction to be called on success, failure or timeout * @param callback_arg argument to pass to the callback function - * @return a DNS_RESULT (@see DNS_RESULT, @see enum dns_result) + * @return @return a err_t return code. */ -static DNS_RESULT +static err_t dns_enqueue(const char *name, dns_found_callback found, void *callback_arg) { u8_t i; @@ -733,7 +733,7 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg) if ((lseqi >= DNS_TABLE_SIZE) || (dns_table[lseqi].state != DNS_STATE_DONE)) { /* no entry can't be used now, table is full */ LWIP_DEBUGF(DNS_DEBUG, ("dns_enqueue: \"%s\": DNS entries table is full\n", name)); - return DNS_ERR_MEM; + return ERR_MEM; } else { /* use the oldest completed one */ i = lseqi; @@ -755,50 +755,51 @@ dns_enqueue(const char *name, dns_found_callback found, void *callback_arg) dns_check_entry(i); /* dns query is enqueued */ - return DNS_QUERY_QUEUED; + return ERR_INPROGRESS; } /** * Resolve a hostname (string) into an IP address. * NON-BLOCKING callback version for use with raw API!!! * - * Returns immediately with one of DNS_RESULT return codes: - * - DNS_COMPLETE if hostname is a valid IP address string or the host + * Returns immediately with one of err_t return codes: + * - ERR_OK if hostname is a valid IP address string or the host * name is already in the local names table. - * - DNS_REQUEST_QUEUED and queues a request to be sent to the DNS server + * - ERR_INPROGRESS enqueue a request to be sent to the DNS server * for resolution if no errors are present. * * @param hostname the hostname that is to be queried * @param addr pointer to a struct ip_addr where to store the address if it is already - * cached in the dns_table (only valid if DNS_COMPLETE is returned!) - * @param found a callback founction to be called on success, failure or timeout (only if - * DNS_QUERY_QUEUED is returned!) + * cached in the dns_table (only valid if ERR_OK is returned!) + * @param found a callback function to be called on success, failure or timeout (only if + * ERR_INPROGRESS is returned!) * @param callback_arg argument to pass to the callback function - * @return a DNS_RESULT (@see DNS_RESULT, @see enum dns_result) + * @return a err_t return code. */ -DNS_RESULT dns_gethostbyname(const char *hostname, struct ip_addr *addr, dns_found_callback found, - void *callback_arg) +err_t +dns_gethostbyname(const char *hostname, struct ip_addr *addr, dns_found_callback found, + void *callback_arg) { /* not initialized or no valid server yet, or invalid addr pointer * or invalid hostname or invalid hostname length */ if ((dns_pcb == NULL) || (addr == NULL) || (!hostname) || (!hostname[0]) || (strlen(hostname) >= DNS_MAX_NAME_LENGTH)) { - return DNS_QUERY_INVALID; + return ERR_VAL; } #if LWIP_HAVE_LOOPIF if (strcmp(hostname,"localhost")==0) { addr->addr = INADDR_LOOPBACK; - return DNS_COMPLETE; + return ERR_OK; } #endif /* LWIP_HAVE_LOOPIF */ - /* host name already in octet notation? set ip addr and return COMPLETE + /* host name already in octet notation? set ip addr and return ERR_OK * already have this address cached? */ if (((addr->addr = inet_addr(hostname)) != INADDR_NONE) || ((addr->addr = dns_lookup(hostname)) != 0)) { - return DNS_COMPLETE; + return ERR_OK; } /* queue query with specified callback */ diff --git a/src/include/lwip/dns.h b/src/include/lwip/dns.h index 744c510d..61967429 100644 --- a/src/include/lwip/dns.h +++ b/src/include/lwip/dns.h @@ -66,21 +66,6 @@ #define DNS_RRCLASS_HS 4 /* Hesiod [Dyer 87] */ #define DNS_RRCLASS_FLUSH 0x800 /* Flush bit */ -/** enumerated list of possible result values returned by dns_gethostname() */ -typedef enum dns_result { - /** dns_table is filled with queries, try again later */ - DNS_ERR_MEM, - /** invalid hostname, hostname too long, - * invalid arguments or dns module not initialized */ - DNS_QUERY_INVALID, - /** the hostname was enqueued for query, - * found callback will be called when resolved */ - DNS_QUERY_QUEUED, - /** the hostname was found in the cache and was directly returned, - * found callback will not be called */ - DNS_COMPLETE -} DNS_RESULT; - /** Callback which is invoked when a hostname is found. * A function of this type must be implemented by the application using the DNS resolver. * @param name pointer to the name that was looked up. @@ -99,8 +84,8 @@ void dns_setserver(u8_t numdns, struct ip_addr *dnsserver); struct ip_addr dns_getserver(u8_t numdns); -DNS_RESULT dns_gethostbyname(const char *hostname, struct ip_addr *addr, - dns_found_callback found, void *callback_arg); +err_t dns_gethostbyname(const char *hostname, struct ip_addr *addr, + dns_found_callback found, void *callback_arg); #endif /* LWIP_DNS */ diff --git a/src/include/lwip/err.h b/src/include/lwip/err.h index bc070854..e5063235 100644 --- a/src/include/lwip/err.h +++ b/src/include/lwip/err.h @@ -42,28 +42,30 @@ typedef s8_t err_t; /* Definitions for error constants. */ -#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_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_RTE) -#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_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 -8 /* Illegal value. */ +#define ERR_VAL -8 /* Illegal value. */ -#define ERR_ARG -9 /* Illegal argument. */ +#define ERR_ARG -9 /* Illegal argument. */ -#define ERR_USE -10 /* Address in use. */ +#define ERR_USE -10 /* Address in use. */ -#define ERR_IF -11 /* Low-level netif error */ -#define ERR_ISCONN -12 /* Already connected. */ +#define ERR_IF -11 /* Low-level netif error */ +#define ERR_ISCONN -12 /* Already connected. */ -#define ERR_TIMEOUT -13 /* Timeout. */ +#define ERR_TIMEOUT -13 /* Timeout. */ + +#define ERR_INPROGRESS -14 /* Operation in progress */ #ifdef LWIP_DEBUG