mirror of
https://github.com/pikvm/ustreamer.git
synced 2026-03-12 02:23:43 +00:00
refactoring
This commit is contained in:
@@ -85,20 +85,8 @@ static int MemsinkObject_init(MemsinkObject *self, PyObject *args, PyObject *kwa
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((self->mem = mmap(
|
if ((self->mem = memsink_shared_map(self->fd)) == NULL) {
|
||||||
NULL,
|
|
||||||
sizeof(memsink_shared_s),
|
|
||||||
PROT_READ | PROT_WRITE,
|
|
||||||
MAP_SHARED,
|
|
||||||
self->fd,
|
|
||||||
0
|
|
||||||
)) == MAP_FAILED) {
|
|
||||||
PyErr_SetFromErrno(PyExc_OSError);
|
PyErr_SetFromErrno(PyExc_OSError);
|
||||||
self->mem = NULL;
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
if (self->mem == NULL) {
|
|
||||||
PyErr_SetString(PyExc_RuntimeError, "Memory mapping is NULL"); \
|
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,14 +54,7 @@ memsink_s *memsink_init(
|
|||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((sink->mem = mmap(
|
if ((sink->mem = memsink_shared_map(sink->fd)) == NULL) {
|
||||||
NULL,
|
|
||||||
sizeof(memsink_shared_s),
|
|
||||||
PROT_READ | PROT_WRITE,
|
|
||||||
MAP_SHARED,
|
|
||||||
sink->fd,
|
|
||||||
0
|
|
||||||
)) == MAP_FAILED) {
|
|
||||||
LOG_PERROR("%s-sink: Can't mmap shared memory", name);
|
LOG_PERROR("%s-sink: Can't mmap shared memory", name);
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@
|
|||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
|
||||||
|
|
||||||
#define MEMSINK_MAGIC ((uint64_t)0xCAFEBABECAFEBABE)
|
#define MEMSINK_MAGIC ((uint64_t)0xCAFEBABECAFEBABE)
|
||||||
@@ -59,3 +60,20 @@ typedef struct {
|
|||||||
|
|
||||||
uint8_t data[MEMSINK_MAX_DATA];
|
uint8_t data[MEMSINK_MAX_DATA];
|
||||||
} memsink_shared_s;
|
} memsink_shared_s;
|
||||||
|
|
||||||
|
|
||||||
|
INLINE memsink_shared_s *memsink_shared_map(int fd) {
|
||||||
|
memsink_shared_s *mem = mmap(
|
||||||
|
NULL,
|
||||||
|
sizeof(memsink_shared_s),
|
||||||
|
PROT_READ | PROT_WRITE,
|
||||||
|
MAP_SHARED,
|
||||||
|
fd,
|
||||||
|
0
|
||||||
|
);
|
||||||
|
if (mem == MAP_FAILED) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
assert(mem != NULL);
|
||||||
|
return mem;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user