Use the '{' '}' for local block(if, for, while, ...) even if it has A line.
Change-Id: I29a8d8ab2c6023db66312b2d2ca93b8c4440248a
Name: libcom-core
Summary: Library for the light-weight IPC
-Version: 0.5.0
+Version: 0.5.1
Release: 1
Group: HomeTF/Framework
License: Apache License
}
DbgPrint("New connectino arrived: server(%d), client(%d)\n", socket_fd, client_fd);
- if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
- if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0)
+ if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
gio = g_io_channel_unix_new(client_fd);
if (!gio) {
return fd;
}
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
ErrPrint("fcntl: %s\n", strerror(errno));
+ }
- if (!is_sync && fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+ if (!is_sync && fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
ErrPrint("fcntl: %s\n", strerror(errno));
+ }
DbgPrint("Create new IO channel for server FD: %d\n", fd);
gio = g_io_channel_unix_new(fd);
return client_fd;
}
- if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
- if (!is_sync && fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0)
+ if (!is_sync && fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
gio = g_io_channel_unix_new(client_fd);
if (!gio) {
cbdata->evt_cb = evt_cb;
cbdata->data = data;
- if (type == CONNECTOR_CONNECTED)
+ if (type == CONNECTOR_CONNECTED) {
s_info.conn_cb_list = dlist_append(s_info.conn_cb_list, cbdata);
- else
+ } else {
s_info.disconn_cb_list = dlist_append(s_info.disconn_cb_list, cbdata);
+ }
return 0;
}
struct dlist *n;
dlist_foreach_safe(s_info.request_list, l, n, ctx) {
- if (ctx->handle != handle)
+ if (ctx->handle != handle) {
continue;
+ }
- if (ctx->recv_cb)
+ if (ctx->recv_cb) {
ctx->recv_cb(-1, handle, NULL, ctx->data);
+ }
destroy_request_ctx(ctx);
}
* Find the client list
*/
dlist_foreach(router->info.server.client_list, cl, client) {
- if (client->handle == handle)
+ if (client->handle == handle) {
return router;
+ }
}
} else if (router->handle == handle) {
return router;
break;
}
- if (request->recv_cb)
+ if (request->recv_cb) {
request->recv_cb(pid, handle, packet, request->data);
+ }
destroy_request_ctx(request);
break;
}
ret = put_send_packet(router, handle, packet);
- if (ret < 0)
+ if (ret < 0) {
ErrPrint("Failed to send a packet\n");
+ }
break;
case PACKET_ERROR:
default:
result = NULL;
for (i = 0; table[i].cmd; i++) {
- if (strcmp(table[i].cmd, packet_command(packet)))
+ if (strcmp(table[i].cmd, packet_command(packet))) {
continue;
+ }
result = table[i].handler(pid, handle, packet);
break;
FD_SET(handle, &set);
status = pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+ }
if (timeout > 0.0f) {
struct timeval tv;
} else {
ErrPrint("Invalid timeout: %lf (it must be greater than 0.0)\n", timeout);
status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+ }
return -EINVAL;
}
ErrPrint("Error: %s\n", strerror(errno));
status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+ }
return ret;
} else if (ret == 0) {
ErrPrint("Timeout expired\n");
status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+ }
return -ETIMEDOUT;
}
status = pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, NULL);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to set cancelstate: %s\n", strerror(status));
+ }
if (!FD_ISSET(handle, &set)) {
ErrPrint("Unexpected handle is toggled\n");
* select event has cancel point
*/
ret = select_event(router->send_pipe[PIPE_READ], 0.0f);
- if (ret == -EAGAIN)
+ if (ret == -EAGAIN) {
continue;
+ }
- if (ret < 0)
+ if (ret < 0) {
break;
+ }
packet = get_send_packet(router, &handle);
if (!packet) {
if (ret != 0) {
ErrPrint("Mutex craetion failed: %s\n", strerror(ret));
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
free(router);
return NULL;
ErrPrint("Mutex creation failed: %s\n", strerror(ret));
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->route_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
free(router);
return NULL;
if (!router->sock) {
ErrPrint("Heap: %s\n", strerror(errno));
ret = pthread_mutex_destroy(&router->send_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->route_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
free(router);
return NULL;
free(router->sock);
ret = pthread_mutex_destroy(&router->send_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->route_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
free(router);
return NULL;
CLOSE_PIPE(router->recv_pipe);
ret = pthread_mutex_destroy(&router->send_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->route_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
free(router);
return NULL;
free(router->sock);
ret = pthread_mutex_destroy(&router->send_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->route_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
free(router);
return NULL;
free(router->sock);
ret = pthread_mutex_destroy(&router->send_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->route_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
free(router);
return NULL;
free(router->sock);
ret = pthread_mutex_destroy(&router->send_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->route_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
free(router);
return NULL;
DbgPrint("Put NULL Packet to terminate send thread (%d)\n", ret);
ret = pthread_join(router->send_thid, NULL);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Join: %s\n", strerror(ret));
+ }
dlist_remove_data(s_info.router_list, router);
- if (router->id > 0)
+ if (router->id > 0) {
g_source_remove(router->id);
+ }
CLOSE_PIPE(router->recv_pipe);
CLOSE_PIPE(router->send_pipe);
free(router->sock);
ret = pthread_mutex_destroy(&router->send_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->recv_packet_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
ret = pthread_mutex_destroy(&router->route_list_lock);
- if (ret != 0)
+ if (ret != 0) {
ErrPrint("Mutex destroy failed: %s\n", strerror(ret));
+ }
handle = router->handle;
free(router);
*
* We have to optimize the processing time in the CRITICAL SECTION
*/
- if (put_send_packet(router, route->handle, packet) < 0)
+ if (put_send_packet(router, route->handle, packet) < 0) {
ErrPrint("Failed to send whole packet\n");
+ }
processed++;
}
* \note
* Producing an event on event pipe
*/
- if (write(router->send_pipe[PIPE_WRITE], &handle, sizeof(handle)) != sizeof(handle))
+ if (write(router->send_pipe[PIPE_WRITE], &handle, sizeof(handle)) != sizeof(handle)) {
ErrPrint("Failed to put an event: %s\n", strerror(errno));
+ }
return 0;
}
* \note
* Producing an event on event pipe
*/
- if (write(router->recv_pipe[PIPE_WRITE], &handle, sizeof(handle)) != sizeof(handle))
+ if (write(router->recv_pipe[PIPE_WRITE], &handle, sizeof(handle)) != sizeof(handle)) {
ErrPrint("Failed to put an event: %s\n", strerror(errno));
+ }
return 0;
}
CRITICAL_SECTION_END(&router->send_packet_list_lock);
- if (read(router->send_pipe[PIPE_READ], handle, sizeof(*handle)) != sizeof(*handle))
+ if (read(router->send_pipe[PIPE_READ], handle, sizeof(*handle)) != sizeof(*handle)) {
ErrPrint("Failed to get an event: %s\n", strerror(errno));
+ }
return packet;
}
router->recv_packet_list = dlist_remove(router->recv_packet_list, l);
packet = item->packet;
- if (pid)
+ if (pid) {
*pid = item->pid;
+ }
free(item);
}
* Even if we cannot get the packet(NULL), we should consuming event
* Because the NULL packet means disconnected
*/
- if (read(router->recv_pipe[PIPE_READ], handle, sizeof(*handle)) != sizeof(*handle))
+ if (read(router->recv_pipe[PIPE_READ], handle, sizeof(*handle)) != sizeof(*handle)) {
ErrPrint("Failed to get an event: %s\n", strerror(errno));
+ }
return packet;
}
ctx->packet = packet_build(ctx->packet, ctx->offset, ptr, ret);
free(ptr);
- if (!ctx->packet)
+ if (!ctx->packet) {
return -EFAULT;
+ }
ctx->offset += ret;
if (ctx->offset == packet_header_size()) {
- if (packet_size(ctx->packet) == ctx->offset)
+ if (packet_size(ctx->packet) == ctx->offset) {
ctx->state = RECV_STATE_READY;
- else
+ } else {
ctx->state = RECV_STATE_BODY;
+ }
}
break;
case RECV_STATE_BODY:
ctx->packet = packet_build(ctx->packet, ctx->offset, ptr, ret);
free(ptr);
- if (!ctx->packet)
+ if (!ctx->packet) {
return -EFAULT;
+ }
ctx->offset += ret;
- if (ctx->offset == packet_size(ctx->packet))
+ if (ctx->offset == packet_size(ctx->packet)) {
ctx->state = RECV_STATE_READY;
+ }
break;
case RECV_STATE_READY:
* select event has cancel point
*/
ret = select_event(handle, ctx->timeout);
- if (ret == -EAGAIN)
+ if (ret == -EAGAIN) {
continue;
+ }
if (ret < 0) {
packet_destroy(ctx->packet);
* If the destination address is ZERO,
* Pull up the packet to this server.
*/
- if (packet_destination(ctx->packet))
+ if (packet_destination(ctx->packet)) {
route_packet(router, handle, ctx->packet);
- else
+ } else {
put_recv_packet(router, handle, ctx->packet, ctx->pid);
+ }
ctx->state = RECV_STATE_INIT;
}
return FALSE;
}
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
- if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
client = calloc(1, sizeof(*client));
if (!client) {
GIOChannel *gio;
handle = secure_socket_create_server(sock);
- if (handle < 0)
+ if (handle < 0) {
return handle;
+ }
router = create_router(sock, handle, table);
if (!router) {
int status;
handle = secure_socket_create_client(sock);
- if (handle < 0)
+ if (handle < 0) {
return handle;
+ }
router = create_router(sock, handle, table);
if (!router) {
router->info.server.client_list = dlist_remove(router->info.server.client_list, l);
status = pthread_cancel(client->thid);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to cacnel a thread: %s\n", strerror(errno));
+ }
ret = NULL;
status = pthread_join(client->thid, &ret);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to join a thread: %s\n", strerror(errno));
+ }
if (ret == PTHREAD_CANCELED) {
DbgPrint("Thread is canceled\n");
}
status = pthread_cancel(router->info.client.thid);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to cancel a thread: %s\n", strerror(errno));
+ }
status = pthread_join(router->info.client.thid, &ret);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to join a thread: %s\n", strerror(errno));
+ }
if (ret == PTHREAD_CANCELED) {
DbgPrint("Thread is canceled\n");
struct router *router;
int ret;
- if (handle < 0 || !packet)
+ if (handle < 0 || !packet) {
return -EINVAL;
+ }
if (packet_type(packet) != PACKET_REQ) {
ErrPrint("Invalid packet - should be PACKET_REQ\n");
}
ctx = create_request_ctx(handle);
- if (!ctx)
+ if (!ctx) {
return -ENOMEM;
+ }
ctx->recv_cb = recv_cb;
ctx->data = data;
ctx->packet = packet_ref(packet);
ret = put_send_packet(router, handle, packet);
- if (ret < 0)
+ if (ret < 0) {
destroy_request_ctx(ctx);
+ }
return ret;
}
{
struct router *router;
- if (handle < 0 || !packet || packet_type(packet) != PACKET_REQ_NOACK)
+ if (handle < 0 || !packet || packet_type(packet) != PACKET_REQ_NOACK) {
return -EINVAL;
+ }
router = find_router_by_handle(handle);
if (!router) {
struct dlist *l;
int found = 0;
- if (handle < 0 || !address || h < 0)
+ if (handle < 0 || !address || h < 0) {
return -EINVAL;
+ }
router = find_router_by_handle(handle);
if (!router) {
}
}
- if (!found)
+ if (!found) {
router->route_list = dlist_append(router->route_list, route);
+ }
CRITICAL_SECTION_END(&router->route_list_lock);
struct dlist *n;
int found = 0;
- if (handle < 0 || !address)
+ if (handle < 0 || !address) {
return -EINVAL;
+ }
router = find_router_by_handle(handle);
if (!router) {
CRITICAL_SECTION_BEGIN(&router->route_list_lock);
dlist_foreach_safe(router->route_list, l, n, route) {
- if (route->address != address)
+ if (route->address != address) {
continue;
+ }
router->route_list = dlist_remove(router->route_list, l);
struct dlist *l;
int found = 0;
- if (handle < 0 || !address || h < 0)
+ if (handle < 0 || !address || h < 0) {
return -EINVAL;
+ }
router = find_router_by_handle(handle);
if (!router) {
CRITICAL_SECTION_BEGIN(&router->route_list_lock);
dlist_foreach(router->route_list, l, route) {
- if (route->address != address)
+ if (route->address != address) {
continue;
+ }
route->handle = h;
route->invalid = 0;
struct dlist *l;
dlist_foreach(s_info.recv_list, l, ctx) {
- if (ctx->handle == handle)
+ if (ctx->handle == handle) {
return ctx;
+ }
}
return NULL;
break;
case PACKET_REQ:
for (i = 0; table[i].cmd; i++) {
- if (strcmp(table[i].cmd, packet_command(receive->packet)))
+ if (strcmp(table[i].cmd, packet_command(receive->packet))) {
continue;
+ }
result = table[i].handler(receive->pid, handle, receive->packet);
if (result) {
break;
case PACKET_REQ_NOACK:
for (i = 0; table[i].cmd; i++) {
- if (strcmp(table[i].cmd, packet_command(receive->packet)))
+ if (strcmp(table[i].cmd, packet_command(receive->packet))) {
continue;
+ }
result = table[i].handler(receive->pid, handle, receive->packet);
- if (result)
+ if (result) {
packet_destroy(result);
+ }
}
break;
default:
int referred = 0;
receive = find_recv_ctx(handle);
- if (receive)
+ if (receive) {
pid = receive->pid;
+ }
DbgPrint("Clean up all requests and a receive context for handle(%d) for pid(%d)\n", handle, pid);
dlist_foreach_safe(s_info.request_list, l, n, request) {
- if (request->handle != handle)
+ if (request->handle != handle) {
continue;
+ }
if (request->in_recv) {
referred = 1;
continue;
}
- if (request->recv_cb)
+ if (request->recv_cb) {
request->recv_cb(pid, handle, NULL, request->data);
+ }
destroy_request_ctx(request);
}
- if (receive && !referred)
+ if (receive && !referred) {
destroy_recv_ctx(receive);
+ }
return 0;
}
receive->offset += ret;
if (receive->offset == packet_header_size()) {
- if (packet_size(receive->packet) == receive->offset)
+ if (packet_size(receive->packet) == receive->offset) {
receive->state = RECV_STATE_READY;
- else
+ } else {
receive->state = RECV_STATE_BODY;
+ }
}
} else {
DbgPrint("ZERO bytes receives(%d)\n", pid);
if (receive->state == RECV_STATE_READY) {
ret = packet_ready(handle, receive, data);
- if (ret == 0)
+ if (ret == 0) {
destroy_recv_ctx(receive);
+ }
/*!
* if ret is negative value, disconnected_cb will be called after this function
*/
}
ctx = create_request_ctx(handle);
- if (!ctx)
+ if (!ctx) {
return -ENOMEM;
+ }
ctx->recv_cb = recv_cb;
ctx->data = data;
}
fd = secure_socket_create_client(addr);
- if (fd < 0)
+ if (fd < 0) {
return NULL;
+ }
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
ErrPrint("fcntl: %s\n", strerror(errno));
+ }
- if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
ret = com_core_send(fd, (char *)packet_data(packet), packet_size(packet), DEFAULT_TIMEOUT);
- if (ret < 0)
+ if (ret < 0) {
goto out;
+ }
ptr = malloc(packet_header_size());
if (!ptr) {
static inline int com_core_packet_init(void)
{
int ret;
- if (s_info.initialized)
+ if (s_info.initialized) {
return 0;
+ }
ret = com_core_add_event_callback(CONNECTOR_DISCONNECTED, client_disconnected_cb, NULL);
s_info.initialized = (ret == 0);
static inline int com_core_packet_fini(void)
{
- if (!s_info.initialized)
+ if (!s_info.initialized) {
return 0;
+ }
s_info.initialized = 0;
com_core_del_event_callback(CONNECTOR_DISCONNECTED, client_disconnected_cb, NULL);
int ret;
ret = com_core_packet_init();
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
ret = s_info.vtable.client_create(addr, is_sync, service_cb, table);
- if (ret < 0)
+ if (ret < 0) {
com_core_packet_fini();
+ }
return ret;
}
int ret;
ret = com_core_packet_init();
- if (ret < 0)
+ if (ret < 0) {
return ret;
+ }
ret = s_info.vtable.server_create(addr, 0, service_cb, table);
- if (ret < 0)
+ if (ret < 0) {
com_core_packet_fini();
+ }
return ret;
}
{
dlist_remove_data(s_info.server_list, server);
- if (server->id > 0)
+ if (server->id > 0) {
g_source_remove(server->id);
+ }
- if (server->handle > 0)
+ if (server->handle > 0) {
secure_socket_destroy_handle(server->handle);
+ }
free(server);
}
void *res = NULL;
struct chunk *chunk;
- if (write(tcb->ctrl_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb))
+ if (write(tcb->ctrl_pipe[PIPE_WRITE], &tcb, sizeof(tcb)) != sizeof(tcb)) {
ErrPrint("Unable to write CTRL pipe\n");
+ }
secure_socket_destroy_handle(tcb->handle);
status = pthread_join(tcb->thid, &res);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Join: %s\n", strerror(status));
+ }
else
ErrPrint("Thread returns: %d\n", (int)res);
return;
}
- if (ret != sizeof(event_ch))
+ if (ret != sizeof(event_ch)) {
ErrPrint("Failed to trigger reader\n");
+ }
/* Take a breathe */
pthread_yield();
DbgPrint("Client CB is terminated (%d)\n", tcb->handle);
/* Wake up main thread to get disconnected event */
event_ch = EVENT_TERM;
- if (write(tcb->evt_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch))
+ if (write(tcb->evt_pipe[PIPE_WRITE], &event_ch, sizeof(event_ch)) != sizeof(event_ch)) {
ErrPrint("write: %s\n", strerror(errno));
+ }
return (void *)ret;
}
dlist_remove_data(s_info.tcb_list, tcb);
- if (tcb->id > 0)
+ if (tcb->id > 0) {
g_source_remove(tcb->id);
+ }
CLOSE_PIPE(tcb->evt_pipe);
CLOSE_PIPE(tcb->ctrl_pipe);
status = pthread_mutex_destroy(&tcb->chunk_lock);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Failed to destroy mutex: %s\n", strerror(status));
+ }
free(tcb);
}
if (pipe2(tcb->evt_pipe, (is_sync ? 0 : O_NONBLOCK) | O_CLOEXEC) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
status = pthread_mutex_destroy(&tcb->chunk_lock);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Error: %s\n", strerror(status));
+ }
free(tcb);
return NULL;
}
CLOSE_PIPE(tcb->evt_pipe);
status = pthread_mutex_destroy(&tcb->chunk_lock);
- if (status != 0)
+ if (status != 0) {
ErrPrint("Error: %s\n", strerror(status));
+ }
free(tcb);
return NULL;
return FALSE;
}
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
- if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+ if (fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
tcb = tcb_create(fd, 0, server->service_cb, server->data);
if (!tcb) {
if (client_fd < 0)
return client_fd;
- if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(client_fd, F_SETFD, FD_CLOEXEC) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
- if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0)
+ if (fcntl(client_fd, F_SETFL, O_NONBLOCK) < 0) {
ErrPrint("Error: %s\n", strerror(errno));
+ }
tcb = tcb_create(client_fd, is_sync, service_cb, data);
if (!tcb) {
struct server *server;
fd = secure_socket_create_server(addr);
- if (fd < 0)
+ if (fd < 0) {
return fd;
+ }
- if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0)
+ if (fcntl(fd, F_SETFD, FD_CLOEXEC) < 0) {
ErrPrint("fcntl: %s\n", strerror(errno));
+ }
- if (!is_sync && fcntl(fd, F_SETFL, O_NONBLOCK) < 0)
+ if (!is_sync && fcntl(fd, F_SETFL, O_NONBLOCK) < 0) {
ErrPrint("fcntl: %s\n", strerror(errno));
+ }
server = server_create(fd, service_cb, data);
if (!server) {
struct tcb *tcb;
dlist_foreach(s_info.tcb_list, l, tcb) {
- if (tcb->handle == handle)
+ if (tcb->handle == handle) {
return tcb;
+ }
}
return NULL;
*sender_pid = chunk->pid;
- if (chunk->offset == chunk->size)
+ if (chunk->offset == chunk->size) {
chunk_remove(tcb, chunk);
+ }
}
return readsize;
struct server *server;
dlist_foreach_safe(s_info.tcb_list, l, n, tcb) {
- if (tcb->server_handle != handle)
+ if (tcb->server_handle != handle) {
continue;
+ }
invoke_disconn_cb_list(handle);
terminate_thread(tcb);
}
dlist_foreach_safe(s_info.server_list, l, n, server) {
- if (server->handle != handle)
+ if (server->handle != handle) {
continue;
+ }
invoke_disconn_cb_list(handle);
server_destroy(server);
struct tcb *tcb;
tcb = find_tcb_by_handle(handle);
- if (!tcb)
+ if (!tcb) {
return -ENOENT;
+ }
invoke_disconn_cb_list(handle);
terminate_thread(tcb);
struct dlist *item;
item = malloc(sizeof(*item));
- if (!item)
+ if (!item) {
return NULL;
+ }
item->next = NULL;
item->data = data;
struct dlist *item;
item = malloc(sizeof(*item));
- if (!item)
+ if (!item) {
return NULL;
+ }
item->data = data;
struct dlist *dlist_remove(struct dlist *list, struct dlist *l)
{
- if (!list || !l)
+ if (!list || !l) {
return NULL;
+ }
- if (l == list)
+ if (l == list) {
list = l->next;
- else
+ } else {
l->prev->next = l->next;
+ }
- if (l->next)
+ if (l->next) {
l->next->prev = l->prev;
+ }
/*!
* \note
* If the removed entry 'l' has no next element, it is the last element.
*
* If we didn't care about this, the head element(list) can indicates the invalid element.
*/
- else if (list)
+ else if (list) {
list->prev = l->prev;
+ }
free(l);
return list;
void *_data;
dlist_foreach(list, l, _data) {
- if (data == _data)
+ if (data == _data) {
return l;
+ }
}
return NULL;
i = 0;
for (n = l; n; n = n->next) {
- if (i == nth)
+ if (i == nth) {
return n;
+ }
i++;
}
EAPI const enum packet_type const packet_type(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return PACKET_ERROR;
+ }
return packet->data->head.type;
}
EAPI unsigned long packet_mask(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return 0;
+ }
return packet->data->head.mask;
}
EAPI int packet_set_mask(struct packet *packet, unsigned long mask)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return -EINVAL;
+ }
packet->data->head.mask = mask;
return 0;
EAPI const enum packet_flag const packet_flag(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return PACKET_FLAG_ERROR;
+ }
return packet->data->head.flag;
}
EAPI int packet_set_flag(struct packet *packet, enum packet_flag flag)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return -EINVAL;
+ }
packet->data->head.flag = flag;
return 0;
EAPI const unsigned long const packet_source(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return 0;
+ }
return packet->data->head.source;
}
EAPI int packet_set_source(struct packet *packet, unsigned long source)
{
- if (!packet || packet->state != VALID || !packet->data || !source)
+ if (!packet || packet->state != VALID || !packet->data || !source) {
return -EINVAL;
+ }
packet->data->head.source = source;
return 0;
EAPI const unsigned long const packet_destination(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return 0;
+ }
return packet->data->head.destination;
}
EAPI int packet_set_destination(struct packet *packet, unsigned long destination)
{
- if (!packet || packet->state != VALID || !packet->data || !destination)
+ if (!packet || packet->state != VALID || !packet->data || !destination) {
return -EINVAL;
+ }
packet->data->head.destination = destination;
return 0;
EAPI const int const packet_version(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return PACKET_ERROR;
+ }
return packet->data->head.version;
}
EAPI const int const packet_size(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return -EINVAL;
+ }
return sizeof(*packet->data) + packet->data->head.payload_size;
}
EAPI const double const packet_seq(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return 0;
+ }
return packet->data->head.seq;
}
EAPI const int const packet_payload_size(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return -EINVAL;
+ }
return packet->data->head.payload_size;
}
EAPI const char * const packet_command(const struct packet *packet)
{
- if (!packet || packet->state != VALID || !packet->data)
+ if (!packet || packet->state != VALID || !packet->data) {
return NULL;
+ }
return packet->data->head.command;
}
EAPI const void * const packet_data(const struct packet *packet)
{
- if (!packet || packet->state != VALID)
+ if (!packet || packet->state != VALID) {
return NULL;
+ }
return packet->data;
}
{
struct data *new_packet;
- if (packet->head.payload_size < *payload_size)
+ if (packet->head.payload_size < *payload_size) {
return packet;
+ }
new_packet = realloc(packet, sizeof(*packet) + *payload_size + BUFSIZ); /*!< Expanding to +BUFSIZ */
if (!new_packet) {
struct packet *result;
va_list va;
- if (!packet || packet->state != VALID)
+ if (!packet || packet->state != VALID) {
return NULL;
+ }
result = malloc(sizeof(*result));
if (!result) {
{
unsigned long tmp;
- if (!packet || packet->state != VALID)
+ if (!packet || packet->state != VALID) {
return -EINVAL;
+ }
tmp = packet->data->head.source;
packet->data->head.source = packet->data->head.destination;
double *double_ptr;
char **str_ptr;
- if (!packet || packet->state != VALID)
+ if (!packet || packet->state != VALID) {
return -EINVAL;
+ }
va_start(va, fmt);
EAPI struct packet *packet_ref(struct packet *packet)
{
- if (!packet || packet->state != VALID)
+ if (!packet || packet->state != VALID) {
return NULL;
+ }
packet->refcnt++;
return packet;
EAPI struct packet *packet_unref(struct packet *packet)
{
- if (!packet || packet->state != VALID)
+ if (!packet || packet->state != VALID) {
return NULL;
+ }
packet->refcnt--;
if (packet->refcnt < 0) {
in_addr->sin_port = htons(port);
in_addr->sin_family = AF_INET;
- if (*peer == '\0')
+ if (*peer == '\0') {
in_addr->sin_addr.s_addr = htonl(INADDR_ANY);
- else
+ } else {
in_addr->sin_addr.s_addr = inet_addr(peer);
+ }
handle = socket(AF_INET, SOCK_STREAM, 0);
if (handle < 0) {
peer += COM_CORE_LOCAL_SCHEME_LEN;
addr = strdup(peer);
- if (!addr)
+ if (!addr) {
ErrPrint("Heap: %s\n", strerror(errno));
+ }
vtable->create_socket = create_unix_socket;
vtable->setup_handle = setup_unix_handle;
goto out;
}
- if (len > 0)
+ if (len > 0) {
strncpy(addr, peer, len);
+ }
+
addr[len] = '\0';
peer += len + 1;
handle = vtable.create_socket(addr, port, sockaddr);
free(addr);
- if (handle < 0)
+ if (handle < 0) {
return handle;
+ }
ret = connect(handle, sockaddr, addrlen);
if (ret < 0) {
ret = -errno;
ErrPrint("Failed to connect to server [%s] %s\n",
peer, strerror(errno));
- if (close(handle) < 0)
+ if (close(handle) < 0) {
ErrPrint("close: %s\n", strerror(errno));
+ }
return ret;
}
ret = vtable.setup_handle(handle);
if (ret < 0) {
- if (close(handle) < 0)
+ if (close(handle) < 0) {
ErrPrint("close: %s\n", strerror(errno));
+ }
return ret;
}
handle = vtable.create_socket(addr, port, sockaddr);
free(addr);
- if (handle < 0)
+ if (handle < 0) {
return handle;
+ }
ret = bind(handle, sockaddr, addrlen);
if (ret < 0) {
ret = -errno;
ErrPrint("bind: %s\n", strerror(errno));
- if (close(handle) < 0)
+ if (close(handle) < 0) {
ErrPrint("close: %s\n", strerror(errno));
+ }
return ret;
}
if (ret < 0) {
ret = -errno;
ErrPrint("listen: %s\n", strerror(errno));
- if (close(handle) < 0)
+ if (close(handle) < 0) {
ErrPrint("close: %s\n", strerror(errno));
+ }
return ret;
}
if (vtable.type == SCHEME_LOCAL) {
- if (chmod(peer, 0666) < 0)
+ if (chmod(peer, 0666) < 0) {
ErrPrint("Failed to change the permission of a socket (%s)\n", strerror(errno));
+ }
}
return handle;
if (addr->sa_family == AF_UNIX) {
ret = setup_unix_handle(handle);
if (ret < 0) {
- if (close(handle) < 0)
+ if (close(handle) < 0) {
ErrPrint("close: %s\n", strerror(errno));
+ }
handle = ret;
}
} else if (addr->sa_family == AF_INET) {
ret = setup_inet_handle(handle);
if (ret < 0) {
- if (close(handle) < 0)
+ if (close(handle) < 0) {
ErrPrint("close: %s\n", strerror(errno));
+ }
handle = ret;
}
int _pid;
int ret;
- if (size <= 0 || !buffer)
+ if (size <= 0 || !buffer) {
return -EINVAL;
+ }
- if (!sender_pid)
+ if (!sender_pid) {
sender_pid = &_pid;
+ }
memset(&msg, 0, sizeof(msg));
iov.iov_base = buffer;