Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ea3e54b authored by Mikhail Naganov's avatar Mikhail Naganov
Browse files

MIDI: Use server-side socket in blocking mode for virtual devices

Since virtual MIDI servers may misbehave, blocking mode will throttle
them if clients are not coping with their sending speed.

Bug: 29413812
Change-Id: I9c4a2a7a7ea3ea060c93fedc7d0f033427c557c9
parent b5bf7ee0
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -226,10 +226,12 @@ public final class MidiDeviceServer implements Closeable {
                ParcelFileDescriptor[] pair = ParcelFileDescriptor.createSocketPair(
                                                    OsConstants.SOCK_SEQPACKET);
                MidiInputPort inputPort = new MidiInputPort(pair[0], portNumber);
                // Configure the server-side socket in non-blocking mode to avoid stalling
                // the entire MIDI framework if client app code gets stuck inside 'onSend'
                // handler.
                // Undo the default blocking-mode of the server-side socket for
                // physical devices to avoid stalling the Java device handler if
                // client app code gets stuck inside 'onSend' handler.
                if (mDeviceInfo.getType() != MidiDeviceInfo.TYPE_VIRTUAL) {
                    IoUtils.setBlocking(pair[0].getFileDescriptor(), false);
                }
                MidiDispatcher dispatcher = mOutputPortDispatchers[portNumber];
                synchronized (dispatcher) {
                    dispatcher.getSender().connect(inputPort);