- Timestamp:
- Sep 5, 2006, 1:09:16 AM (19 years ago)
- Location:
- psi/trunk/cutestuff/network
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
psi/trunk/cutestuff/network/ndns.cpp
r2 r12 48 48 //! QString ip_address = dns.resultString(); 49 49 //! \endcode 50 //! 51 //! \note The MAP_NDNS_TO_QDNS macro can be used to use QDns to implement the 52 //! NDns functionality. This is a but stupid, because it is supposed that if 53 //! NO_NDNS macro is defined, QDns is directly used instead of NDns in the 54 //! relevant sources. However, I (dmik) couln't get the DNS resolver working 55 //! when NO_NDNS is defined and was too lazy to debug why. The reason for using 56 //! QDns instead of NDns is pretty simple: it's impossible to cancel the async 57 //! gethostbyname() request executed on a worker thread (for example, during 58 //! application termination). As a result, in case of a lost connection (or 59 //! whatever), Psi won't close until the gethostbyname() timeout expires which 60 //! can take quite a while on OS/2. On the other hand, QDns is fully asynchronus 61 //! there, so NDns is absolutely not necessary. 50 62 51 63 #include"ndns.h" … … 56 68 #include<qeventloop.h> 57 69 58 #ifdef Q_OS_UNIX 70 #if !defined(MAP_NDNS_TO_QDNS) 71 72 #if defined(Q_OS_UNIX) || defined(Q_OS_OS2) 59 73 #include<netdb.h> 60 74 #include<sys/types.h> … … 67 81 #endif 68 82 83 #endif 84 69 85 // CS_NAMESPACE_BEGIN 86 87 #if defined(MAP_NDNS_TO_QDNS) 88 89 // dummy methods necessary because MOC doesn't understand #ifdefs and such 90 NDnsManager::NDnsManager() {} 91 NDnsManager::~NDnsManager() {} 92 bool NDnsManager::event(QEvent *e) { return false; } 93 void NDnsManager::app_aboutToQuit() {} 94 95 #else // !MAP_NDNS_TO_QDNS 70 96 71 97 //! \if _hide_doc_ … … 248 274 } 249 275 276 #endif // !MAP_NDNS_TO_QDNS 277 250 278 251 279 //---------------------------------------------------------------------------- … … 261 289 :QObject(parent) 262 290 { 291 #if defined(MAP_NDNS_TO_QDNS) 292 connect(&qdns, SIGNAL(resultsReady()), this, SIGNAL(resultsReady())); 293 #endif 263 294 } 264 295 … … 267 298 NDns::~NDns() 268 299 { 300 #if !defined(MAP_NDNS_TO_QDNS) 269 301 stop(); 302 #endif 270 303 } 271 304 … … 274 307 void NDns::resolve(const QString &host) 275 308 { 309 #if defined(MAP_NDNS_TO_QDNS) 310 qdns.setLabel(host); 311 if (qdns.recordType() != QDns::A) 312 qdns.setRecordType(QDns::A); 313 #else 276 314 stop(); 277 315 if(!man) 278 316 man = new NDnsManager; 279 317 man->resolve(this, host); 318 #endif 280 319 } 281 320 … … 285 324 void NDns::stop() 286 325 { 326 #if defined(MAP_NDNS_TO_QDNS) 327 qdns.setRecordType(QDns::None); 328 #else 287 329 if(man) 288 330 man->stop(this); 331 #endif 289 332 } 290 333 … … 294 337 uint NDns::result() const 295 338 { 339 #if defined(MAP_NDNS_TO_QDNS) 340 QHostAddress addr; 341 QValueList<QHostAddress> list = qdns.addresses(); 342 if (!list.isEmpty()) 343 addr = list.first(); 296 344 return addr.ip4Addr(); 345 #else 346 return addr.ip4Addr(); 347 #endif 297 348 } 298 349 … … 302 353 QString NDns::resultString() const 303 354 { 355 #if defined(MAP_NDNS_TO_QDNS) 356 QHostAddress addr; 357 QValueList<QHostAddress> list = qdns.addresses(); 358 if (!list.isEmpty()) 359 addr = list.first(); 304 360 return addr.toString(); 361 #else 362 return addr.toString(); 363 #endif 305 364 } 306 365 … … 309 368 bool NDns::isBusy() const 310 369 { 370 #if defined(MAP_NDNS_TO_QDNS) 371 return qdns.isWorking(); 372 #else 311 373 if(!man) 312 374 return false; 313 375 return man->isBusy(this); 314 } 376 #endif 377 } 378 379 #if !defined(MAP_NDNS_TO_QDNS) 315 380 316 381 void NDns::finished(const QHostAddress &a) … … 374 439 } 375 440 441 #endif // !MAP_NDNS_TO_QDNS 442 376 443 // CS_NAMESPACE_END -
psi/trunk/cutestuff/network/ndns.h
r2 r12 28 28 #include<qhostaddress.h> 29 29 30 #if defined(MAP_NDNS_TO_QDNS) 31 #include <qdns.h> 32 #endif 33 30 34 // CS_NAMESPACE_BEGIN 31 35 36 #if !defined(MAP_NDNS_TO_QDNS) 32 37 class NDnsWorker; 33 38 class NDnsManager; 39 #endif 34 40 35 41 class NDns : public QObject … … 51 57 52 58 private: 59 #if defined(MAP_NDNS_TO_QDNS) 60 QDns qdns; 61 #else 53 62 QHostAddress addr; 54 63 55 64 friend class NDnsManager; 56 65 void finished(const QHostAddress &); 66 #endif 57 67 }; 58 68
Note:
See TracChangeset
for help on using the changeset viewer.