From: Youness Alaoui Date: Wed, 20 Oct 2010 19:41:15 +0000 (+0200) Subject: shm: stylist improvements X-Git-Tag: RELEASE-0.11.1~356 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=768319b86623477a3658b448d01f5cc332cbf818;p=platform%2Fupstream%2Fgst-plugins-bad.git shm: stylist improvements --- diff --git a/sys/shm/shmpipe.c b/sys/shm/shmpipe.c index 58d3cd6..aa868ae 100644 --- a/sys/shm/shmpipe.c +++ b/sys/shm/shmpipe.c @@ -41,6 +41,8 @@ #include #include +#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); }