Example #1
0
void qt_flushOutBuffer()
{
	if (!qt_initialized)
		return;

	// Write the block size at the beginning of the bock
	QDataStream sizeStream(&qt_socket);
	sizeStream << (quint32)(qt_outBuffer.size());
	// Write the block to the QLocalSocket
	qt_socket.write(qt_outBuffer);
	// waitForBytesWritten(-1) is supposed implement this loop, but it does not seem to work !
	// update: seems to work with Qt 4.5
	while (qt_socket.bytesToWrite() > 0)
	{
		qt_socket.flush();
		qt_socket.waitForBytesWritten(-1);
	}
	// Reset the buffer
	qt_out.device()->seek(0);
	qt_outBuffer.clear();
}
Example #2
0
static bool sendData(const QByteArray &out, QByteArray *in)
{
#if USE_LOCAL_SOCKETS
    QLocalSocket socket;
    socket.connectToServer("gdrdeamon");
#else
    QTcpSocket socket;
    socket.connectToHost("127.0.0.1", 15001);
#endif
    if (!socket.waitForConnected(1000))
        return false;

    qint32 size = out.size();
    socket.write((char*)&size, sizeof(qint32));
    socket.write(out);
    while (socket.bytesToWrite() && socket.waitForBytesWritten())
        ;

    while (socket.waitForReadyRead())
        in->append(socket.readAll());

    return true;
}