void QEventDispatcherBlackberry::unregisterSocketNotifier(QSocketNotifier *notifier)
{
    Q_D(QEventDispatcherBlackberry);

    int sockfd = notifier->socket();

    qEventDispatcherDebug << Q_FUNC_INFO << "fd =" << sockfd;

    if (Q_UNLIKELY(sockfd >= FD_SETSIZE)) {
        qWarning() << "QEventDispatcherBlackberry: cannot unregister QSocketNotifier" << sockfd;
        return;
    }

    // Allow the base Unix implementation to unregister the fd too (before call to ioEvents()!)
    QEventDispatcherUNIX::unregisterSocketNotifier(notifier);

    // Unregister the fd with bps
    BpsChannelScopeSwitcher channelSwitcher(d->bps_channel);
    int result = bps_remove_fd(sockfd);
    if (Q_UNLIKELY(result != BPS_SUCCESS))
        qWarning() << "QEventDispatcherBlackberry: bps_remove_fd failed" << sockfd;

    const int io_events = ioEvents(sockfd);
    // if other socket notifier is watching sockfd, readd it
    if (io_events) {
        result = bps_add_fd(sockfd, io_events, &bpsIOHandler, d->ioData.data());
        if (Q_UNLIKELY(result != BPS_SUCCESS))
            qWarning("QEventDispatcherBlackberry: bps_add_fd error");
    }
}
Exemplo n.º 2
0
void QEventDispatcherBlackberry::unregisterSocketNotifier(QSocketNotifier *notifier)
{
    // Allow the base Unix implementation to unregister the fd too
    QEventDispatcherUNIX::unregisterSocketNotifier(notifier);

    // Unregister the fd with bps
    int sockfd = notifier->socket();

    const int io_events = ioEvents(sockfd);

    int result = bps_remove_fd(sockfd);
    if (result != BPS_SUCCESS)
        qWarning() << Q_FUNC_INFO << "bps_remove_fd() failed" << sockfd;


    /* if no other socket notifier is
     * watching sockfd, our job ends here
     */
    if (!io_events)
        return;

    Q_D(QEventDispatcherBlackberry);

    errno = 0;
    result = bps_add_fd(sockfd, io_events, &bpsIOHandler, d->ioData.data());
    if (result != BPS_SUCCESS) {
        qWarning() << Q_FUNC_INFO << "bps_add_fd() failed" << strerror(errno) << "code:" << errno;
    }
}
void QEventDispatcherBlackberry::registerSocketNotifier(QSocketNotifier *notifier)
{
    Q_ASSERT(notifier);
    Q_D(QEventDispatcherBlackberry);

    int sockfd = notifier->socket();
    int type = notifier->type();

    qEventDispatcherDebug << Q_FUNC_INFO << "fd =" << sockfd;

    if (Q_UNLIKELY(sockfd >= FD_SETSIZE)) {
        qWarning() << "QEventDispatcherBlackberry: cannot register QSocketNotifier (fd too high)"
                   << sockfd;
        return;
    }

    // Register the fd with bps
    BpsChannelScopeSwitcher channelSwitcher(d->bps_channel);
    int io_events = ioEvents(sockfd);
    if (io_events)
        bps_remove_fd(sockfd);

    switch (type) {
    case QSocketNotifier::Read:
        qEventDispatcherDebug << "Registering" << sockfd << "for Reads";
        io_events |= BPS_IO_INPUT;
        break;
    case QSocketNotifier::Write:
        qEventDispatcherDebug << "Registering" << sockfd << "for Writes";
        io_events |= BPS_IO_OUTPUT;
        break;
    case QSocketNotifier::Exception:
    default:
        qEventDispatcherDebug << "Registering" << sockfd << "for Exceptions";
        io_events |= BPS_IO_EXCEPT;
        break;
    }

    const int result = bps_add_fd(sockfd, io_events, &bpsIOHandler, d->ioData.data());
    if (Q_UNLIKELY(result != BPS_SUCCESS))
        qWarning() << "QEventDispatcherBlackberry: bps_add_fd failed";

    // Call the base Unix implementation. Needed to allow select() to be called correctly
    QEventDispatcherUNIX::registerSocketNotifier(notifier);
}
Exemplo n.º 4
0
void QEventDispatcherBlackberry::registerSocketNotifier(QSocketNotifier *notifier)
{
    Q_ASSERT(notifier);

    // Register the fd with bps
    int sockfd = notifier->socket();
    int type = notifier->type();

    int io_events = ioEvents(sockfd);

    if (io_events)
        bps_remove_fd(sockfd);

    // Call the base Unix implementation. Needed to allow select() to be called correctly
    QEventDispatcherUNIX::registerSocketNotifier(notifier);

    switch (type) {
    case QSocketNotifier::Read:
        io_events |= BPS_IO_INPUT;
        break;
    case QSocketNotifier::Write:
        io_events |= BPS_IO_OUTPUT;
        break;
    case QSocketNotifier::Exception:
    default:
        io_events |= BPS_IO_EXCEPT;
        break;
    }

    Q_D(QEventDispatcherBlackberry);

    errno = 0;
    int result = bps_add_fd(sockfd, io_events, &bpsIOHandler, d->ioData.data());

    if (result != BPS_SUCCESS)
        qWarning() << Q_FUNC_INFO << "bps_add_fd() failed" << strerror(errno) << "code:" << errno;
}
Exemplo n.º 5
0
int QEventDispatcherBlackberry::select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds,
                                       timeval *timeout)
{
    Q_UNUSED(nfds);

    // prepare file sets for bps callback
    Q_D(QEventDispatcherBlackberry);
    d->ioData->count = 0;
    d->ioData->readfds = readfds;
    d->ioData->writefds = writefds;
    d->ioData->exceptfds = exceptfds;

    // \TODO Remove this when bps is fixed
    //
    // Work around a bug in BPS with which if we register the thread_pipe[0] fd with bps in the
    // private class' ctor once only then we get spurious notifications that thread_pipe[0] is
    // ready for reading. The first time the notification is correct and the pipe is emptied in
    // the calling doSelect() function. The 2nd notification is an error and the resulting attempt
    // to read and call to wakeUps.testAndSetRelease(1, 0) fails as there has been no intervening
    // call to QEventDispatcherUNIX::wakeUp().
    //
    // Registering thread_pipe[0] here and unregistering it at the end of this call works around
    // this issue.
    int io_events = BPS_IO_INPUT;
    int result = bps_add_fd(d->thread_pipe[0], io_events, &bpsIOHandler, d->ioData.data());
    if (result != BPS_SUCCESS)
        qWarning() << Q_FUNC_INFO << "bps_add_fd() failed";

    // reset all file sets
    if (readfds)
        FD_ZERO(readfds);

    if (writefds)
        FD_ZERO(writefds);

    if (exceptfds)
        FD_ZERO(exceptfds);

    // convert timeout to milliseconds
    int timeout_ms = -1;
    if (timeout)
        timeout_ms = (timeout->tv_sec * 1000) + (timeout->tv_usec / 1000);

    QElapsedTimer timer;
    timer.start();

    do {
        // wait for event or file to be ready
        bps_event_t *event = NULL;

        // \TODO Remove this when bps is fixed
        // BPS has problems respecting timeouts.
        // Replace the bps_get_event statement
        // with the following commented version
        // once bps is fixed.
        // result = bps_get_event(&event, timeout_ms);
        result = bps_get_event(&event, 0);

        if (result != BPS_SUCCESS)
            qWarning("QEventDispatcherBlackberry::select: bps_get_event() failed");

        if (!event)
            break;

        // pass all received events through filter - except IO ready events
        if (event && bps_event_get_domain(event) != bpsIOReadyDomain)
            filterEvent((void*)event);
    } while (timer.elapsed() < timeout_ms);

    // \TODO Remove this when bps is fixed (see comment above)
    result = bps_remove_fd(d->thread_pipe[0]);
    if (result != BPS_SUCCESS)
        qWarning() << Q_FUNC_INFO << "bps_remove_fd() failed";

    // the number of bits set in the file sets
    return d->ioData->count;
}