From 2619d50de3b777e0d37d0f68c67075e7ee163218 Mon Sep 17 00:00:00 2001 From: Jaepil Choi Date: Mon, 22 Apr 2013 19:55:46 +0900 Subject: [PATCH] 0.0.28-1 has been merged Change-Id: I913b712dbece410675efb88c1919a5fc8a910ac8 --- CMakeLists.txt | 2 +- LICENSE.APLv2 | 2 +- NOTICE | 2 +- include/pims-ipc-data.h | 2 +- include/pims-ipc-svc.h | 2 +- include/pims-ipc-types.h | 2 +- include/pims-ipc.h | 2 +- packaging/pims-ipc.spec | 4 +-- pims-ipc.manifest.in | 4 +-- src/pims-debug.h | 4 +-- src/pims-internal.h | 2 +- src/pims-ipc-data.c | 2 +- src/pims-ipc-svc.c | 33 +++++++++++++++++++------ src/pims-ipc.c | 64 +++++++++++++++++++++++++++++++++++++++++++----- src/pims-socket.c | 2 +- src/pims-socket.h | 2 +- test/sock-test.c | 2 +- test/test.c | 2 +- 18 files changed, 103 insertions(+), 32 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 655c15f..5631d18 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ SET(EXEC_PREFIX "\${prefix}") SET(INCLUDEDIR "\${prefix}/${DEST_INCLUDE_DIR}") SET(VERSION_MAJOR 0) -SET(VERSION "${VERSION_MAJOR}.0.1") +SET(VERSION "${VERSION_MAJOR}.0.28") INCLUDE_DIRECTORIES(${SRC_INCLUDE_DIR}) #SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -I${CMAKE_SOURCE_DIR}/src -I${SRC_INCLUDE_DIR} -D_NON_SLP") diff --git a/LICENSE.APLv2 b/LICENSE.APLv2 index bae7f54..311e5ba 100644 --- a/LICENSE.APLv2 +++ b/LICENSE.APLv2 @@ -1,4 +1,4 @@ -Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. +Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. Apache License Version 2.0, January 2004 diff --git a/NOTICE b/NOTICE index 4c49449..d34af37 100644 --- a/NOTICE +++ b/NOTICE @@ -1 +1 @@ -Copyright (c) 2000 - 2012 Samsung Electronics Co., Ltd. All rights reserved. +Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. diff --git a/include/pims-ipc-data.h b/include/pims-ipc-data.h index e3bc131..5c8e0f4 100644 --- a/include/pims-ipc-data.h +++ b/include/pims-ipc-data.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/include/pims-ipc-svc.h b/include/pims-ipc-svc.h index 0f85bb8..7946626 100644 --- a/include/pims-ipc-svc.h +++ b/include/pims-ipc-svc.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/include/pims-ipc-types.h b/include/pims-ipc-types.h index 3244c34..54d4c2f 100644 --- a/include/pims-ipc-types.h +++ b/include/pims-ipc-types.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/include/pims-ipc.h b/include/pims-ipc.h index f192ec9..fe7837c 100644 --- a/include/pims-ipc.h +++ b/include/pims-ipc.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/packaging/pims-ipc.spec b/packaging/pims-ipc.spec index 8db0eb1..ee4e6f2 100644 --- a/packaging/pims-ipc.spec +++ b/packaging/pims-ipc.spec @@ -1,6 +1,6 @@ Name: pims-ipc Summary: library for PIMs IPC -Version: 0.0.22 +Version: 0.0.28 Release: 1 Group: System/Libraries License: Apache-2.0 @@ -18,7 +18,7 @@ library for PIMs IPC %package devel Summary: DB library for calendar Group: Development/Libraries -Requires: %{name} = %{version} +Requires: %{name} = %{version}-%{release} %description devel library for PIMs IPC (developement files) diff --git a/pims-ipc.manifest.in b/pims-ipc.manifest.in index d0a5026..f9162a6 100644 --- a/pims-ipc.manifest.in +++ b/pims-ipc.manifest.in @@ -3,8 +3,8 @@ - - + + diff --git a/src/pims-debug.h b/src/pims-debug.h index 055ed62..62b7076 100644 --- a/src/pims-debug.h +++ b/src/pims-debug.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -44,7 +44,7 @@ extern "C" #define LOG_WARN "WARN" #define LOG_ERROR "ERROR" #define __ug_log(logtype, tag, frmt, args...) \ - do {printf("[%s][%s][%08x] %s:%s(%d) > "frmt"\n", logtype, tag, (unsigned int)pthread_self(), __MODULE__, __FUNCTION__, __LINE__, ##args);} while (0) + do {printf("[%s][%s][%08x] %s:%s(%d) > "frmt"\n", logtype, tag, (unsigned int)pthread_self(), __FILE__, __FUNCTION__, __LINE__, ##args);} while (0) #endif #define pims_verbose(tag, frmt, args...) __ug_log(LOG_VERBOSE, tag, frmt, ##args) diff --git a/src/pims-internal.h b/src/pims-internal.h index 98de999..03c5736 100644 --- a/src/pims-internal.h +++ b/src/pims-internal.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/pims-ipc-data.c b/src/pims-ipc-data.c index 86d39be..fa0ee5d 100644 --- a/src/pims-ipc-data.c +++ b/src/pims-ipc-data.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/pims-ipc-svc.c b/src/pims-ipc-svc.c index 86a05c1..ef48e0c 100644 --- a/src/pims-ipc-svc.c +++ b/src/pims-ipc-svc.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -71,6 +71,15 @@ typedef struct static pims_ipc_svc_t *_g_singleton = NULL; static pims_ipc_svc_for_publish_t *_g_singleton_for_publish = NULL; +#define PIMS_IPC_STRING_WORKER_ID_SIZE 10 +static char* __get_string_worker_id(int worker_id, char *string_worker_id) +{ + snprintf(string_worker_id, PIMS_IPC_STRING_WORKER_ID_SIZE, "%08x00", worker_id); + string_worker_id[PIMS_IPC_STRING_WORKER_ID_SIZE] = 0x0; + + return string_worker_id; +} + API int pims_ipc_svc_init(char *service, gid_t group, mode_t mode) { if (_g_singleton) @@ -458,7 +467,9 @@ static void* __worker_loop(void *args) ERROR("socket error : %s", zmq_strerror(errno)); return NULL; } - if (zmq_setsockopt(worker, ZMQ_IDENTITY, &worker_id, sizeof(int)) != 0) + char string_worker_id[PIMS_IPC_STRING_WORKER_ID_SIZE + 1] = ""; + if (zmq_setsockopt(worker, ZMQ_IDENTITY, __get_string_worker_id(worker_id, string_worker_id), + PIMS_IPC_STRING_WORKER_ID_SIZE) != 0) { ERROR("setsockopt error : %s", zmq_strerror(errno)); zmq_close(worker); @@ -482,7 +493,8 @@ static void* __worker_loop(void *args) zmq_close(worker); return NULL; } - if (zmq_setsockopt(manager, ZMQ_IDENTITY, &worker_id, sizeof(int)) != 0) + if (zmq_setsockopt(manager, ZMQ_IDENTITY, __get_string_worker_id(worker_id, string_worker_id), + PIMS_IPC_STRING_WORKER_ID_SIZE) != 0) { ERROR("setsockopt error : %s", zmq_strerror(errno)); zmq_close(manager); @@ -524,6 +536,9 @@ static void* __worker_loop(void *args) if (zmq_poll(items, 2, -1) == -1) { + if (errno == EINTR) + continue; + ERROR("poll error : %s", zmq_strerror(errno)); break; } @@ -618,8 +633,10 @@ static void __terminate_worker(void *manager, int worker_id, const char *pid) { // send worker id zmq_msg_t worker_id_msg; - zmq_msg_init_size(&worker_id_msg, sizeof(int)); - memcpy(zmq_msg_data(&worker_id_msg), &worker_id, sizeof(int)); + zmq_msg_init_size(&worker_id_msg, PIMS_IPC_STRING_WORKER_ID_SIZE); + char string_worker_id[PIMS_IPC_STRING_WORKER_ID_SIZE + 1] = ""; + memcpy(zmq_msg_data(&worker_id_msg), __get_string_worker_id(worker_id, string_worker_id), + PIMS_IPC_STRING_WORKER_ID_SIZE); if (_pims_zmq_msg_send(&worker_id_msg, manager, ZMQ_SNDMORE) == -1) { ERROR("send error : %s", zmq_strerror(errno)); @@ -819,8 +836,10 @@ static int __process_router_event(void *context, void *router, void *worker, gbo VERBOSE("routing worker id = %x", worker_id); // send worker id zmq_msg_t worker_id_msg; - zmq_msg_init_size(&worker_id_msg, sizeof(int)); - memcpy(zmq_msg_data(&worker_id_msg), &worker_id, sizeof(int)); + zmq_msg_init_size(&worker_id_msg, PIMS_IPC_STRING_WORKER_ID_SIZE); + char string_worker_id[PIMS_IPC_STRING_WORKER_ID_SIZE + 1] = ""; + memcpy(zmq_msg_data(&worker_id_msg), __get_string_worker_id(worker_id, string_worker_id), + PIMS_IPC_STRING_WORKER_ID_SIZE); if (_pims_zmq_msg_send(&worker_id_msg, worker, ZMQ_SNDMORE) == -1) { ERROR("send error : %s", zmq_strerror(errno)); diff --git a/src/pims-ipc.c b/src/pims-ipc.c index 5f9be24..301a52f 100644 --- a/src/pims-ipc.c +++ b/src/pims-ipc.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. @@ -83,6 +83,58 @@ typedef struct GHashTable *subscribe_cb_table; } pims_ipc_t; +#define PIMS_IPC_SOCKET_BUFFER_SIZE 256 +static inline int __pims_zmq_msg_recv_by_handle(zmq_msg_t *msg, pims_ipc_t *handle, int flags) +{ + int ret = -1; + + while (1) + { + zmq_pollitem_t items[] = { + {handle->requester, 0, ZMQ_POLLIN, 0}, + {NULL, handle->fd, ZMQ_POLLIN, 0} + }; + + if (zmq_poll(items, 2, -1) == -1) + { + if (errno == EINTR) + continue; + + ERROR("poll error : %s", zmq_strerror(errno)); + break; + } + + if (items[0].revents & ZMQ_POLLIN) + { + ret = zmq_msg_recv(msg, handle->requester, flags); + if (ret == -1 && errno == EINTR) + continue; + break; + } + + if (items[1].revents & ZMQ_POLLIN) + { + char buffer[PIMS_IPC_SOCKET_BUFFER_SIZE] = ""; + + memset(buffer, 0x00, PIMS_IPC_SOCKET_BUFFER_SIZE); + ret = read(handle->fd, (char *)buffer, PIMS_IPC_SOCKET_BUFFER_SIZE-1); + ASSERT(ret <= 0); + + close(handle->fd); + handle->fd = -1; + + if (handle->requester) + zmq_close(handle->requester); + handle->requester = NULL; + + errno = ETERM; + ret = -1; + break; + } + } + + return ret; +} static void __pims_ipc_free_handle(pims_ipc_t *handle) { @@ -143,7 +195,7 @@ static int __pims_ipc_receive_for_subscribe(pims_ipc_t *handle) do { // recv call id - if (_pims_zmq_msg_recv(&call_id_msg, handle->requester, 0) == -1) + if (__pims_zmq_msg_recv_by_handle(&call_id_msg, handle, 0) == -1) { ERROR("recv error : %s", zmq_strerror(errno)); break; @@ -156,7 +208,7 @@ static int __pims_ipc_receive_for_subscribe(pims_ipc_t *handle) zmq_getsockopt(handle->requester, ZMQ_RCVMORE, &more, &more_size); if (more) { - if (_pims_zmq_msg_recv(&data_msg, handle->requester, 0) == -1) + if (__pims_zmq_msg_recv_by_handle(&data_msg, handle, 0) == -1) { ERROR("recv error : %s", zmq_strerror(errno)); break; @@ -531,7 +583,7 @@ static int __pims_ipc_receive(pims_ipc_t *handle, pims_ipc_data_h *data_out) do { // recv sequence no - if (_pims_zmq_msg_recv(&sequence_no_msg, handle->requester, 0) == -1) + if (__pims_zmq_msg_recv_by_handle(&sequence_no_msg, handle, 0) == -1) { ERROR("recv error : %s", zmq_strerror(errno)); break; @@ -539,7 +591,7 @@ static int __pims_ipc_receive(pims_ipc_t *handle, pims_ipc_data_h *data_out) memcpy(&sequence_no, zmq_msg_data(&sequence_no_msg), sizeof(unsigned int)); // recv call id - if (_pims_zmq_msg_recv(&call_id_msg, handle->requester, 0) == -1) + if (__pims_zmq_msg_recv_by_handle(&call_id_msg, handle, 0) == -1) { ERROR("recv error : %s", zmq_strerror(errno)); break; @@ -549,7 +601,7 @@ static int __pims_ipc_receive(pims_ipc_t *handle, pims_ipc_data_h *data_out) zmq_getsockopt(handle->requester, ZMQ_RCVMORE, &more, &more_size); if (more) { - if (_pims_zmq_msg_recv(&data_out_msg, handle->requester, 0) == -1) + if (__pims_zmq_msg_recv_by_handle(&data_out_msg, handle, 0) == -1) { ERROR("recv error : %s", zmq_strerror(errno)); break; diff --git a/src/pims-socket.c b/src/pims-socket.c index f2ee131..bf02682 100644 --- a/src/pims-socket.c +++ b/src/pims-socket.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/src/pims-socket.h b/src/pims-socket.h index 5cf2696..790e3d0 100644 --- a/src/pims-socket.h +++ b/src/pims-socket.h @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd All Rights Reserved + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the License); * you may not use this file except in compliance with the License. diff --git a/test/sock-test.c b/test/sock-test.c index b086864..a18e6f2 100644 --- a/test/sock-test.c +++ b/test/sock-test.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/test/test.c b/test/test.c index 6335a38..74e0b8a 100644 --- a/test/test.c +++ b/test/test.c @@ -1,7 +1,7 @@ /* * PIMS IPC * - * Copyright (c) 2012 Samsung Electronics Co., Ltd. All rights reserved. + * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. -- 2.7.4