Results 1 to 2 of 2

Thread: QSqlDatabase Mysql timeout versus PortScanner

  1. #1
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QSqlDatabase Mysql timeout versus PortScanner

    Is here a other way to stop QSqlDatabase MYSQL driver after 300 ms second on not connect?

    I write this simple PortScanner and run ok ...
    but i suppose QSqlDatabase can handle this how?


    Qt Code:
    1. /* ShemaConnect = mysql://user:pass@host:port/databasename */
    2.  
    3. /*
    4. ScanPort *portcheck = new ScanPort();
    5. connect(portcheck, SIGNAL(result(int,int,bool)), this, SLOT(serveracess(int,int,bool)));
    6. portcheck->SetUrl(QUrl(ShemaConnect));
    7. portcheck->start(QThread::HighPriority);
    8. */
    9.  
    10.  
    11. class ScanPort : public QThread
    12. {
    13. Q_OBJECT
    14. public:
    15. void SetUrl( QUrl check_url , int maxtime = 300 , QObject * redirect = 0 )
    16. {
    17. url = check_url;
    18. receiver = redirect;
    19. Timeout = maxtime;
    20. setTerminationEnabled(true);
    21. }
    22. protected:
    23. void run()
    24. {
    25. QTime st = QTime::currentTime();
    26. m_Socket = new QTcpSocket();
    27. m_Socket->connectToHost(url.host(),url.port(),QIODevice::ReadOnly);
    28. if (m_Socket->waitForConnected(Timeout)) {
    29. if (m_Socket->waitForReadyRead(Timeout)) {
    30. qDebug() << "### connect ok port " << url.port();
    31. QTextStream *t = new QTextStream( m_Socket );
    32. t->setCodec(QTextCodec::codecForMib(106));
    33. int loops = 0;
    34. while (!t->atEnd()) {
    35. loops++;
    36. response = t->readLine();
    37. qDebug() << loops << " line " << response;
    38. }
    39. emit result(url.port(),runtime(st),true);
    40. quit();
    41. } else {
    42. m_Socket->close();
    43. qDebug() << "### connect nooo on port " << url.port();
    44. emit result(url.port(),runtime(st),false);
    45. quit();
    46. }
    47. } else {
    48. m_Socket->close();
    49. qDebug() << "### connect nooo on port " << url.port();
    50. emit result(url.port(),runtime(st),false);
    51. quit();
    52. }
    53. }
    54. int runtime( QTime go )
    55. {
    56. QTime now = QTime::currentTime();
    57. return go.msecsTo ( now );
    58. }
    59. signals:
    60. void result(int,int,bool); /* port , time , true = ok */
    61. private:
    62. QString response;
    63. int Timeout;
    64. QTcpSocket *m_Socket;
    65. uint millisecond;
    66. QUrl url;
    67. QObject* receiver;
    68. };
    To copy to clipboard, switch view to plain text mode 
    Last edited by patrik08; 21st May 2008 at 14:23.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QSqlDatabase Mysql timeout versus PortScanner

    Unfortunately you can't do much with MySQL driver. See QSqlDatabase::setConnectOptions().

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.