]> git.alsa-project.org Git - alsa-plugins.git/commitdiff
jack: Fix hanging applications when using jack plugin
authorKevin Ross <kevin@familyross.net>
Thu, 4 Aug 2011 14:19:56 +0000 (16:19 +0200)
committerTakashi Iwai <tiwai@suse.de>
Thu, 4 Aug 2011 14:33:37 +0000 (16:33 +0200)
As described in issue #2727

   https://bugtrack.alsa-project.org/alsa-bug/view.php?id=2727

applications hang after some seconds when using the jack plugin.

Kevin Ross <kevin@familyross.net> writes:

   The cause: The plugin creates a pipe, so that the fd's could be
   polled to indicate completion of a transfer.  However, the call to
   write() blocks when playing audio, as nothing actually reads from the
   pipe, and it fills up until it blocks.

   Making the socket non-blocking fixes the problem, and testing with
   playback and capture both work properly for me now.

[Adrian: I've also tested Kevin's patch and confirm it works.]

Signed-off-by: Adrian Knoth <adi@drcomp.erfurt.thur.de>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
jack/pcm_jack.c

index 3370a26aa4ee2c6e56df3864db6f71a09fbf7e64..eb3359c3ab2bb1379c6ae2931664dcf207cecc20 100644 (file)
@@ -307,6 +307,19 @@ static int parse_ports(snd_pcm_jack_t *jack, snd_config_t *conf)
        return 0;
 }
 
+static int make_nonblock(int fd)
+{
+       int fl;
+
+       if ((fl = fcntl(fd, F_GETFL)) < 0)
+               return fl;
+
+       if (fl & O_NONBLOCK)
+               return 0;
+
+       return fcntl(fd, F_SETFL, fl | O_NONBLOCK);
+}
+
 static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name,
                             snd_config_t *playback_conf,
                             snd_config_t *capture_conf,
@@ -363,6 +376,9 @@ static int snd_pcm_jack_open(snd_pcm_t **pcmp, const char *name,
 
        socketpair(AF_LOCAL, SOCK_STREAM, 0, fd);
        
+       make_nonblock(fd[0]);
+       make_nonblock(fd[1]);
+
        jack->fd = fd[0];
 
        jack->io.version = SND_PCM_IOPLUG_VERSION;