Пример #1
0
/*!
    \internal
    Reads data from the socket into the readbuffer
 */
void QLocalSocketPrivate::startAsyncRead()
{
    do {
        DWORD bytesToRead = checkPipeState();
        if (pipeClosed)
            return;

        if (bytesToRead == 0) {
            // There are no bytes in the pipe but we need to
            // start the overlapped read with some buffer size.
            bytesToRead = initialReadBufferSize;
        }

        if (readBufferMaxSize && bytesToRead > (readBufferMaxSize - readBuffer.size())) {
            bytesToRead = readBufferMaxSize - readBuffer.size();
            if (bytesToRead == 0) {
                // Buffer is full. User must read data from the buffer
                // before we can read more from the pipe.
                return;
            }
        }

        char *ptr = readBuffer.reserve(bytesToRead);

        readSequenceStarted = true;
        if (ReadFile(handle, ptr, bytesToRead, NULL, &overlapped)) {
            completeAsyncRead();
        } else {
            switch (GetLastError()) {
                case ERROR_IO_PENDING:
                    // This is not an error. We're getting notified, when data arrives.
                    return;
                case ERROR_MORE_DATA:
                    // This is not an error. The synchronous read succeeded.
                    // We're connected to a message mode pipe and the message
                    // didn't fit into the pipe's system buffer.
                    completeAsyncRead();
                    break;
                case ERROR_PIPE_NOT_CONNECTED:
                    {
                        // It may happen, that the other side closes the connection directly
                        // after writing data. Then we must set the appropriate socket state.
                        pipeClosed = true;
                        Q_Q(QLocalSocket);
                        emit q->readChannelFinished();
                        return;
                    }
                default:
                    setErrorString(QLatin1String("QLocalSocketPrivate::startAsyncRead"));
                    return;
            }
        }
    } while (!readSequenceStarted);
}
Пример #2
0
void QLocalSocketPrivate::_q_notified()
{
    Q_Q(QLocalSocket);
    if (!completeAsyncRead()) {
        pipeClosed = true;
        emit q->readChannelFinished();
        return;
    }
    startAsyncRead();
    pendingReadyRead = false;
    emit q->readyRead();
}
Пример #3
0
void QLocalSocketPrivate::_q_notified()
{
    Q_Q(QLocalSocket);
    if (!completeAsyncRead()) {
        pipeClosed = true;
        emit q->readChannelFinished();
        if (actualReadBufferSize == 0)
            QTimer::singleShot(0, q, SLOT(_q_pipeClosed()));
        return;
    }
    startAsyncRead();
    pendingReadyRead = false;
    emit q->readyRead();
}