]> git.ipfire.org Git - thirdparty/shairport-sync.git/commitdiff
Improve error reporting if pipe can't be opened or written to.
authorMike Brady <mikebrady@eircom.net>
Fri, 7 Apr 2017 17:33:05 +0000 (18:33 +0100)
committerMike Brady <mikebrady@eircom.net>
Fri, 7 Apr 2017 17:33:05 +0000 (18:33 +0100)
audio_pipe.c

index 22cac67225d7dbf118a1b1aac10b740a0a26bade..9b7d75c7607a89efae5de793b99bd4d5ccb88476 100644 (file)
 static int fd = -1;
 
 char *pipename = NULL;
+int warned = 0;
 
 static void start(int sample_rate, int sample_format) {
   // this will leave fd as -1 if a reader hasn't been attached
   fd = open(pipename, O_WRONLY | O_NONBLOCK);
+  if ((fd<-1) && (warned==0)) {
+    warn("Error %d opening the pipe named \"%s\".",errno,pipename);
+    warned = 1;
+  }
 }
 
 static void play(short buf[], int samples) {
   // if the file is not open, try to open it.
+  char errorstring[1024];
   if (fd == -1) {
     fd = open(pipename, O_WRONLY | O_NONBLOCK);
   }
   // if it's got a reader, write to it.
-  if (fd != -1) {
-    int ignore = non_blocking_write(fd, buf, samples * 4);
-  }
+  if (fd > 0) {
+    int rc = non_blocking_write(fd, buf, samples * 4);
+    if ((rc<0) && (warned==0)) {
+      strerror_r(errno,(char*)errorstring,1024);
+      warn("Error %d writing to the pipe named \"%s\": \"%s\".",errno,pipename,errorstring);
+      warned = 1;
+    }
+  } else if ((fd == -1) && (warned==0)) {
+    strerror_r(errno,(char*)errorstring,1024);
+    warn("Error %d opening the pipe named \"%s\": \"%s\".",errno,pipename,errorstring);
+    warned = 1;
+   }
 }
 
 static void stop(void) {