[gst-cvs] gst-plugins-bad: shm: Try alternate paths for the socket
Olivier Crête
tester at kemper.freedesktop.org
Thu Jun 3 12:28:16 PDT 2010
Module: gst-plugins-bad
Branch: master
Commit: 7e8eae9f2abf4352a8d9b65a3277e1ced877e2bd
URL: http://cgit.freedesktop.org/gstreamer/gst-plugins-bad/commit/?id=7e8eae9f2abf4352a8d9b65a3277e1ced877e2bd
Author: Olivier Crête <olivier.crete at collabora.co.uk>
Date: Tue Jan 26 12:32:56 2010 +0200
shm: Try alternate paths for the socket
---
gst/shm/shmpipe.c | 20 +++++++++++++++++---
gst/shm/shmpipe.h | 1 +
2 files changed, 18 insertions(+), 3 deletions(-)
diff --git a/gst/shm/shmpipe.c b/gst/shm/shmpipe.c
index 6f4a867..f7619b7 100644
--- a/gst/shm/shmpipe.c
+++ b/gst/shm/shmpipe.c
@@ -166,6 +166,7 @@ sp_writer_create (const char *path, size_t size, mode_t perms)
ShmPipe *self = spalloc_new (ShmPipe);
int flags;
struct sockaddr_un sun;
+ int i = 0;
memset (self, 0, sizeof (ShmPipe));
@@ -188,12 +189,19 @@ sp_writer_create (const char *path, size_t size, mode_t perms)
sun.sun_family = AF_UNIX;
strncpy (sun.sun_path, path, sizeof (sun.sun_path));
- if (bind (self->main_socket, (struct sockaddr *) &sun,
+ while (bind (self->main_socket, (struct sockaddr *) &sun,
sizeof (struct sockaddr_un)) < 0) {
- RETURN_ERROR ("bind() failed (%d): %s\n", errno, strerror (errno));
+ if (errno != EADDRINUSE)
+ RETURN_ERROR ("bind() failed (%d): %s\n", errno, strerror (errno));
+
+ if (i > 256)
+ RETURN_ERROR ("Could not find a free socket name for %s", path);
+
+ snprintf (sun.sun_path, sizeof (sun.sun_path), "%s.%d", path, i);
+ i++;
}
- self->socket_path = strdup (path);
+ self->socket_path = strdup (sun.sun_path);
if (listen (self->main_socket, 10) < 0) {
RETURN_ERROR ("listen() failed (%d): %s\n", errno, strerror (errno));
@@ -809,3 +817,9 @@ sp_writer_pending_writes (ShmPipe * self)
{
return (self->buffers != NULL);
}
+
+const char *
+sp_writer_get_path (ShmPipe *pipe)
+{
+ return pipe->socket_path;
+}
diff --git a/gst/shm/shmpipe.h b/gst/shm/shmpipe.h
index f9a4afa..ed23d20 100644
--- a/gst/shm/shmpipe.h
+++ b/gst/shm/shmpipe.h
@@ -47,6 +47,7 @@ typedef struct _ShmPipe ShmPipe;
typedef struct _ShmBlock ShmBlock;
ShmPipe *sp_writer_create (const char *path, size_t size, mode_t perms);
+const char *sp_writer_get_path (ShmPipe *pipe);
void sp_close (ShmPipe * self);
void sp_writer_setperms_shm (ShmPipe * self, mode_t perms);
More information about the Gstreamer-commits
mailing list