Example #1
0
static void clientSocketRead(void *subject, const char *event, void *data, va_list args)
{
    LineServerClient *client = data;
    char *message = va_arg(args, char *);
    logTrace("Read message: %s", message);

    g_string_append(client->line_buffer, message);
    unsigned int added_lines = processClientBuffer(client);
    if (added_lines > 0) {
        LineServerCallback callback = client->server->callback;
        callback(client);
    }
}
Example #2
0
void Listener::readFromSocket()
{
    QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender());
    if (!socket) {
        return;
    }

    log("Reading from socket...");
    for (Client &client: m_connections) {
        if (client.socket == socket) {
            client.commandBuffer += socket->readAll();
            if (processClientBuffer(client) && !m_clientBufferProcessesTimer->isActive()) {
                // we have more client buffers to handle
                m_clientBufferProcessesTimer->start();
            }
            break;
        }
    }
}
Example #3
0
void Listener::readFromSocket()
{
    QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender());
    if (!socket) {
        return;
    }

    Console::main()->log("Reading from socket...");
    for (Client &client: m_connections) {
        if (client.socket == socket) {
            Console::main()->log(QString("    Client: %1").arg(client.name));
            client.commandBuffer += socket->readAll();
            // FIXME: schedule these rather than process them all at once
            //        right now this can lead to starvation of clients due to
            //        one overly active client
            while (processClientBuffer(client)) {}
            break;
        }
    }
}
Example #4
0
void Listener::processClientBuffers()
{
    //TODO: we should not process all clients, but iterate async over them and process
    //      one command from each in turn to ensure all clients get fair handling of
    //      commands?
    bool again = false;
    for (Client &client: m_connections) {
        if (!client.socket || !client.socket->isValid() || client.commandBuffer.isEmpty()) {
            continue;
        }

        if (processClientBuffer(client)) {
            again = true;
        }
    }

    if (again) {
        m_clientBufferProcessesTimer->start();
    }
}