Changeset 561 for trunk/src/network/kernel/qhostinfo.cpp
- Timestamp:
- Feb 11, 2010, 11:19:06 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk
-
Property svn:mergeinfo
set to (toggle deleted branches)
/branches/vendor/nokia/qt/4.6.1 merged eligible /branches/vendor/nokia/qt/current merged eligible /branches/vendor/trolltech/qt/current 3-149
-
Property svn:mergeinfo
set to (toggle deleted branches)
-
trunk/src/network/kernel/qhostinfo.cpp
r2 r561 2 2 ** 3 3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). 4 ** Contact: Qt Software Information ([email protected]) 4 ** All rights reserved. 5 ** Contact: Nokia Corporation ([email protected]) 5 6 ** 6 7 ** This file is part of the QtNetwork module of the Qt Toolkit. … … 21 22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 22 23 ** 23 ** In addition, as a special exception, Nokia gives you certain 24 ** additional rights. These rights are described in the Nokia Qt LGPL 25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this 26 ** package. 24 ** In addition, as a special exception, Nokia gives you certain additional 25 ** rights. These rights are described in the Nokia Qt LGPL Exception 26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 27 27 ** 28 28 ** GNU General Public License Usage … … 34 34 ** met: http://www.gnu.org/copyleft/gpl.html. 35 35 ** 36 ** If you are unsure which license is appropriate for your use, please37 ** contact the sales department at qt-sales@nokia.com.36 ** If you 37 ** @nokia.com. 38 38 ** $QT_END_LICENSE$ 39 39 ** … … 43 43 #include "qhostinfo_p.h" 44 44 45 45 46 #include <qabstracteventdispatcher.h> 46 47 #include <private/qunicodetables_p.h> … … 60 61 QT_BEGIN_NAMESPACE 61 62 62 Q_GLOBAL_STATIC(QHostInfoAgent, theAgent) 63 void QHostInfoAgent::staticCleanup() 64 { 65 theAgent()->cleanup(); 66 } 63 #ifndef QT_NO_THREAD 64 Q_GLOBAL_STATIC(QHostInfoLookupManager, theHostInfoLookupManager) 65 #endif 67 66 68 67 //#define QHOSTINFO_DEBUG … … 74 73 \reentrant 75 74 \inmodule QtNetwork 76 \ingroup io75 \ingroup 77 76 78 77 QHostInfo uses the lookup mechanisms provided by the operating … … 142 141 143 142 \snippet doc/src/snippets/code/src_network_kernel_qhostinfo.cpp 4 143 144 145 144 146 145 147 \sa abortHostLookup(), addresses(), error(), fromName() … … 159 161 qRegisterMetaType<QHostInfo>("QHostInfo"); 160 162 161 #if defined(Q_OS_WIN32) || defined(Q_OS_WINCE) 162 QWindowsSockInit bust; // makes sure WSAStartup was callled 163 int id = theIdCounter.fetchAndAddRelaxed(1); // generate unique ID 164 165 if (name.isEmpty()) { 166 QHostInfo hostInfo(id); 167 hostInfo.setError(QHostInfo::HostNotFound); 168 hostInfo.setErrorString(QObject::tr("No host name given")); 169 QScopedPointer<QHostInfoResult> result(new QHostInfoResult); 170 QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)), 171 receiver, member, Qt::QueuedConnection); 172 result.data()->emitResultsReady(hostInfo); 173 return id; 174 } 175 176 #ifdef QT_NO_THREAD 177 QHostInfo hostInfo = QHostInfoAgent::fromName(name); 178 hostInfo.setLookupId(id); 179 QScopedPointer<QHostInfoResult> result(new QHostInfoResult); 180 QObject::connect(result.data(), SIGNAL(resultsReady(QHostInfo)), 181 receiver, member, Qt::QueuedConnection); 182 result.data()->emitResultsReady(hostInfo); 183 #else 184 QHostInfoRunnable* runnable = new QHostInfoRunnable(name, id); 185 QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); 186 theHostInfoLookupManager()->scheduleLookup(runnable); 163 187 #endif 164 188 165 // Support for IDNA 166 QString lookup = QString::fromLatin1(QUrl::toAce(name)); 167 168 QHostInfoResult *result = new QHostInfoResult; 169 result->autoDelete = false; 170 QObject::connect(result, SIGNAL(resultsReady(QHostInfo)), 171 receiver, member); 172 int id = result->lookupId = theIdCounter.fetchAndAddRelaxed(1); 173 174 if (lookup.isEmpty()) { 175 QHostInfo info(id); 176 info.setError(QHostInfo::HostNotFound); 177 info.setErrorString(QObject::tr("No host name given")); 178 QMetaObject::invokeMethod(result, "emitResultsReady", Qt::QueuedConnection, 179 Q_ARG(QHostInfo, info)); 180 result->autoDelete = true; 181 return id; 182 } 183 184 QHostInfoAgent *agent = theAgent(); 185 agent->addHostName(lookup, result); 186 187 #if !defined QT_NO_THREAD 188 if (!agent->isRunning()) 189 agent->start(); 189 return id; 190 } 191 192 /*! 193 Aborts the host lookup with the ID \a id, as returned by lookupHost(). 194 195 \sa lookupHost(), lookupId() 196 */ 197 void QHostInfo::abortHostLookup(int id) 198 { 199 #ifndef QT_NO_THREAD 200 theHostInfoLookupManager()->abortLookup(id); 190 201 #else 191 // if (!agent->isRunning()) 192 agent->run(); 193 // else 194 // agent->wakeOne(); 202 // we cannot abort if it was non threaded.. the result signal has already been posted 203 Q_UNUSED(id); 195 204 #endif 196 return id;197 }198 199 /*!200 Aborts the host lookup with the ID \a id, as returned by lookupHost().201 202 \sa lookupHost(), lookupId()203 */204 void QHostInfo::abortHostLookup(int id)205 {206 QHostInfoAgent *agent = theAgent();207 agent->abortLookup(id);208 205 } 209 206 … … 227 224 #endif 228 225 229 if (!name.isEmpty()) 230 return QHostInfoAgent::fromName(QLatin1String(QUrl::toAce(name))); 231 232 QHostInfo retval; 233 retval.d->err = HostNotFound; 234 retval.d->errorStr = QObject::tr("No host name given"); 235 return retval; 236 } 237 238 /*! 239 \internal 240 Pops a query off the queries list, performs a blocking call to 241 QHostInfoAgent::lookupHost(), and emits the resultsReady() 242 signal. This process repeats until the queries list is empty. 243 */ 244 void QHostInfoAgent::run() 245 { 246 #ifndef QT_NO_THREAD 247 // Dont' allow thread termination during event delivery, but allow it 248 // during the actual blocking host lookup stage. 249 setTerminationEnabled(false); 250 forever 251 #endif 252 { 253 QHostInfoQuery *query; 254 { 255 #ifndef QT_NO_THREAD 256 // the queries list is shared between threads. lock all 257 // access to it. 258 QMutexLocker locker(&mutex); 259 if (!quit && queries.isEmpty()) 260 cond.wait(&mutex); 261 if (quit) { 262 // Reset the quit variable in case QCoreApplication is 263 // destroyed and recreated. 264 quit = false; 265 break; 266 } 267 if (queries.isEmpty()) 268 continue; 269 #else 270 if (queries.isEmpty()) 271 return; 272 #endif 273 query = queries.takeFirst(); 274 pendingQueryId = query->object->lookupId; 275 } 276 277 #if defined(QHOSTINFO_DEBUG) 278 qDebug("QHostInfoAgent::run(%p): looking up \"%s\"", this, 279 query->hostName.toLatin1().constData()); 280 #endif 281 282 #ifndef QT_NO_THREAD 283 // Start query - allow termination at this point, but not outside. We 284 // don't want to all termination during event delivery, but we don't 285 // want the lookup to prevent the app from quitting (the agent 286 // destructor terminates the thread). 287 setTerminationEnabled(true); 288 #endif 289 QHostInfo info = fromName(query->hostName); 290 #ifndef QT_NO_THREAD 291 setTerminationEnabled(false); 292 #endif 293 294 int id = query->object->lookupId; 295 info.setLookupId(id); 296 if (pendingQueryId == id) 297 query->object->emitResultsReady(info); 298 delete query; 299 } 226 return QHostInfoAgent::fromName(name); 300 227 } 301 228 … … 328 255 */ 329 256 QHostInfo::QHostInfo(const QHostInfo &other) 330 : d(new QHostInfoPrivate(*other.d ))257 : d(new QHostInfoPrivate(*other.d)) 331 258 { 332 259 } … … 338 265 QHostInfo &QHostInfo::operator=(const QHostInfo &other) 339 266 { 340 *d = *other.d;267 *d; 341 268 return *this; 342 269 } … … 347 274 QHostInfo::~QHostInfo() 348 275 { 349 delete d;350 276 } 351 277 … … 477 403 */ 478 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 479 575 QT_END_NAMESPACE
Note:
See TracChangeset
for help on using the changeset viewer.