void AbstractSocket::connectPrivateSignals()
{

    // Used to manage socket expiration timeout
    // Expiration delay is reinit when a bytes is writted
    connect(this, SIGNAL(bytesWritten(qint64)),
            this, SLOT(onBytesWritten(qint64)));

    // Used to manage socket expiration timeout
    // Expiration delay is reinit when data are available is read
    connect(this, SIGNAL(readyRead()),
            this, SLOT(onReadyRead()));

    // Those next signals are used as debug, for now
    connect(this, SIGNAL(connected()),
            this, SLOT(onConnected()));
    connect(this, SIGNAL(disconnected()),
            this, SLOT(onDisconnected()));
    connect(this, SIGNAL(error ( QAbstractSocket::SocketError)),
            this, SLOT(onError ( QAbstractSocket::SocketError)));
    connect(this, SIGNAL(hostFound ()),
            this, SLOT(onHostFound ()));
    connect(this, SIGNAL(proxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator *)),
            this, SLOT(onProxyAuthenticationRequired ( const QNetworkProxy &, QAuthenticator *)));
    connect(this, SIGNAL(stateChanged (QAbstractSocket::SocketState)),
            this, SLOT(onStateChanged (QAbstractSocket::SocketState)));
    connect(this, SIGNAL(aboutToClose()),
            this, SLOT(onAboutToClose()));
    connect(this, SIGNAL(readChannelFinished()),
            this, SLOT(onReadChannelFinished()));
}
Esempio n. 2
0
void QIODeviceCopier::stop()
{
    disconnect(d->src, SIGNAL(readyRead()), d, SLOT(onReadyRead()));
    disconnect(d->src, SIGNAL(readChannelFinished()), d, SLOT(onReadChannelFinished()));

    Q_EMIT finished();
}
Esempio n. 3
0
void QIODeviceCopier::start()
{
    if(!d->src->isOpen()) {
        if(!d->src->open(QIODevice::ReadOnly)) {
            Q_EMIT error(tr("Unable to open source device for reading"));
            Q_EMIT finished();
            return;
        }
    }

    if(!d->dest->isOpen()) {
        if(!d->dest->open(QIODevice::WriteOnly)) {
            Q_EMIT error(tr("Unable to open destination device for writing"));
            Q_EMIT finished();
            return;
        }
    }

    // These signals cannot be connected in the constructor since they may
    // begin firing before the start() method is called

    // readyRead() and readChannelFinished() are only emitted for sequential
    // devices - for other types of devices, it is necessary to check atEnd()
    // in order to determine whether the end of the device has been reached
    connect(d->src, SIGNAL(readyRead()), d, SLOT(onReadyRead()));
    connect(d->src, SIGNAL(readChannelFinished()), d, SLOT(onReadChannelFinished()));

    // The first read from the device needs to be triggered
    QTimer::singleShot(0, d, d->src->isSequential() ? SLOT(onReadyRead()) : SLOT(nextBlock()));
}
Esempio n. 4
0
void QObjectHandler::process(QHttpSocket *socket, const QString &path)
{
    // Only POST requests are accepted - reject any other methods but ensure
    // that the Allow header is set in order to comply with RFC 2616
    if(socket->method() != "POST") {
        socket->setHeader("Allow", "POST");
        socket->writeError(QHttpSocket::MethodNotAllowed);
        return;
    }

    // Determine the index of the slot with the specified name - note that we
    // don't need to worry about retrieving the index for deleteLater() since
    // we specify the "QVariantMap" parameter type, which no parent slots use
    int index = metaObject()->indexOfSlot(QString("%1(QVariantMap)").arg(path).toUtf8().data());

    // If the index is invalid, the "resource" was not found
    if(index == -1) {
        socket->writeError(QHttpSocket::NotFound);
        return;
    }

    // Ensure that the return type of the slot is QVariantMap
    QMetaMethod method = metaObject()->method(index);
    if(method.returnType() != QMetaType::QVariantMap) {
        socket->writeError(QHttpSocket::InternalServerError);
        return;
    }

    // Check to see if the socket has finished receiving all of the data yet
    // or not - if so, jump to invokeSlot(), otherwise wait for the
    // readChannelFinished() signal
    if(socket->bytesAvailable() >= socket->contentLength()) {
        d->invokeSlot(socket, index);
    } else {

        // Add the socket and index to the map so that the latter can be
        // retrieved when the readChannelFinished() signal is emitted
        d->map.insert(socket, index);
        connect(socket, SIGNAL(readChannelFinished()), d, SLOT(onReadChannelFinished()));
    }
}