WIP
parent
9429be80b3
commit
9cdf868755
|
@ -34,18 +34,6 @@ service_path (char *path, const char *sname)
|
||||||
IPC_RETURN_NO_ERROR;
|
IPC_RETURN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ipc_error ipc_ctx_init (struct ipc_ctx **ctx)
|
|
||||||
{
|
|
||||||
T_R ((ctx == NULL), IPC_ERROR_CTX_INIT__NO_CONTEXT_PARAM);
|
|
||||||
T_R ((*ctx != NULL), IPC_ERROR_CTX_INIT__CONTEXT_ALREADY_INIT);
|
|
||||||
|
|
||||||
*ctx = malloc(sizeof(struct ipc_ctx));
|
|
||||||
T_R ((*ctx == NULL), IPC_ERROR_CTX_INIT__MALLOC_CTX);
|
|
||||||
memset (ctx, 0, sizeof(struct ipc_ctx));
|
|
||||||
|
|
||||||
IPC_RETURN_NO_ERROR;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PERFORMANCE POINT:
|
* PERFORMANCE POINT:
|
||||||
* Realloc is performed at each new user. There is plenty of room for improvement,
|
* Realloc is performed at each new user. There is plenty of room for improvement,
|
||||||
|
@ -76,12 +64,10 @@ struct ipc_error ipc_ctx_new_alloc (struct ipc_ctx *ctx)
|
||||||
IPC_RETURN_NO_ERROR;
|
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);
|
||||||
|
|
||||||
ipc_ctx_init(ctx); // Allocate the context.
|
|
||||||
|
|
||||||
// Declaration and instanciation of the new connection (ipc_connection_info + pollfd).
|
// Declaration and instanciation of the new connection (ipc_connection_info + pollfd).
|
||||||
SECURE_DECLARATION (struct ipc_connection_info, srv);
|
SECURE_DECLARATION (struct ipc_connection_info, srv);
|
||||||
srv.type = IPC_CONNECTION_TYPE_SERVER;
|
srv.type = IPC_CONNECTION_TYPE_SERVER;
|
||||||
|
@ -103,7 +89,7 @@ struct ipc_error ipc_server_init (struct ipc_ctx **ctx, const char *sname)
|
||||||
|
|
||||||
// Add the server to the listened file descriptors.
|
// Add the server to the listened file descriptors.
|
||||||
// ipc_add allocate memory then copy the data of srv and pollfd in ctx.
|
// ipc_add allocate memory then copy the data of srv and pollfd in ctx.
|
||||||
TEST_IPC_RR (ipc_add (*ctx, &srv, &pollfd), "cannot add the server in the context");
|
TEST_IPC_RR (ipc_add (ctx, &srv, &pollfd), "cannot add the server in the context");
|
||||||
|
|
||||||
IPC_RETURN_NO_ERROR;
|
IPC_RETURN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -165,13 +151,11 @@ struct ipc_error ipc_contact_networkd (int *pfd, const char *sname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create context, contact networkd, connects to the service.
|
// Create context, contact networkd, connects to the service.
|
||||||
struct ipc_error ipc_connection (struct ipc_ctx **ctx, const char *sname)
|
struct ipc_error ipc_connection (struct ipc_ctx *ctx, const char *sname)
|
||||||
{
|
{
|
||||||
T_R ((ctx == NULL), IPC_ERROR_CONNECTION__NO_CTX);
|
T_R ((ctx == NULL), IPC_ERROR_CONNECTION__NO_CTX);
|
||||||
T_R ((sname == NULL), IPC_ERROR_CONNECTION__NO_SERVICE_NAME);
|
T_R ((sname == NULL), IPC_ERROR_CONNECTION__NO_SERVICE_NAME);
|
||||||
|
|
||||||
ipc_ctx_init(ctx); // Allocate memory for the context.
|
|
||||||
|
|
||||||
SECURE_DECLARATION(struct ipc_connection_info, srv);
|
SECURE_DECLARATION(struct ipc_connection_info, srv);
|
||||||
srv.type = IPC_CONNECTION_TYPE_IPC; // Data received on the socket = messages, not new clients.
|
srv.type = IPC_CONNECTION_TYPE_IPC; // Data received on the socket = messages, not new clients.
|
||||||
SECURE_DECLARATION(struct pollfd, pollfd);
|
SECURE_DECLARATION(struct pollfd, pollfd);
|
||||||
|
@ -188,7 +172,7 @@ struct ipc_error ipc_connection (struct ipc_ctx **ctx, const char *sname)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the server to the listened file descriptors.
|
// Add the server to the listened file descriptors.
|
||||||
TEST_IPC_RR (ipc_add (*ctx, &srv, &pollfd), "cannot add the server in the context");
|
TEST_IPC_RR (ipc_add (ctx, &srv, &pollfd), "cannot add the server in the context");
|
||||||
|
|
||||||
IPC_RETURN_NO_ERROR;
|
IPC_RETURN_NO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
18
src/error.c
18
src/error.c
|
@ -120,6 +120,24 @@ static struct ipc_errors_verbose ipc_errors_verbose[] = {
|
||||||
|
|
||||||
, {IPC_ERROR_DIR_SETUP__DIRECTORY_NOT_WRITABLE, "directory_setup_: directory not writable"}
|
, {IPC_ERROR_DIR_SETUP__DIRECTORY_NOT_WRITABLE, "directory_setup_: directory not writable"}
|
||||||
, {IPC_ERROR_DIRECTORY_SETUP__PATH_PARAM , "directory_setup_: no path param"}
|
, {IPC_ERROR_DIRECTORY_SETUP__PATH_PARAM , "directory_setup_: no path param"}
|
||||||
|
|
||||||
|
, {IPC_ERROR_SERVER_INIT__NOT_ENOUGH_MEMORY, "IPC_ERROR_SERVER_INIT__NOT_ENOUGH_MEMORY"}
|
||||||
|
, {IPC_ERROR_CONNECTION__NOT_ENOUGH_MEMORY, "IPC_ERROR_CONNECTION__NOT_ENOUGH_MEMORY"}
|
||||||
|
, {IPC_ERROR_CTX_INIT__NO_CONTEXT_PARAM, "IPC_ERROR_CTX_INIT__NO_CONTEXT_PARAM"}
|
||||||
|
, {IPC_ERROR_CTX_INIT__CONTEXT_ALREADY_INIT, "IPC_ERROR_CTX_INIT__CONTEXT_ALREADY_INIT"}
|
||||||
|
, {IPC_ERROR_ADD__MALLOC_POLLFD, "IPC_ERROR_ADD__MALLOC_POLLFD"}
|
||||||
|
, {IPC_ERROR_ADD_MESSAGE_TO_SEND__EMPTY_LIST, "IPC_ERROR_ADD_MESSAGE_TO_SEND__EMPTY_LIST"}
|
||||||
|
, {IPC_ERROR_ADD_MESSAGE_TO_SEND__MALLOC, "IPC_ERROR_ADD_MESSAGE_TO_SEND__MALLOC"}
|
||||||
|
, {IPC_ERROR_ADD_MESSAGE_TO_SEND__NO_PARAM_MESSAGE, "IPC_ERROR_ADD_MESSAGE_TO_SEND__NO_PARAM_MESSAGE"}
|
||||||
|
, {IPC_ERROR_ADD_MESSAGE_TO_SEND__NO_PARAM_MESSAGES, "IPC_ERROR_ADD_MESSAGE_TO_SEND__NO_PARAM_MESSAGES"}
|
||||||
|
, {IPC_ERROR_CONNECTION__NO_CTX, "IPC_ERROR_CONNECTION__NO_CTX"}
|
||||||
|
, {IPC_ERROR_CTX_INIT__MALLOC_CTX, "IPC_ERROR_CTX_INIT__MALLOC_CTX"}
|
||||||
|
, {IPC_ERROR_CTX_INIT__MALLOC_POLLFD, "IPC_ERROR_CTX_INIT__MALLOC_POLLFD"}
|
||||||
|
, {IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM, "IPC_ERROR_CONTACT_NETWORKD__NO_FD_PARAM"}
|
||||||
|
, {IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX, "IPC_ERROR_HANDLE_NEW_CONNECTION__INCONSISTENT_INDEX"}
|
||||||
|
, {IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES, "IPC_ERROR_DEL_MESSAGE_TO_SEND__NO_PARAM_MESSAGES"}
|
||||||
|
, {IPC_ERROR_MESSAGE_DEL__INDEX_ERROR, "IPC_ERROR_MESSAGE_DEL__INDEX_ERROR"}
|
||||||
|
, {IPC_ERROR_MESSAGE_DEL__EMPTY_LIST, "IPC_ERROR_MESSAGE_DEL__EMPTY_LIST"}
|
||||||
};
|
};
|
||||||
|
|
||||||
const char *ipc_errors_get (enum ipc_error_code e)
|
const char *ipc_errors_get (enum ipc_error_code e)
|
||||||
|
|
|
@ -295,8 +295,8 @@ enum ipc_connection_types {
|
||||||
* main public functions
|
* main public functions
|
||||||
**/
|
**/
|
||||||
|
|
||||||
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);
|
||||||
struct ipc_error ipc_connection (struct ipc_ctx **ctx, const char *sname);
|
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);
|
||||||
|
|
|
@ -6,28 +6,30 @@
|
||||||
|
|
||||||
#define SERVICE_NAME "pong"
|
#define SERVICE_NAME "pong"
|
||||||
|
|
||||||
int main(int argc, char * argv[], char **env)
|
int main(int argc, char * argv[])
|
||||||
{
|
{
|
||||||
argc = (int) argc;
|
argc = (int) argc;
|
||||||
argv = (char **) argv;
|
argv = (char **) argv;
|
||||||
|
|
||||||
SECURE_DECLARATION(struct ipc_error, ret);
|
SECURE_DECLARATION(struct ipc_error, ret);
|
||||||
SECURE_DECLARATION(struct ipc_connection_info,service);
|
SECURE_DECLARATION(struct ipc_ctx, ctx);
|
||||||
SECURE_DECLARATION(struct ipc_event, event);
|
SECURE_DECLARATION(struct ipc_event, event);
|
||||||
|
|
||||||
ret = ipc_connection (env, &service, SERVICE_NAME);
|
ret = ipc_connection (&ctx, SERVICE_NAME);
|
||||||
if (ret.error_code != IPC_ERROR_NONE) {
|
if (ret.error_code != IPC_ERROR_NONE) {
|
||||||
|
printf ("error: %s\n", ipc_errors_get(ret.error_code));
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
// long timer = 10;
|
// int timer = 10000; // 10 seconds
|
||||||
// ret = ipc_wait_event (services, struct ipc_event *event, &timer);
|
// ret = ipc_wait_event (services, struct ipc_event *event, &timer);
|
||||||
// if (ret.error_code != IPC_ERROR_NONE) {
|
// if (ret.error_code != IPC_ERROR_NONE) {
|
||||||
// return EXIT_FAILURE;
|
// return EXIT_FAILURE;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
ret = ipc_close (&service);
|
ret = ipc_close_all (&ctx);
|
||||||
if (ret.error_code != IPC_ERROR_NONE) {
|
if (ret.error_code != IPC_ERROR_NONE) {
|
||||||
|
printf ("error: %s\n", ipc_errors_get(ret.error_code));
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,14 +11,13 @@ int main(int argc, char * argv[], char **env)
|
||||||
argc = (int) argc;
|
argc = (int) argc;
|
||||||
argv = (char **) argv;
|
argv = (char **) argv;
|
||||||
|
|
||||||
SECURE_DECLARATION(struct ipc_connection_info,srv);
|
SECURE_DECLARATION(struct ipc_ctx,ctx);
|
||||||
long timer = 10;
|
long timer = 10;
|
||||||
|
|
||||||
printf ("func 01 - server init...\n");
|
printf ("func 01 - server init...\n");
|
||||||
TEST_IPC_Q(ipc_server_init (env, &srv, SERVICE_NAME), EXIT_FAILURE);
|
TEST_IPC_Q(ipc_server_init (&ctx, SERVICE_NAME), EXIT_FAILURE);
|
||||||
|
|
||||||
printf ("func 01 - server init ok\n");
|
printf ("func 01 - server init ok\n");
|
||||||
SECURE_DECLARATION(struct ipc_ctx, clients);
|
|
||||||
SECURE_DECLARATION(struct ipc_event,event);
|
SECURE_DECLARATION(struct ipc_event,event);
|
||||||
|
|
||||||
printf ("func 01 - service polling...\n");
|
printf ("func 01 - service polling...\n");
|
||||||
|
|
Reference in New Issue