/* UpTools v8.6 * * Copyright (c) 2005-2013 Fundacion Universidad de Palermo (Argentina). * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. Neither the name of the copyright holder nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * 4. Redistributions of any form whatsoever must retain the following * acknowledgment: 'This product includes software developed by the * "Universidad de Palermo, Argentina" (http://www.palermo.edu/).' * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include <iostream> #include <UpTools/UpResolver.h> #include <UpTools/UpInet.h> #include <UpTools/UpLog.h> using namespace std; ////////////////////////////////////////////////////////////////////////////////////////////// // Test con 1 resolver Asyncronico int main() { cout << "UpResolver: asynchronous resolver: test" << endl << endl; upOpenLog("testUpResolver",LOG_PERROR|LOG_THID,LOG_LOCAL7,LOG_DEBUG); // upOpenLogFile("",LOG_THID,"stdout",LOG_DEBUG); UpResolver resolv; UpDnsQuery *q0 = new UpDnsQuery("www.google.com",ns_t_a, QUERY_DONT_USE_CALLBACK,QUERY_BLOCKING); UpDnsQuery *q1 = new UpDnsQuery("palermo.edu",ns_t_naptr,QUERY_USE_CALLBACK,QUERY_NONBLOCKING); UpDnsQuery *q2 = new UpDnsQuery("www.intel.com",ns_t_a, QUERY_USE_CALLBACK,QUERY_NONBLOCKING); UpDnsQuery *q3 = new UpDnsQuery("intel.com",ns_t_mx, QUERY_USE_CALLBACK,QUERY_NONBLOCKING); UpDnsQuery *q4 = new UpDnsQuery("www.yahoo.com",ns_t_a, QUERY_USE_CALLBACK,QUERY_NONBLOCKING); cout << "\nMaking a blocking query for www.google.com type=A ..." << endl; bool q0result = resolv.query(*q0); cout << "Query return value: " << q0result << endl << *q0 << endl; delete q0; cout << "Making nonblocking queries, various domains and types..." << endl; resolv.query(*q1); resolv.query(*q2); resolv.query(*q3); resolv.query(*q4); cout << "resetting query id " << q1->getId() << " for a new domain"<< endl; q1->set("berkeley.edu",ns_t_mx, QUERY_USE_CALLBACK,QUERY_NONBLOCKING); resolv.query(*q1); cout << "Sleeping for one sec..." << endl; sleep(1); cout << "Deleting query id " << q2->getId() << endl; delete q2; cout << "Sleeping for one sec..." << endl; sleep(1); cout << "Cancelling queries id " << q3->getId() << endl; q3->cancel(); delete q3; cout << "Waiting for query id " << q4->getId() << endl; q4->waitCompletion(); cout << "resetting query id " << q4->getId() << " for a new domain"<< endl; q4->set(UpAddress("200.69.213.2"),QUERY_USE_CALLBACK,QUERY_NONBLOCKING); resolv.query(*q4); cout << "Waiting for query id " << q4->getId() << endl; q4->waitCompletion(); q1->waitCompletion(); delete q1; delete q4; cout << "Sleeping for one sec..." << endl; sleep(1); return 0; }