mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-01-30 12:32:37 +00:00
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".
This commit is contained in:
parent
d2fa5c91a7
commit
2b54da5070
@ -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.
|
||||
|
@ -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);
|
||||
|
@ -54,7 +54,8 @@ static const char *err_strerr[] = {
|
||||
"Address in use.", /* ERR_USE -10 */
|
||||
"Low-level netif error.", /* ERR_IF -11 */
|
||||
"Already connected.", /* ERR_ISCONN -12 */
|
||||
"Timeout." /* ERR_TIMEOUT -13 */
|
||||
"Timeout.", /* ERR_TIMEOUT -13 */
|
||||
"Operation in progress." /* ERR_INPROGRESS -14 */
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -137,7 +137,8 @@ static const int err_to_errno_table[] = {
|
||||
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 */
|
||||
ETIMEDOUT, /* ERR_TIMEOUT -13 Timeout */
|
||||
EINPROGRESS /* ERR_INPROGRESS -14 Operation in progress */
|
||||
};
|
||||
|
||||
#define ERR_TO_ERRNO_TABLE_SIZE \
|
||||
|
@ -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,28 +755,29 @@ 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,
|
||||
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
|
||||
@ -784,21 +785,21 @@ DNS_RESULT dns_gethostbyname(const char *hostname, struct ip_addr *addr, dns_fou
|
||||
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 */
|
||||
|
@ -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,7 +84,7 @@ 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,
|
||||
err_t dns_gethostbyname(const char *hostname, struct ip_addr *addr,
|
||||
dns_found_callback found, void *callback_arg);
|
||||
|
||||
#endif /* LWIP_DNS */
|
||||
|
@ -65,6 +65,8 @@ typedef s8_t err_t;
|
||||
|
||||
#define ERR_TIMEOUT -13 /* Timeout. */
|
||||
|
||||
#define ERR_INPROGRESS -14 /* Operation in progress */
|
||||
|
||||
|
||||
#ifdef LWIP_DEBUG
|
||||
extern const char *lwip_strerr(err_t err);
|
||||
|
Loading…
x
Reference in New Issue
Block a user