examples: ipcpipeline: do not use the linux-specific SOCK_NONBLOCK flag
authorGeorge Kiagiadakis <george.kiagiadakis@collabora.com>
Thu, 31 Aug 2017 12:07:45 +0000 (15:07 +0300)
committerGeorge Kiagiadakis <george.kiagiadakis@collabora.com>
Thu, 31 Aug 2017 12:09:24 +0000 (15:09 +0300)
Use fcntl() instead to set O_NONBLOCK, which is portable.

https://bugzilla.gnome.org/show_bug.cgi?id=786763

tests/examples/ipcpipeline/ipc-play.c
tests/examples/ipcpipeline/ipcpipeline1.c

index e41c07a..805bbcc 100644 (file)
@@ -610,10 +610,16 @@ on_pad_added (GstElement * element, GstPad * pad, GstElement * pipeline)
   g_signal_connect (pad, "unlinked", (GCallback) on_pad_unlinked, pipeline);
 
   if (create_sockets) {
-    if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, sockets)) {
+    if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets)) {
       fprintf (stderr, "Error creating sockets: %s\n", strerror (errno));
       exit (1);
     }
+    if (fcntl (sockets[0], F_SETFL, O_NONBLOCK) < 0 ||
+        fcntl (sockets[1], F_SETFL, O_NONBLOCK) < 0) {
+      fprintf (stderr, "Error setting O_NONBLOCK on sockets: %s\n",
+          strerror (errno));
+      exit (1);
+    }
     g_object_set (ipcpipelinesink, "fdin", sockets[0], "fdout", sockets[0],
         NULL);
 
index 4459f0f..df45c4a 100644 (file)
@@ -159,10 +159,17 @@ main (int argc, char **argv)
   int sockets[2];
   pid_t pid;
 
-  if (socketpair (AF_UNIX, SOCK_STREAM | SOCK_NONBLOCK, 0, sockets) < 0) {
+  if (socketpair (AF_UNIX, SOCK_STREAM, 0, sockets)) {
     fprintf (stderr, "Error creating sockets: %s\n", strerror (errno));
     return 1;
   }
+  if (fcntl (sockets[0], F_SETFL, O_NONBLOCK) < 0 ||
+      fcntl (sockets[1], F_SETFL, O_NONBLOCK) < 0) {
+    fprintf (stderr, "Error setting O_NONBLOCK on sockets: %s\n",
+        strerror (errno));
+    return 1;
+  }
+
   pid = fork ();
   if (pid < 0) {
     fprintf (stderr, "Error forking: %s\n", strerror (errno));