InterprocessConnection improvement


#1

I'm working on a streaming application where I need the reading of the StreamingSocket throttled (in order not to overflow my FIFO queue). 

Added method in juce_InterprocessConnection.h:


    /** Called to query if connection should be throttled. 

         Override this if you need to throttle the streaming of data.
    */
    virtual bool connectionThrottle() { return false; }

And implementation in juce_InterprocessConnection.cpp:

void InterprocessConnection::runThread()
{
    while (! thread->threadShouldExit())
    {
        if (socket != nullptr)
        {
            const int ready = socket->waitUntilReady (true, 0);
            if (ready < 0)
            {
                deletePipeAndSocket();
                connectionLostInt();
                break;
            }
            if (ready == 0 || connectionThrottle())
            {
                thread->wait (1);
                continue;
            }
        }
        else if (pipe != nullptr)
        {
            if (! pipe->isOpen())
            {
                deletePipeAndSocket();
                connectionLostInt();
                break;
            }
            if (connectionThrottle())
            {
                thread->wait (1);
                continue;
            }
        }
        else
        {
            break;
        }
        if (thread->threadShouldExit() || ! readNextMessageInt())
            break;
    }
}

When throttling is active, the sender side will stall until receiver is ready to accept more data.

 

 


#2

Hmm. Should this perhaps just be the default behaviour?

You'd rarely want to keep spamming the server with requests if it can't handle them fast enough..