RTC auf true
features/netsocket/DNS.h@2:7aab896b1a3b, 2019-03-13 (annotated)
- Committer:
- kevman
- Date:
- Wed Mar 13 11:03:24 2019 +0000
- Revision:
- 2:7aab896b1a3b
- Parent:
- 0:38ceb79fef03
2019-03-13
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kevman | 0:38ceb79fef03 | 1 | /* |
kevman | 0:38ceb79fef03 | 2 | * Copyright (c) 2018 ARM Limited |
kevman | 0:38ceb79fef03 | 3 | * |
kevman | 0:38ceb79fef03 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kevman | 0:38ceb79fef03 | 5 | * you may not use this file except in compliance with the License. |
kevman | 0:38ceb79fef03 | 6 | * You may obtain a copy of the License at |
kevman | 0:38ceb79fef03 | 7 | * |
kevman | 0:38ceb79fef03 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kevman | 0:38ceb79fef03 | 9 | * |
kevman | 0:38ceb79fef03 | 10 | * Unless required by applicable law or agreed to in writing, software |
kevman | 0:38ceb79fef03 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kevman | 0:38ceb79fef03 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kevman | 0:38ceb79fef03 | 13 | * See the License for the specific language governing permissions and |
kevman | 0:38ceb79fef03 | 14 | * limitations under the License. |
kevman | 0:38ceb79fef03 | 15 | */ |
kevman | 0:38ceb79fef03 | 16 | |
kevman | 0:38ceb79fef03 | 17 | #ifndef DNS_H |
kevman | 0:38ceb79fef03 | 18 | #define DNS_H |
kevman | 0:38ceb79fef03 | 19 | |
kevman | 0:38ceb79fef03 | 20 | class DNS { |
kevman | 0:38ceb79fef03 | 21 | public: |
kevman | 0:38ceb79fef03 | 22 | |
kevman | 0:38ceb79fef03 | 23 | /** Translate a hostname to an IP address with specific version. |
kevman | 0:38ceb79fef03 | 24 | * |
kevman | 0:38ceb79fef03 | 25 | * The hostname may be either a domain name or an IP address. If the |
kevman | 0:38ceb79fef03 | 26 | * hostname is an IP address, no network transactions will be performed. |
kevman | 0:38ceb79fef03 | 27 | * |
kevman | 0:38ceb79fef03 | 28 | * If no stack-specific DNS resolution is provided, the hostname |
kevman | 0:38ceb79fef03 | 29 | * will be resolve using a UDP socket on the stack. |
kevman | 0:38ceb79fef03 | 30 | * |
kevman | 0:38ceb79fef03 | 31 | * @param host Hostname to resolve. |
kevman | 0:38ceb79fef03 | 32 | * @param address Pointer to a SocketAddress to store the result. |
kevman | 0:38ceb79fef03 | 33 | * @param version IP version of address to resolve, NSAPI_UNSPEC indicates |
kevman | 0:38ceb79fef03 | 34 | * version is chosen by the stack (defaults to NSAPI_UNSPEC). |
kevman | 0:38ceb79fef03 | 35 | * @return NSAPI_ERROR_OK on success, negative error code on failure. |
kevman | 0:38ceb79fef03 | 36 | */ |
kevman | 0:38ceb79fef03 | 37 | virtual nsapi_error_t gethostbyname(const char *host, |
kevman | 0:38ceb79fef03 | 38 | SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC) = 0; |
kevman | 0:38ceb79fef03 | 39 | |
kevman | 0:38ceb79fef03 | 40 | /** Hostname translation callback for gethostbyname_async. |
kevman | 0:38ceb79fef03 | 41 | * |
kevman | 0:38ceb79fef03 | 42 | * The callback is called after DNS resolution completes, or a failure occurs. |
kevman | 0:38ceb79fef03 | 43 | * |
kevman | 0:38ceb79fef03 | 44 | * Callback should not take more than 10ms to execute, otherwise it might |
kevman | 0:38ceb79fef03 | 45 | * prevent underlying thread processing. A portable user of the callback |
kevman | 0:38ceb79fef03 | 46 | * should not make calls to network operations due to stack size limitations. |
kevman | 0:38ceb79fef03 | 47 | * The callback should not perform expensive operations such as socket recv/send |
kevman | 0:38ceb79fef03 | 48 | * calls or blocking operations. |
kevman | 0:38ceb79fef03 | 49 | * |
kevman | 0:38ceb79fef03 | 50 | * @param result NSAPI_ERROR_OK on success, negative error code on failure. |
kevman | 0:38ceb79fef03 | 51 | * @param address On success, destination for the host SocketAddress. |
kevman | 0:38ceb79fef03 | 52 | */ |
kevman | 0:38ceb79fef03 | 53 | typedef mbed::Callback<void (nsapi_error_t result, SocketAddress *address)> hostbyname_cb_t; |
kevman | 0:38ceb79fef03 | 54 | |
kevman | 0:38ceb79fef03 | 55 | /** Translate a hostname to an IP address (asynchronous). |
kevman | 0:38ceb79fef03 | 56 | * |
kevman | 0:38ceb79fef03 | 57 | * The hostname may be either a domain name or an IP address. If the |
kevman | 0:38ceb79fef03 | 58 | * hostname is an IP address, no network transactions will be performed. |
kevman | 0:38ceb79fef03 | 59 | * |
kevman | 0:38ceb79fef03 | 60 | * If no stack-specific DNS resolution is provided, the hostname |
kevman | 0:38ceb79fef03 | 61 | * will be resolved using a UDP socket on the stack. |
kevman | 0:38ceb79fef03 | 62 | * |
kevman | 0:38ceb79fef03 | 63 | * The call is non-blocking. The result of the DNS operation is returned by the callback. |
kevman | 0:38ceb79fef03 | 64 | * If this function returns failure, the callback will not be called. If it is successful, |
kevman | 0:38ceb79fef03 | 65 | * (the IP address was found from the DNS cache), the callback will be called |
kevman | 0:38ceb79fef03 | 66 | * before the function returns. |
kevman | 0:38ceb79fef03 | 67 | * |
kevman | 0:38ceb79fef03 | 68 | * @param host Hostname to resolve. |
kevman | 0:38ceb79fef03 | 69 | * @param callback Callback that is called to return the result. |
kevman | 0:38ceb79fef03 | 70 | * @param version IP version of address to resolve. NSAPI_UNSPEC indicates that the |
kevman | 0:38ceb79fef03 | 71 | * version is chosen by the stack (defaults to NSAPI_UNSPEC). |
kevman | 0:38ceb79fef03 | 72 | * @return NSAPI_ERROR_OK on immediate success, |
kevman | 0:38ceb79fef03 | 73 | * negative error code on immediate failure or |
kevman | 0:38ceb79fef03 | 74 | * a positive unique ID that represents the hostname translation operation |
kevman | 0:38ceb79fef03 | 75 | * and can be passed to cancel. |
kevman | 0:38ceb79fef03 | 76 | */ |
kevman | 0:38ceb79fef03 | 77 | virtual nsapi_value_or_error_t gethostbyname_async(const char *host, hostbyname_cb_t callback, |
kevman | 0:38ceb79fef03 | 78 | nsapi_version_t version = NSAPI_UNSPEC) = 0; |
kevman | 0:38ceb79fef03 | 79 | |
kevman | 0:38ceb79fef03 | 80 | /** Cancel asynchronous hostname translation. |
kevman | 0:38ceb79fef03 | 81 | * |
kevman | 0:38ceb79fef03 | 82 | * When translation is canceled, callback is not called. |
kevman | 0:38ceb79fef03 | 83 | * |
kevman | 0:38ceb79fef03 | 84 | * @param id Unique ID of the hostname translation operation returned by gethostbyname_async. |
kevman | 0:38ceb79fef03 | 85 | * @return NSAPI_ERROR_OK on success, negative error code on failure. |
kevman | 0:38ceb79fef03 | 86 | */ |
kevman | 0:38ceb79fef03 | 87 | virtual nsapi_error_t gethostbyname_async_cancel(int id) = 0; |
kevman | 0:38ceb79fef03 | 88 | |
kevman | 0:38ceb79fef03 | 89 | /** Add a domain name server to list of servers to query. |
kevman | 0:38ceb79fef03 | 90 | * |
kevman | 0:38ceb79fef03 | 91 | * @param address DNS server host address. |
kevman | 0:38ceb79fef03 | 92 | * @return NSAPI_ERROR_OK on success, negative error code on failure. |
kevman | 0:38ceb79fef03 | 93 | */ |
kevman | 0:38ceb79fef03 | 94 | virtual nsapi_error_t add_dns_server(const SocketAddress &address) = 0; |
kevman | 0:38ceb79fef03 | 95 | }; |
kevman | 0:38ceb79fef03 | 96 | |
kevman | 0:38ceb79fef03 | 97 | #endif |