Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
NetServices/if/net/netdnsrequest.cpp@0:8cdad1c73e8e, 2012-03-25 (annotated)
- Committer:
- bfictorie
- Date:
- Sun Mar 25 17:26:30 2012 +0000
- Revision:
- 0:8cdad1c73e8e
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| bfictorie | 0:8cdad1c73e8e | 1 | |
| bfictorie | 0:8cdad1c73e8e | 2 | /* |
| bfictorie | 0:8cdad1c73e8e | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
| bfictorie | 0:8cdad1c73e8e | 4 | |
| bfictorie | 0:8cdad1c73e8e | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
| bfictorie | 0:8cdad1c73e8e | 6 | of this software and associated documentation files (the "Software"), to deal |
| bfictorie | 0:8cdad1c73e8e | 7 | in the Software without restriction, including without limitation the rights |
| bfictorie | 0:8cdad1c73e8e | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| bfictorie | 0:8cdad1c73e8e | 9 | copies of the Software, and to permit persons to whom the Software is |
| bfictorie | 0:8cdad1c73e8e | 10 | furnished to do so, subject to the following conditions: |
| bfictorie | 0:8cdad1c73e8e | 11 | |
| bfictorie | 0:8cdad1c73e8e | 12 | The above copyright notice and this permission notice shall be included in |
| bfictorie | 0:8cdad1c73e8e | 13 | all copies or substantial portions of the Software. |
| bfictorie | 0:8cdad1c73e8e | 14 | |
| bfictorie | 0:8cdad1c73e8e | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| bfictorie | 0:8cdad1c73e8e | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| bfictorie | 0:8cdad1c73e8e | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| bfictorie | 0:8cdad1c73e8e | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| bfictorie | 0:8cdad1c73e8e | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| bfictorie | 0:8cdad1c73e8e | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
| bfictorie | 0:8cdad1c73e8e | 21 | THE SOFTWARE. |
| bfictorie | 0:8cdad1c73e8e | 22 | */ |
| bfictorie | 0:8cdad1c73e8e | 23 | |
| bfictorie | 0:8cdad1c73e8e | 24 | #include "netdnsrequest.h" |
| bfictorie | 0:8cdad1c73e8e | 25 | #include <string.h> |
| bfictorie | 0:8cdad1c73e8e | 26 | |
| bfictorie | 0:8cdad1c73e8e | 27 | NetDnsRequest::NetDnsRequest(const char* hostname) : NetService(), m_ip(0,0,0,0), m_pCbItem(NULL), m_pCbMeth(NULL), m_pHost(NULL), m_closed(false) |
| bfictorie | 0:8cdad1c73e8e | 28 | { |
| bfictorie | 0:8cdad1c73e8e | 29 | m_hostname = new char[strlen(hostname)+1]; |
| bfictorie | 0:8cdad1c73e8e | 30 | strcpy( m_hostname, hostname ); |
| bfictorie | 0:8cdad1c73e8e | 31 | } |
| bfictorie | 0:8cdad1c73e8e | 32 | |
| bfictorie | 0:8cdad1c73e8e | 33 | NetDnsRequest::NetDnsRequest(Host* pHost) : NetService(), m_ip(0,0,0,0), m_pCbItem(NULL), m_pCbMeth(NULL), m_closed(false) |
| bfictorie | 0:8cdad1c73e8e | 34 | { |
| bfictorie | 0:8cdad1c73e8e | 35 | m_hostname = (char*) pHost->getName(); |
| bfictorie | 0:8cdad1c73e8e | 36 | m_pHost = pHost; |
| bfictorie | 0:8cdad1c73e8e | 37 | } |
| bfictorie | 0:8cdad1c73e8e | 38 | |
| bfictorie | 0:8cdad1c73e8e | 39 | NetDnsRequest::~NetDnsRequest() |
| bfictorie | 0:8cdad1c73e8e | 40 | { |
| bfictorie | 0:8cdad1c73e8e | 41 | close(); |
| bfictorie | 0:8cdad1c73e8e | 42 | } |
| bfictorie | 0:8cdad1c73e8e | 43 | |
| bfictorie | 0:8cdad1c73e8e | 44 | void NetDnsRequest::getResult(IpAddr* pIp) |
| bfictorie | 0:8cdad1c73e8e | 45 | { |
| bfictorie | 0:8cdad1c73e8e | 46 | if( pIp != NULL ) |
| bfictorie | 0:8cdad1c73e8e | 47 | *pIp = m_ip; |
| bfictorie | 0:8cdad1c73e8e | 48 | } |
| bfictorie | 0:8cdad1c73e8e | 49 | |
| bfictorie | 0:8cdad1c73e8e | 50 | void NetDnsRequest::close() |
| bfictorie | 0:8cdad1c73e8e | 51 | { |
| bfictorie | 0:8cdad1c73e8e | 52 | if(m_closed) |
| bfictorie | 0:8cdad1c73e8e | 53 | return; |
| bfictorie | 0:8cdad1c73e8e | 54 | m_closed = true; |
| bfictorie | 0:8cdad1c73e8e | 55 | if( !m_pHost ) |
| bfictorie | 0:8cdad1c73e8e | 56 | delete[] m_hostname; |
| bfictorie | 0:8cdad1c73e8e | 57 | NetService::close(); |
| bfictorie | 0:8cdad1c73e8e | 58 | } |
| bfictorie | 0:8cdad1c73e8e | 59 | |
| bfictorie | 0:8cdad1c73e8e | 60 | void NetDnsRequest::onReply(NetDnsReply reply) //Must be called by impl when the request completes |
| bfictorie | 0:8cdad1c73e8e | 61 | { |
| bfictorie | 0:8cdad1c73e8e | 62 | if( m_pHost ) |
| bfictorie | 0:8cdad1c73e8e | 63 | m_pHost->setIp(m_ip); |
| bfictorie | 0:8cdad1c73e8e | 64 | if(m_pCbItem && m_pCbMeth) |
| bfictorie | 0:8cdad1c73e8e | 65 | (m_pCbItem->*m_pCbMeth)(reply); |
| bfictorie | 0:8cdad1c73e8e | 66 | } |