Commit 04687138 authored by Simon Morlat's avatar Simon Morlat

shared memory abstraction

parent 18eccd4f
......@@ -240,7 +240,7 @@ fi
dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(poll.h sys/poll.h sys/uio.h fcntl.h sys/time.h unistd.h sys/audio.h linux/soundcard.h)
AC_CHECK_HEADERS(poll.h sys/poll.h sys/uio.h fcntl.h sys/time.h unistd.h sys/audio.h linux/soundcard.h sys/shm.h)
dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
......
......@@ -271,7 +271,7 @@ char *ortp_strdup_vprintf(const char *fmt, va_list ap);
int ortp_file_exist(const char *pathname);
/* portable named pipes */
/* portable named pipes and shared memory*/
#if !defined(_WIN32_WCE)
#ifdef WIN32
typedef HANDLE ortp_pipe_t;
......@@ -296,6 +296,10 @@ int ortp_client_pipe_close(ortp_pipe_t sock);
int ortp_pipe_read(ortp_pipe_t p, uint8_t *buf, int len);
int ortp_pipe_write(ortp_pipe_t p, const uint8_t *buf, int len);
void *ortp_shm_open(unsigned int keyid, int size, int create);
void ortp_shm_close(void *memory);
#endif
#ifdef __cplusplus
......
......@@ -32,6 +32,10 @@
#include <process.h>
#endif
#ifdef HAVE_SYS_SHM_H
#include <sys/shm.h>
#endif
static void *ortp_libc_malloc(size_t sz){
return malloc(sz);
}
......@@ -436,6 +440,38 @@ int ortp_client_pipe_close(ortp_socket_t sock){
return close(sock);
}
#ifdef HAVE_SYS_SHM_H
void *ortp_shm_open(unsigned int keyid, int size, int create){
key_t key=keyid;
void *mem;
int fd=shmget(key,size,create ? (IPC_CREAT | 0666) : 0666);
if (fd==-1){
printf("shmget failed: %s\n",strerror(errno));
return NULL;
}
mem=shmat(fd,NULL,0);
if (mem==(void*)-1){
printf("shmat() failed: %s", strerror(errno));
return NULL;
}
return mem;
}
void ortp_shm_close(void *mem){
shmdt(mem);
}
#else
void *ortp_shm_open(unsigned int keyid, int size, int create){
ortp_error("No shared memory support for this OS.");
}
void ortp_shm_close(void *mem){
}
#endif
#elif defined(WIN32) && !defined(_WIN32_WCE)
......@@ -528,5 +564,11 @@ int ortp_client_pipe_close(ortp_pipe_t sock){
return CloseHandle(sock);
}
void *ortp_shm_open(unsigned int keyid, int size, int create{
return NULL;
}
void ortp_shm_close(void *mem){
}
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment