API change: ipc_context_deinit now frees context memory.
This commit is contained in:
parent
21ecf157d1
commit
51cad2c07d
@ -26,7 +26,7 @@ enum cb_event_types {
|
||||
int ipc_context_init (void** ptr);
|
||||
int ipc_service_init (void* ctx, int* servicefd, const char* service_name, uint16_t service_name_len);
|
||||
int ipc_connect_service (void* ctx, int* servicefd, const char* service_name, uint16_t service_name_len);
|
||||
void ipc_context_deinit (void* ctx);
|
||||
void ipc_context_deinit (void** ctx);
|
||||
int ipc_write (void* ctx, int servicefd, char* mcontent, uint32_t mlen);
|
||||
int ipc_schedule (void* ctx, int servicefd, const char* mcontent, uint32_t mlen);
|
||||
int ipc_read_fd (void* ctx, int fd, char* buffer, size_t* buflen);
|
||||
|
@ -29,8 +29,10 @@ export fn ipc_connect_service (ctx: *Context, servicefd: *i32, service_name: [*]
|
||||
return 0;
|
||||
}
|
||||
|
||||
export fn ipc_context_deinit (ctx: *Context) callconv(.C) void {
|
||||
ctx.deinit();
|
||||
export fn ipc_context_deinit (ctx: **Context) callconv(.C) void {
|
||||
var ptr: *Context = ctx.*;
|
||||
ptr.deinit();
|
||||
std.heap.c_allocator.destroy(ptr);
|
||||
}
|
||||
|
||||
/// Write a message (no waiting).
|
||||
|
@ -36,8 +36,7 @@ int direct_write_then_read(void) {
|
||||
if (ret != 0) {
|
||||
printf ("Cannot connect to a service.\n");
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -47,8 +46,7 @@ int direct_write_then_read(void) {
|
||||
if (ret != 0) {
|
||||
printf ("Cannot write to the service.\n");
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -60,16 +58,14 @@ int direct_write_then_read(void) {
|
||||
if (ret != 0) {
|
||||
printf ("Cannot read from the service fd: %d.\n", ret);
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (size == 0) {
|
||||
printf ("No message returned.\n");
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -77,9 +73,7 @@ int direct_write_then_read(void) {
|
||||
printf ("Response: %s.\n", message);
|
||||
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
|
||||
printf ("Context freed.\n");
|
||||
return 0;
|
||||
@ -102,8 +96,7 @@ int wait_event(void) {
|
||||
if (ret != 0) {
|
||||
printf ("Cannot init context.\n");
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -113,8 +106,7 @@ int wait_event(void) {
|
||||
if (ret != 0) {
|
||||
printf ("Cannot connect to a service.\n");
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -124,8 +116,7 @@ int wait_event(void) {
|
||||
if (ret != 0) {
|
||||
printf ("Cannot schedule a message.\n");
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -194,9 +185,7 @@ int wait_event(void) {
|
||||
}
|
||||
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
|
||||
printf ("Context freed.\n");
|
||||
return 0;
|
||||
|
@ -121,9 +121,7 @@ int main(int argc, char**argv) {
|
||||
}
|
||||
|
||||
printf ("Deinit context\n");
|
||||
ipc_context_deinit (ctx);
|
||||
|
||||
free(ctx);
|
||||
ipc_context_deinit (&ctx);
|
||||
|
||||
printf ("Context freed.\n");
|
||||
return 0;
|
||||
|
Reference in New Issue
Block a user