Changeset 83


Ignore:
Timestamp:
Jul 24, 2009, 2:31:38 AM (16 years ago)
Author:
Dmitry A. Kuminov
Message:

corelib: Implemented socket notifiers (#24).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/corelib/kernel/qeventdispatcher_pm.cpp

    r67 r83  
    4646#include "qcoreapplication.h"
    4747#include "qhash.h"
    48 #include "qlibrary.h"
    49 #include "qpair.h"
    50 #include "qset.h"
    5148#include "qsocketnotifier.h"
    52 #include "qvarlengtharray.h"
     49#include "qmutex.h"
     50#include "qwaitcondition.h"
    5351
    5452#include "qabstracteventdispatcher_p.h"
     
    5957
    6058#include <Qt/qwindowdefs_pm.h> // for QPMObjectWindow declaration
     59
     60
    6161
    6262QT_BEGIN_NAMESPACE
     
    152152*/
    153153
    154 /// @todo remove?
    155 // returns HMQ of the current thread or NULL if no event queue has been created
    156 static HMQ qt_WinQueryQueue(HAB hab)
    157 {
    158     PTIB ptib;
    159     PPIB ppib;
    160     DosGetInfoBlocks(&ptib, &ppib);
    161     return WinQueueFromID(hab, ppib->pib_ulpid, ptib->tib_ptib2->tib2_ultid);
    162 }
    163 
    164154/*!
    165155    Constructs a new object window for the current thread.
     
    263253
    264254/*!
    265   \fn QPMObjectWindow::send(ULONG msg, MPARAM mp1, MPARAM mp2) const
    266 
    267   Synchronously sends a message \a msg with the given parameters \a mp1 and
    268   \a mp2 to this window handle and returns a reply from the message() function.
    269 
    270   \note Must be called on the same thread that cosnstructed this instance.
     255  \fn QPMObjectWindow::send(ULONG msg, MPARAM mp1, MPARAM mp2) const
     256
     257  Synchronously sends a message \a msg with the given parameters \a mp1 and
     258  \a mp2 to this window handle and returns a reply from the message() function.
     259
     260  \note Must be called on the same thread that cosnstructed this instance.
    271261*/
    272262
    273263/*!
    274   \fn QPMObjectWindow::post(ULONG msg, MPARAM mp1, MPARAM mp2) const
    275 
    276   Asynchronously posts a message \a msg with the given parameters \a mp1 and
    277   \a mp2 to this window handle. Returns \c TRUE on success and \c FALSE
    278   otherwise.
    279 
    280   \note Can be called on any thread.
     264  \fn QPMObjectWindow::post(ULONG msg, MPARAM mp1, MPARAM mp2) const
     265
     266  Asynchronously posts a message \a msg with the given parameters \a mp1 and
     267 
     268  otherwise.
     269
     270  \note Can be called on any thread.
    281271*/
     272
    282273
    283274// socket select notification (highest priority)
     
    285276// zero timer notification (lowest priority)
    286277#define WM_U_SEM_ZEROTIMER  WM_SEM4
     278
     279
     280
     281
     282
     283
     284
     285
     286
     287
     288
     289
     290
     291
     292
     293
     294
     295
     296
     297
     298
     299
     300
     301
     302
     303
     304
     305
     306
     307
     308
     309
     310
     311
     312
     313
     314
     315
     316
     317
     318
     319
     320
     321
     322
     323
     324
     325
     326
     327
     328
     329
     330
     331
     332
     333
     334
     335
     336
     337
     338
     339
     340
     341
     342
     343
     344
     345
     346
     347
     348
     349
     350
     351
     352
     353
     354
     355
     356
     357
     358
     359
     360
     361
     362
     363
     364
     365
     366
     367
     368
     369
     370
     371
     372
     373
     374
     375
     376
     377
     378
     379
     380
     381
     382
     383
     384
     385
     386
     387
     388
     389
     390
     391
     392
     393
     394
     395
     396
     397
     398
     399
     400
     401
     402
     403
     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
     575
     576
     577
     578
     579
     580
     581
     582
     583
    287584
    288585class QEventDispatcherPMPrivate : public QAbstractEventDispatcherPrivate
     
    318615
    319616// @todo later
    320 //  DWORD threadId;
    321 //
    322 //  bool interrupt;
    323 //
    324 //  // internal window handle used for socketnotifiers/timers/etc
    325 //  HWND internalHwnd;
    326617//
    327618//  // timers
     
    331622//  void unregisterTimer(WinTimerInfo *t);
    332623//  void sendTimerEvent(int timerId);
    333 //
    334 //  // socket notifiers
    335 //  QSNDict sn_read;
    336 //  QSNDict sn_write;
    337 //  QSNDict sn_except;
    338 //  void doWsaAsyncSelect(int socket);
    339624//
    340625//  QList<QMSG> queuedUserInputEvents;
     
    399684    switch (msg) {
    400685        case WM_U_SEM_SELECT: {
    401 // @todo later
    402 //          if (eventLoop)
    403 //              eventLoop->activateSocketNotifiers();
     686            QSocketNotifier *notifier =
     687                QSockSelectThread::getSocketNotifier(LONGFROMMP(mp1));
     688                if (notifier) {
     689                    QEvent event(QEvent::SockAct);
     690                    QCoreApplication::sendEvent(notifier, &event);
     691                }
    404692            break;
    405693        }
     
    575863}
    576864
    577 void QEventDispatcherPMPrivate::doWsaAsyncSelect(int socket)
    578 {
    579     Q_ASSERT(internalHwnd);
    580     int sn_event = 0;
    581     if (sn_read.contains(socket))
    582         sn_event |= FD_READ | FD_CLOSE | FD_ACCEPT;
    583     if (sn_write.contains(socket))
    584         sn_event |= FD_WRITE | FD_CONNECT;
    585     if (sn_except.contains(socket))
    586         sn_event |= FD_OOB;
    587     // BoundsChecker may emit a warning for WSAAsyncSelect when sn_event == 0
    588     // This is a BoundsChecker bug and not a Qt bug
    589     WSAAsyncSelect(socket, internalHwnd, sn_event ? WM_USER : 0, sn_event);
    590 }
    591 
    592865void QEventDispatcherPM::createInternalHwnd()
    593866{
     
    624897bool QEventDispatcherPM::processEvents(QEventLoop::ProcessEventsFlags flags)
    625898{
    626     Q_D(QEventDispatcherPM);
    627 
    628899// @todo later
    629900#if 0
     901
     902
    630903    if (!d->internalHwnd)
    631904        createInternalHwnd();
     
    7321005void QEventDispatcherPM::registerSocketNotifier(QSocketNotifier *notifier)
    7331006{
    734 // @todo later
    735 #if 0
    7361007    Q_ASSERT(notifier);
     1008
    7371009    int sockfd = notifier->socket();
    738     int type = notifier->type();
    739 #ifndef QT_NO_DEBUG
    740     if (sockfd < 0) {
     1010    if (sockfd < 0
     1011        || unsigned(sockfd) >= FD_SETSIZE) {
    7411012        qWarning("QSocketNotifier: Internal error");
    7421013        return;
    743     } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
     1014    } else if (notifier->thread() != thread()
     1015               || thread() != QThread::currentThread()) {
    7441016        qWarning("QSocketNotifier: socket notifiers cannot be enabled from another thread");
    7451017        return;
     
    7481020
    7491021    Q_D(QEventDispatcherPM);
    750     QSNDict *sn_vec[3] = { &d->sn_read, &d->sn_write, &d->sn_except };
    751     QSNDict *dict = sn_vec[type];
    752 
    753     if (QCoreApplication::closingDown()) // ### d->exitloop?
    754         return; // after sn_cleanup, don't reinitialize.
    755 
    756     if (dict->contains(sockfd)) {
    757         const char *t[] = { "Read", "Write", "Exception" };
    758     /* Variable "socket" below is a function pointer. */
    759         qWarning("QSocketNotifier: Multiple socket notifiers for "
    760                  "same socket %d and type %s", sockfd, t[type]);
    761     }
    762 
    763     QSockNot *sn = new QSockNot;
    764     sn->obj = notifier;
    765     sn->fd  = sockfd;
    766     dict->insert(sn->fd, sn);
    767 
    768     if (d->internalHwnd)
    769         d->doWsaAsyncSelect(sockfd);
    770 #endif
     1022    d->createAuxWnd();
     1023
     1024    QSockSelectThread::addSelect(notifier, d->auxWnd.hwnd());
    7711025}
    7721026
    7731027void QEventDispatcherPM::unregisterSocketNotifier(QSocketNotifier *notifier)
    7741028{
    775 // @todo later
    776 #if 0
    7771029    Q_ASSERT(notifier);
     1030
    7781031    int sockfd = notifier->socket();
    779     int type = notifier->type();
    780 #ifndef QT_NO_DEBUG
    781     if (sockfd < 0) {
     1032    if (sockfd < 0
     1033        || unsigned(sockfd) >= FD_SETSIZE) {
    7821034        qWarning("QSocketNotifier: Internal error");
    7831035        return;
    784     } else if (notifier->thread() != thread() || thread() != QThread::currentThread()) {
     1036    } else if (notifier->thread() != thread()
     1037               || thread() != QThread::currentThread()) {
    7851038        qWarning("QSocketNotifier: socket notifiers cannot be disabled from another thread");
    7861039        return;
     
    7881041#endif
    7891042
    790     Q_D(QEventDispatcherPM);
    791     QSNDict *sn_vec[3] = { &d->sn_read, &d->sn_write, &d->sn_except };
    792     QSNDict *dict = sn_vec[type];
    793     QSockNot *sn = dict->value(sockfd);
    794     if (!sn)
    795         return;
    796 
    797     dict->remove(sockfd);
    798     delete sn;
    799 
    800     if (d->internalHwnd)
    801         d->doWsaAsyncSelect(sockfd);
    802 #endif
     1043    QSockSelectThread::removeSelect(notifier);
    8031044}
    8041045
     
    9441185void QEventDispatcherPM::startingUp()
    9451186{
     1187
    9461188}
    9471189
    9481190void QEventDispatcherPM::closingDown()
    9491191{
    950     Q_D(QEventDispatcherPM);
     1192    Q);
    9511193
    9521194// @todo remove later
    9531195#if 0
    954     // clean up any socketnotifiers
    955     while (!d->sn_read.isEmpty())
    956         unregisterSocketNotifier((*(d->sn_read.begin()))->obj);
    957     while (!d->sn_write.isEmpty())
    958         unregisterSocketNotifier((*(d->sn_write.begin()))->obj);
    959     while (!d->sn_except.isEmpty())
    960         unregisterSocketNotifier((*(d->sn_except.begin()))->obj);
     1196    Q_D(QEventDispatcherPM);
    9611197
    9621198    // clean up any timers
Note: See TracChangeset for help on using the changeset viewer.