summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorYouness Alaoui <youness.alaoui@collabora.co.uk>2010-10-20 21:41:15 +0200
committerOlivier CrĂȘte <olivier.crete@collabora.co.uk>2010-11-24 19:12:10 -0500
commit768319b86623477a3658b448d01f5cc332cbf818 (patch)
tree2d4954cbc9b3ebf1b9a6057b5ed0d398ae168fb9 /sys
parenta7b27bc2d094582c91c77f91b5198686e8a86775 (diff)
downloadgstreamer-plugins-bad-768319b86623477a3658b448d01f5cc332cbf818.tar.gz
shm: stylist improvements
Diffstat (limited to 'sys')
-rw-r--r--sys/shm/shmpipe.c39
1 files changed, 20 insertions, 19 deletions
diff --git a/sys/shm/shmpipe.c b/sys/shm/shmpipe.c
index 58d3cd6cc..aa868ae04 100644
--- a/sys/shm/shmpipe.c
+++ b/sys/shm/shmpipe.c
@@ -41,6 +41,8 @@
#include <sys/mman.h>
#include <assert.h>
+#include "shmalloc.h"
+
/*
* The protocol over the pipe is in packets
*
@@ -65,7 +67,7 @@
*/
-#include "shmalloc.h"
+#define LISTEN_BACKLOG 10
enum
{
@@ -195,19 +197,16 @@ sp_writer_create (const char *path, size_t size, mode_t perms)
self->main_socket = socket (PF_UNIX, SOCK_STREAM, 0);
- if (self->main_socket < 0) {
+ if (self->main_socket < 0)
RETURN_ERROR ("Could not create socket (%d): %s\n", errno,
strerror (errno));
- }
flags = fcntl (self->main_socket, F_GETFL, 0);
- if (flags < 0) {
+ if (flags < 0)
RETURN_ERROR ("fcntl(F_GETFL) failed (%d): %s\n", errno, strerror (errno));
- }
- if (fcntl (self->main_socket, F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0) {
+ if (fcntl (self->main_socket, F_SETFL, flags | O_NONBLOCK | FD_CLOEXEC) < 0)
RETURN_ERROR ("fcntl(F_SETFL) failed (%d): %s\n", errno, strerror (errno));
- }
sun.sun_family = AF_UNIX;
strncpy (sun.sun_path, path, sizeof (sun.sun_path) - 1);
@@ -226,9 +225,8 @@ sp_writer_create (const char *path, size_t size, mode_t perms)
self->socket_path = strdup (sun.sun_path);
- if (listen (self->main_socket, 10) < 0) {
+ if (listen (self->main_socket, LISTEN_BACKLOG) < 0)
RETURN_ERROR ("listen() failed (%d): %s\n", errno, strerror (errno));
- }
self->shm_area = sp_open_shm (NULL, ++self->next_area_id, 1, perms, size);
@@ -249,6 +247,14 @@ sp_writer_create (const char *path, size_t size, mode_t perms)
sp_shm_area_dec (NULL, area); \
return NULL;
+/**
+ * sp_open_shm:
+ * @path: Path of the shm area, NULL if this is a writer (then it will allocate
+ * its own path)
+ *
+ * Opens a ShmArea
+ */
+
static ShmArea *
sp_open_shm (char *path, int id, int writer, mode_t perms, size_t size)
{
@@ -281,20 +287,17 @@ sp_open_shm (char *path, int id, int writer, mode_t perms, size_t size)
} while (area->shm_fd < 0 && errno == EEXIST);
}
- if (area->shm_fd < 0) {
+ if (area->shm_fd < 0)
RETURN_ERROR ("shm_open failed on %s (%d): %s\n",
path ? path : tmppath, errno, strerror (errno));
- }
if (!path)
area->shm_area_name = strdup (tmppath);
- if (writer) {
- if (ftruncate (area->shm_fd, size)) {
+ if (writer)
+ if (ftruncate (area->shm_fd, size))
RETURN_ERROR ("Could not resize memory area to header size,"
" ftruncate failed (%d): %s\n", errno, strerror (errno));
- }
- }
if (writer)
prot = PROT_READ | PROT_WRITE;
@@ -303,9 +306,8 @@ sp_open_shm (char *path, int id, int writer, mode_t perms, size_t size)
area->shm_area = mmap (NULL, size, prot, MAP_SHARED, area->shm_fd, 0);
- if (area->shm_area == MAP_FAILED) {
+ if (area->shm_area == MAP_FAILED)
RETURN_ERROR ("mmap failed (%d): %s\n", errno, strerror (errno));
- }
area->id = id;
@@ -387,9 +389,8 @@ sp_close (ShmPipe * self)
while (self->clients)
sp_writer_close_client (self, self->clients);
- while (self->shm_area) {
+ while (self->shm_area)
sp_shm_area_dec (self, self->shm_area);
- }
spalloc_free (ShmPipe, self);
}