WIP: no mem leaks on simple use. switch still to test.
parent
f4ffd7386f
commit
a5877101eb
44
Makefile
44
Makefile
|
@ -45,9 +45,9 @@ man/libipc.7.uninstall:
|
||||||
@echo '[01;37m RM > [01;37m$(MANDIR)/man7/libipc.7[00m'
|
@echo '[01;37m RM > [01;37m$(MANDIR)/man7/libipc.7[00m'
|
||||||
$(Q)rm -f '$(DESTDIR)$(MANDIR)/man7/libipc.7'
|
$(Q)rm -f '$(DESTDIR)$(MANDIR)/man7/libipc.7'
|
||||||
|
|
||||||
libipc.so: src/communication.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/usocket.o src/utils.o src/fs.h src/ipc.h src/message.h src/usocket.h src/utils.h
|
libipc.so: src/communication.o src/context.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/service_path.o src/usocket.o src/utils.o src/fs.h src/ipc.h src/message.h src/usocket.h src/utils.h
|
||||||
@echo '[01;32m LD > [01;37mlibipc.so[00m'
|
@echo '[01;32m LD > [01;37mlibipc.so[00m'
|
||||||
$(Q)$(CC) -o libipc.so -shared $(LDFLAGS) src/communication.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/usocket.o src/utils.o
|
$(Q)$(CC) -o libipc.so -shared $(LDFLAGS) src/communication.o src/context.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/service_path.o src/usocket.o src/utils.o
|
||||||
|
|
||||||
libipc.so.install: libipc.so
|
libipc.so.install: libipc.so
|
||||||
@echo '[01;31m IN > [01;37m$(LIBDIR)/libipc.so.0.6.0[00m'
|
@echo '[01;31m IN > [01;37m$(LIBDIR)/libipc.so.0.6.0[00m'
|
||||||
|
@ -74,9 +74,9 @@ libipc.so.uninstall:
|
||||||
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so[00m'
|
@echo '[01;37m RM > [01;37m$(LIBDIR)/libipc.so[00m'
|
||||||
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so'
|
$(Q)rm -f '$(DESTDIR)$(LIBDIR)/libipc.so'
|
||||||
|
|
||||||
libipc.a: src/communication.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/usocket.o src/utils.o src/fs.h src/ipc.h src/message.h src/usocket.h src/utils.h
|
libipc.a: src/communication.o src/context.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/service_path.o src/usocket.o src/utils.o src/fs.h src/ipc.h src/message.h src/usocket.h src/utils.h
|
||||||
@echo '[01;32m LD > [01;37mlibipc.a[00m'
|
@echo '[01;32m LD > [01;37mlibipc.a[00m'
|
||||||
$(Q)$(AR) rc 'libipc.a' src/communication.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/usocket.o src/utils.o
|
$(Q)$(AR) rc 'libipc.a' src/communication.o src/context.o src/error.o src/fs.o src/message.o src/network.o src/print.o src/service_path.o src/usocket.o src/utils.o
|
||||||
|
|
||||||
libipc.a.install: libipc.a
|
libipc.a.install: libipc.a
|
||||||
@echo '[01;31m IN > [01;37m$(LIBDIR)/libipc.a[00m'
|
@echo '[01;31m IN > [01;37m$(LIBDIR)/libipc.a[00m'
|
||||||
|
@ -103,6 +103,18 @@ src/communication.o.clean:
|
||||||
|
|
||||||
src/communication.o.uninstall:
|
src/communication.o.uninstall:
|
||||||
|
|
||||||
|
src/context.o: src/context.c src/ipc.h
|
||||||
|
@echo '[01;34m CC > [01;37msrc/context.o[00m'
|
||||||
|
$(Q)$(CC) $(CFLAGS) -fPIC -std=c11 -c src/context.c -fPIC -std=c11 -o src/context.o
|
||||||
|
|
||||||
|
src/context.o.install:
|
||||||
|
|
||||||
|
src/context.o.clean:
|
||||||
|
@echo '[01;37m RM > [01;37msrc/context.o[00m'
|
||||||
|
$(Q)rm -f src/context.o
|
||||||
|
|
||||||
|
src/context.o.uninstall:
|
||||||
|
|
||||||
src/error.o: src/error.c src/ipc.h
|
src/error.o: src/error.c src/ipc.h
|
||||||
@echo '[01;34m CC > [01;37msrc/error.o[00m'
|
@echo '[01;34m CC > [01;37msrc/error.o[00m'
|
||||||
$(Q)$(CC) $(CFLAGS) -fPIC -std=c11 -c src/error.c -fPIC -std=c11 -o src/error.o
|
$(Q)$(CC) $(CFLAGS) -fPIC -std=c11 -c src/error.c -fPIC -std=c11 -o src/error.o
|
||||||
|
@ -163,6 +175,18 @@ src/print.o.clean:
|
||||||
|
|
||||||
src/print.o.uninstall:
|
src/print.o.uninstall:
|
||||||
|
|
||||||
|
src/service_path.o: src/service_path.c src/ipc.h
|
||||||
|
@echo '[01;34m CC > [01;37msrc/service_path.o[00m'
|
||||||
|
$(Q)$(CC) $(CFLAGS) -fPIC -std=c11 -c src/service_path.c -fPIC -std=c11 -o src/service_path.o
|
||||||
|
|
||||||
|
src/service_path.o.install:
|
||||||
|
|
||||||
|
src/service_path.o.clean:
|
||||||
|
@echo '[01;37m RM > [01;37msrc/service_path.o[00m'
|
||||||
|
$(Q)rm -f src/service_path.o
|
||||||
|
|
||||||
|
src/service_path.o.uninstall:
|
||||||
|
|
||||||
src/usocket.o: src/usocket.c src/usocket.h src/utils.h src/fs.h
|
src/usocket.o: src/usocket.c src/usocket.h src/utils.h src/fs.h
|
||||||
@echo '[01;34m CC > [01;37msrc/usocket.o[00m'
|
@echo '[01;34m CC > [01;37msrc/usocket.o[00m'
|
||||||
$(Q)$(CC) $(CFLAGS) -fPIC -std=c11 -c src/usocket.c -fPIC -std=c11 -o src/usocket.o
|
$(Q)$(CC) $(CFLAGS) -fPIC -std=c11 -c src/usocket.c -fPIC -std=c11 -o src/usocket.o
|
||||||
|
@ -209,13 +233,13 @@ $(DESTDIR)$(INCLUDEDIR):
|
||||||
$(DESTDIR)$(MANDIR):
|
$(DESTDIR)$(MANDIR):
|
||||||
@echo '[01;35m DIR > [01;37m$(MANDIR)[00m'
|
@echo '[01;35m DIR > [01;37m$(MANDIR)[00m'
|
||||||
$(Q)mkdir -p $(DESTDIR)$(MANDIR)
|
$(Q)mkdir -p $(DESTDIR)$(MANDIR)
|
||||||
install: libipc.install man/libipc.7.install libipc.so.install libipc.a.install src/communication.o.install src/error.o.install src/fs.o.install src/message.o.install src/network.o.install src/print.o.install src/usocket.o.install src/utils.o.install src/communication.o.install src/error.o.install src/fs.o.install src/message.o.install src/network.o.install src/print.o.install src/usocket.o.install src/utils.o.install
|
install: libipc.install man/libipc.7.install libipc.so.install libipc.a.install src/communication.o.install src/context.o.install src/error.o.install src/fs.o.install src/message.o.install src/network.o.install src/print.o.install src/service_path.o.install src/usocket.o.install src/utils.o.install src/communication.o.install src/context.o.install src/error.o.install src/fs.o.install src/message.o.install src/network.o.install src/print.o.install src/service_path.o.install src/usocket.o.install src/utils.o.install
|
||||||
@:
|
@:
|
||||||
|
|
||||||
uninstall: libipc.uninstall man/libipc.7.uninstall libipc.so.uninstall libipc.a.uninstall src/communication.o.uninstall src/error.o.uninstall src/fs.o.uninstall src/message.o.uninstall src/network.o.uninstall src/print.o.uninstall src/usocket.o.uninstall src/utils.o.uninstall src/communication.o.uninstall src/error.o.uninstall src/fs.o.uninstall src/message.o.uninstall src/network.o.uninstall src/print.o.uninstall src/usocket.o.uninstall src/utils.o.uninstall
|
uninstall: libipc.uninstall man/libipc.7.uninstall libipc.so.uninstall libipc.a.uninstall src/communication.o.uninstall src/context.o.uninstall src/error.o.uninstall src/fs.o.uninstall src/message.o.uninstall src/network.o.uninstall src/print.o.uninstall src/service_path.o.uninstall src/usocket.o.uninstall src/utils.o.uninstall src/communication.o.uninstall src/context.o.uninstall src/error.o.uninstall src/fs.o.uninstall src/message.o.uninstall src/network.o.uninstall src/print.o.uninstall src/service_path.o.uninstall src/usocket.o.uninstall src/utils.o.uninstall
|
||||||
@:
|
@:
|
||||||
|
|
||||||
clean: libipc.clean man/libipc.7.clean libipc.so.clean libipc.a.clean src/communication.o.clean src/error.o.clean src/fs.o.clean src/message.o.clean src/network.o.clean src/print.o.clean src/usocket.o.clean src/utils.o.clean src/communication.o.clean src/error.o.clean src/fs.o.clean src/message.o.clean src/network.o.clean src/print.o.clean src/usocket.o.clean src/utils.o.clean
|
clean: libipc.clean man/libipc.7.clean libipc.so.clean libipc.a.clean src/communication.o.clean src/context.o.clean src/error.o.clean src/fs.o.clean src/message.o.clean src/network.o.clean src/print.o.clean src/service_path.o.clean src/usocket.o.clean src/utils.o.clean src/communication.o.clean src/context.o.clean src/error.o.clean src/fs.o.clean src/message.o.clean src/network.o.clean src/print.o.clean src/service_path.o.clean src/usocket.o.clean src/utils.o.clean
|
||||||
distclean: clean
|
distclean: clean
|
||||||
dist: dist-gz dist-xz dist-bz2
|
dist: dist-gz dist-xz dist-bz2
|
||||||
$(Q)rm -- $(PACKAGE)-$(VERSION)
|
$(Q)rm -- $(PACKAGE)-$(VERSION)
|
||||||
|
@ -235,11 +259,13 @@ $(PACKAGE)-$(VERSION).tar.gz: distdir
|
||||||
$(PACKAGE)-$(VERSION)/Makefile \
|
$(PACKAGE)-$(VERSION)/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/project.zsh \
|
$(PACKAGE)-$(VERSION)/project.zsh \
|
||||||
$(PACKAGE)-$(VERSION)/src/communication.c \
|
$(PACKAGE)-$(VERSION)/src/communication.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/context.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/error.c \
|
$(PACKAGE)-$(VERSION)/src/error.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/fs.c \
|
$(PACKAGE)-$(VERSION)/src/fs.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/message.c \
|
$(PACKAGE)-$(VERSION)/src/message.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/network.c \
|
$(PACKAGE)-$(VERSION)/src/network.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/print.c \
|
$(PACKAGE)-$(VERSION)/src/print.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/service_path.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/usocket.c \
|
$(PACKAGE)-$(VERSION)/src/usocket.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/utils.c \
|
$(PACKAGE)-$(VERSION)/src/utils.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/ipc.h \
|
$(PACKAGE)-$(VERSION)/src/ipc.h \
|
||||||
|
@ -259,11 +285,13 @@ $(PACKAGE)-$(VERSION).tar.xz: distdir
|
||||||
$(PACKAGE)-$(VERSION)/Makefile \
|
$(PACKAGE)-$(VERSION)/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/project.zsh \
|
$(PACKAGE)-$(VERSION)/project.zsh \
|
||||||
$(PACKAGE)-$(VERSION)/src/communication.c \
|
$(PACKAGE)-$(VERSION)/src/communication.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/context.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/error.c \
|
$(PACKAGE)-$(VERSION)/src/error.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/fs.c \
|
$(PACKAGE)-$(VERSION)/src/fs.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/message.c \
|
$(PACKAGE)-$(VERSION)/src/message.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/network.c \
|
$(PACKAGE)-$(VERSION)/src/network.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/print.c \
|
$(PACKAGE)-$(VERSION)/src/print.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/service_path.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/usocket.c \
|
$(PACKAGE)-$(VERSION)/src/usocket.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/utils.c \
|
$(PACKAGE)-$(VERSION)/src/utils.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/ipc.h \
|
$(PACKAGE)-$(VERSION)/src/ipc.h \
|
||||||
|
@ -283,11 +311,13 @@ $(PACKAGE)-$(VERSION).tar.bz2: distdir
|
||||||
$(PACKAGE)-$(VERSION)/Makefile \
|
$(PACKAGE)-$(VERSION)/Makefile \
|
||||||
$(PACKAGE)-$(VERSION)/project.zsh \
|
$(PACKAGE)-$(VERSION)/project.zsh \
|
||||||
$(PACKAGE)-$(VERSION)/src/communication.c \
|
$(PACKAGE)-$(VERSION)/src/communication.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/context.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/error.c \
|
$(PACKAGE)-$(VERSION)/src/error.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/fs.c \
|
$(PACKAGE)-$(VERSION)/src/fs.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/message.c \
|
$(PACKAGE)-$(VERSION)/src/message.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/network.c \
|
$(PACKAGE)-$(VERSION)/src/network.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/print.c \
|
$(PACKAGE)-$(VERSION)/src/print.c \
|
||||||
|
$(PACKAGE)-$(VERSION)/src/service_path.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/usocket.c \
|
$(PACKAGE)-$(VERSION)/src/usocket.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/utils.c \
|
$(PACKAGE)-$(VERSION)/src/utils.c \
|
||||||
$(PACKAGE)-$(VERSION)/src/ipc.h \
|
$(PACKAGE)-$(VERSION)/src/ipc.h \
|
||||||
|
|
|
@ -13,53 +13,6 @@
|
||||||
// print structures
|
// print structures
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
|
|
||||||
struct ipc_error
|
|
||||||
service_path (char *path, const char *sname)
|
|
||||||
{
|
|
||||||
T_R ((path == NULL), IPC_ERROR_SERVICE_PATH__NO_PATH);
|
|
||||||
T_R ((sname == NULL), IPC_ERROR_SERVICE_PATH__NO_SERVICE_NAME);
|
|
||||||
|
|
||||||
memset (path, 0, PATH_MAX);
|
|
||||||
|
|
||||||
char *rundir = getenv ("IPC_RUNDIR");
|
|
||||||
if (rundir == NULL)
|
|
||||||
rundir = RUNDIR;
|
|
||||||
|
|
||||||
snprintf (path, PATH_MAX - 1, "%s/%s", rundir, sname);
|
|
||||||
|
|
||||||
IPC_RETURN_NO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* PERFORMANCE POINT:
|
|
||||||
* Realloc is performed at each new user. There is plenty of room for improvement,
|
|
||||||
* for example by managing allocations of thousands of structures at once.
|
|
||||||
* WARNING: Store and remove only pointers on allocated structures.
|
|
||||||
*/
|
|
||||||
struct ipc_error ipc_ctx_new_alloc (struct ipc_ctx *ctx)
|
|
||||||
{
|
|
||||||
ctx->size++;
|
|
||||||
|
|
||||||
// Memory could be not allocated, yet.
|
|
||||||
if (ctx->size == 1 && ctx->cinfos == NULL && ctx->pollfd == NULL) {
|
|
||||||
SECURE_BUFFER_HEAP_ALLOCATION_R (ctx->cinfos, sizeof (struct ipc_connection_info),,
|
|
||||||
IPC_ERROR_ADD__MALLOC);
|
|
||||||
SECURE_BUFFER_HEAP_ALLOCATION_R (ctx->pollfd, sizeof (struct pollfd),, IPC_ERROR_ADD__MALLOC_POLLFD);
|
|
||||||
} else {
|
|
||||||
ctx->cinfos = realloc (ctx->cinfos, sizeof (struct ipc_connection_info) * ctx->size);
|
|
||||||
ctx->pollfd = realloc (ctx->pollfd, sizeof (struct pollfd ) * ctx->size);
|
|
||||||
}
|
|
||||||
|
|
||||||
T_R ((ctx->cinfos == NULL), IPC_ERROR_ADD__EMPTY_LIST);
|
|
||||||
T_R ((ctx->pollfd == NULL), IPC_ERROR_ADD__EMPTY_LIST);
|
|
||||||
|
|
||||||
// Clean the last entry.
|
|
||||||
memset (&ctx->cinfos[ctx->size -1], 0, sizeof (struct ipc_connection_info));
|
|
||||||
memset (&ctx->pollfd[ctx->size -1], 0, sizeof (struct pollfd));
|
|
||||||
|
|
||||||
IPC_RETURN_NO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ipc_error ipc_server_init (struct ipc_ctx *ctx, const char *sname)
|
struct ipc_error ipc_server_init (struct ipc_ctx *ctx, const char *sname)
|
||||||
{
|
{
|
||||||
T_R ((sname == NULL), IPC_ERROR_SERVER_INIT__NO_SERVER_NAME_PARAM);
|
T_R ((sname == NULL), IPC_ERROR_SERVER_INIT__NO_SERVER_NAME_PARAM);
|
||||||
|
@ -194,7 +147,6 @@ struct ipc_error ipc_close (struct ipc_ctx *ctx, uint32_t index)
|
||||||
struct ipc_error ret = usock_close (ctx->pollfd[index].fd);
|
struct ipc_error ret = usock_close (ctx->pollfd[index].fd);
|
||||||
|
|
||||||
// TODO: verify that the close was OK??
|
// TODO: verify that the close was OK??
|
||||||
|
|
||||||
if (ctx->cinfos[index].type == IPC_CONNECTION_TYPE_SERVER) {
|
if (ctx->cinfos[index].type == IPC_CONNECTION_TYPE_SERVER) {
|
||||||
ret = usock_remove (ctx->cinfos[index].spath);
|
ret = usock_remove (ctx->cinfos[index].spath);
|
||||||
if (ctx->cinfos[index].spath != NULL) {
|
if (ctx->cinfos[index].spath != NULL) {
|
||||||
|
@ -319,7 +271,7 @@ struct ipc_error ipc_del (struct ipc_ctx *ctx, uint32_t index)
|
||||||
|
|
||||||
if (ctx->size == 0) {
|
if (ctx->size == 0) {
|
||||||
// free ctx->cinfos and ctx->pollfd
|
// free ctx->cinfos and ctx->pollfd
|
||||||
ipc_connections_free (ctx);
|
ipc_ctx_free (ctx);
|
||||||
IPC_RETURN_NO_ERROR;
|
IPC_RETURN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,22 +290,6 @@ struct ipc_error ipc_del (struct ipc_ctx *ctx, uint32_t index)
|
||||||
IPC_RETURN_NO_ERROR;
|
IPC_RETURN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ipc_connections_free (struct ipc_ctx *ctx)
|
|
||||||
{
|
|
||||||
if (ctx->cinfos != NULL) {
|
|
||||||
free (ctx->cinfos);
|
|
||||||
free (ctx->pollfd);
|
|
||||||
ctx->cinfos = NULL;
|
|
||||||
ctx->pollfd = NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ctx->switchdb.collection != NULL) {
|
|
||||||
free (ctx->switchdb.collection);
|
|
||||||
ctx->switchdb.collection = NULL;
|
|
||||||
}
|
|
||||||
ctx->size = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add an arbitrary file descriptor to read
|
// add an arbitrary file descriptor to read
|
||||||
struct ipc_error ipc_add_fd (struct ipc_ctx *ctx, int fd)
|
struct ipc_error ipc_add_fd (struct ipc_ctx *ctx, int fd)
|
||||||
{
|
{
|
||||||
|
@ -385,8 +321,6 @@ struct ipc_error ipc_del_fd (struct ipc_ctx *ctx, int fd)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index);
|
|
||||||
|
|
||||||
struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index)
|
struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index)
|
||||||
{
|
{
|
||||||
int txfd = ctx->pollfd[index].fd;
|
int txfd = ctx->pollfd[index].fd;
|
||||||
|
|
|
@ -0,0 +1,46 @@
|
||||||
|
#include "ipc.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* PERFORMANCE POINT:
|
||||||
|
* Realloc is performed at each new user. There is plenty of room for improvement,
|
||||||
|
* for example by managing allocations of thousands of structures at once.
|
||||||
|
* WARNING: Store and remove only pointers on allocated structures.
|
||||||
|
*/
|
||||||
|
struct ipc_error ipc_ctx_new_alloc (struct ipc_ctx *ctx)
|
||||||
|
{
|
||||||
|
ctx->size++;
|
||||||
|
|
||||||
|
// Memory could be not allocated, yet.
|
||||||
|
if (ctx->size == 1 && ctx->cinfos == NULL && ctx->pollfd == NULL) {
|
||||||
|
SECURE_BUFFER_HEAP_ALLOCATION_R (ctx->cinfos, sizeof (struct ipc_connection_info),,
|
||||||
|
IPC_ERROR_ADD__MALLOC);
|
||||||
|
SECURE_BUFFER_HEAP_ALLOCATION_R (ctx->pollfd, sizeof (struct pollfd),, IPC_ERROR_ADD__MALLOC_POLLFD);
|
||||||
|
} else {
|
||||||
|
ctx->cinfos = realloc (ctx->cinfos, sizeof (struct ipc_connection_info) * ctx->size);
|
||||||
|
ctx->pollfd = realloc (ctx->pollfd, sizeof (struct pollfd ) * ctx->size);
|
||||||
|
}
|
||||||
|
|
||||||
|
T_R ((ctx->cinfos == NULL), IPC_ERROR_ADD__EMPTY_LIST);
|
||||||
|
T_R ((ctx->pollfd == NULL), IPC_ERROR_ADD__EMPTY_LIST);
|
||||||
|
|
||||||
|
// Clean the last entry.
|
||||||
|
memset (&ctx->cinfos[ctx->size -1], 0, sizeof (struct ipc_connection_info));
|
||||||
|
memset (&ctx->pollfd[ctx->size -1], 0, sizeof (struct pollfd));
|
||||||
|
|
||||||
|
IPC_RETURN_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ipc_ctx_free (struct ipc_ctx *ctx)
|
||||||
|
{
|
||||||
|
if (ctx->cinfos != NULL) {
|
||||||
|
free (ctx->cinfos);
|
||||||
|
ctx->cinfos = NULL;
|
||||||
|
}
|
||||||
|
if (ctx->pollfd != NULL) {
|
||||||
|
free (ctx->pollfd);
|
||||||
|
ctx->pollfd = NULL;
|
||||||
|
}
|
||||||
|
ctx->size = 0;
|
||||||
|
|
||||||
|
ipc_messages_free (&ctx->tx);
|
||||||
|
}
|
20
src/ipc.h
20
src/ipc.h
|
@ -221,11 +221,11 @@ struct ipc_connection_info {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ipc_message {
|
struct ipc_message {
|
||||||
char type;
|
char type; // Internal message type.
|
||||||
char user_type;
|
char user_type; // User-defined message type.
|
||||||
uint32_t length;
|
int fd; // File descriptor concerned about this message.
|
||||||
|
uint32_t length; // Payload length.
|
||||||
char *payload;
|
char *payload;
|
||||||
int fd; // File descriptor concerned about this message.
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ipc_messages {
|
struct ipc_messages {
|
||||||
|
@ -306,6 +306,8 @@ struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname);
|
||||||
struct ipc_error ipc_close (struct ipc_ctx *ctx, uint32_t index);
|
struct ipc_error ipc_close (struct ipc_ctx *ctx, uint32_t index);
|
||||||
struct ipc_error ipc_close_all (struct ipc_ctx *ctx);
|
struct ipc_error ipc_close_all (struct ipc_ctx *ctx);
|
||||||
|
|
||||||
|
void ipc_ctx_free (struct ipc_ctx *ctx);
|
||||||
|
|
||||||
struct ipc_error ipc_read (const struct ipc_ctx *, uint32_t index, struct ipc_message *m);
|
struct ipc_error ipc_read (const struct ipc_ctx *, uint32_t index, struct ipc_message *m);
|
||||||
struct ipc_error ipc_write (struct ipc_ctx *, const struct ipc_message *m);
|
struct ipc_error ipc_write (struct ipc_ctx *, const struct ipc_message *m);
|
||||||
|
|
||||||
|
@ -316,10 +318,8 @@ struct ipc_error ipc_add (struct ipc_ctx *, struct ipc_connection_info *, struct
|
||||||
struct ipc_error ipc_del (struct ipc_ctx *, uint32_t index);
|
struct ipc_error ipc_del (struct ipc_ctx *, uint32_t index);
|
||||||
|
|
||||||
// add an arbitrary file descriptor to read
|
// add an arbitrary file descriptor to read
|
||||||
struct ipc_error ipc_add_fd (struct ipc_ctx *cinfos, int fd);
|
struct ipc_error ipc_add_fd (struct ipc_ctx *ctx, int fd);
|
||||||
struct ipc_error ipc_del_fd (struct ipc_ctx *cinfos, int fd);
|
struct ipc_error ipc_del_fd (struct ipc_ctx *ctx, int fd);
|
||||||
|
|
||||||
void ipc_connections_free (struct ipc_ctx *);
|
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* message functions
|
* message functions
|
||||||
|
@ -349,6 +349,10 @@ void ipc_messages_free (struct ipc_messages *);
|
||||||
**/
|
**/
|
||||||
|
|
||||||
struct ipc_error ipc_write_fd (int fd, const struct ipc_message *m);
|
struct ipc_error ipc_write_fd (int fd, const struct ipc_message *m);
|
||||||
|
struct ipc_error ipc_ctx_new_alloc (struct ipc_ctx *ctx);
|
||||||
|
struct ipc_error service_path (char *path, const char *sname);
|
||||||
|
|
||||||
|
struct ipc_error handle_writing_message (struct ipc_event *event, struct ipc_ctx *ctx, uint32_t index);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used by ipc_server_init and ipc_connection
|
* Used by ipc_server_init and ipc_connection
|
||||||
|
|
|
@ -200,6 +200,5 @@ void ipc_messages_free (struct ipc_messages *messages)
|
||||||
free(messages->messages);
|
free(messages->messages);
|
||||||
messages->messages = 0;
|
messages->messages = 0;
|
||||||
}
|
}
|
||||||
free(messages);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,19 @@
|
||||||
|
#include "ipc.h"
|
||||||
|
|
||||||
|
struct ipc_error
|
||||||
|
service_path (char *path, const char *sname)
|
||||||
|
{
|
||||||
|
T_R ((path == NULL), IPC_ERROR_SERVICE_PATH__NO_PATH);
|
||||||
|
T_R ((sname == NULL), IPC_ERROR_SERVICE_PATH__NO_SERVICE_NAME);
|
||||||
|
|
||||||
|
memset (path, 0, PATH_MAX);
|
||||||
|
|
||||||
|
char *rundir = getenv ("IPC_RUNDIR");
|
||||||
|
if (rundir == NULL)
|
||||||
|
rundir = RUNDIR;
|
||||||
|
|
||||||
|
snprintf (path, PATH_MAX - 1, "%s/%s", rundir, sname);
|
||||||
|
|
||||||
|
IPC_RETURN_NO_ERROR;
|
||||||
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ void non_interactive ()
|
||||||
ipc_message_empty (&m);
|
ipc_message_empty (&m);
|
||||||
|
|
||||||
TEST_IPC_Q(ipc_close_all (&ctx), EXIT_FAILURE);
|
TEST_IPC_Q(ipc_close_all (&ctx), EXIT_FAILURE);
|
||||||
|
ipc_ctx_free (&ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
|
|
Reference in New Issue