examples: ipcpipeline: do not use the linux-specific SOCK_NONBLOCK flag

Use fcntl() instead to set O_NONBLOCK, which is portable.

https://bugzilla.gnome.org/show_bug.cgi?id=786763
This commit is contained in:
George Kiagiadakis 2017-08-31 15:07:45 +03:00
parent 282b682cab
commit 4e239a6632
2 changed files with 15 additions and 2 deletions

View 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);

View 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));