X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=src%2FIpcServer.cpp;h=93074cfc7f3f312837012346e0f4374a42956db2;hb=dfae6ea61376a60ba26244f1b5ea925fd5b584f6;hp=e6231250f7e8e9ce57278c4e116cb5211ed47518;hpb=42055e1b3b432d3e963a9561383244b11ccca357;p=platform%2Fframework%2Fnative%2Fchannel-service.git diff --git a/src/IpcServer.cpp b/src/IpcServer.cpp index e623125..93074cf 100644 --- a/src/IpcServer.cpp +++ b/src/IpcServer.cpp @@ -231,7 +231,7 @@ IpcServer::Construct(const String& name, const IIpcServerEventListener& listener SysTryCatch(NID_IO, ret == 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to change permission of a socket(%d, %s): %s", serverSocket, socketName.c_str(), strerror(errno)); - ret = listen(serverSocket, 15); + ret = listen(serverSocket, 128); SysTryCatch(NID_IO, ret == 0, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to listen a socket(%d, %s): %s", serverSocket, socketName.c_str(), strerror(errno)); @@ -290,7 +290,7 @@ CATCH: struct HelloMessage { int pid; - bool reverse; // true if the connection is for reverse message + int reverse; // if the connection is for reverse message }; gboolean @@ -303,6 +303,7 @@ IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoin _ChannelInfo* pChannelInfo = null; GSource* pGSource = null; GIOChannel* pChannel = null; + ssize_t readBytes = 0; int server = -1; int client = -1; @@ -317,7 +318,9 @@ IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoin client = accept(server, (struct sockaddr*) &clientAddress, &clientLen); SysTryCatch(NID_IO, client != -1, , E_SYSTEM, "[E_SYSTEM] Accept failed."); - read(client, &helloMessage, sizeof(helloMessage)); + readBytes = read(client, &helloMessage, sizeof(helloMessage)); + SysTryCatch(NID_IO, readBytes >= 0, , E_SYSTEM, "[E_SYSTEM] Failed to receive hello message (%d, %s).", + errno, strerror(errno)); pChannel = g_io_channel_unix_new(client); SysTryCatch(NID_IO, pChannel != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory."); @@ -339,7 +342,7 @@ IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoin char* pAppId = NULL; int ret = app_manager_get_app_id(helloMessage.pid, &pAppId); - SysTryCatch(NID_IO, ret >= 0, ,E_SYSTEM, "[E_SYSTEM] Failed to get_app_id: %d", ret); + SysTryCatch(NID_IO, ret >= 0, delete pClientInfo, E_SYSTEM, "[E_SYSTEM] Failed to get_app_id: %d", ret); pClientInfo->appId = pAppId; free(pAppId); @@ -352,7 +355,7 @@ IpcServer::OnConnectionRequest(GIOChannel* source, GIOCondition condition, gpoin pIpcServer->__pCurrentClientInfo = null; } - if (helloMessage.reverse) + if (helloMessage.reverse != 0) { pClientInfo->pReverseChannel = pChannel; } @@ -694,6 +697,8 @@ IpcServer::Send(IPC::Message* msg) // empty statement; } + delete msg; + return true; } @@ -706,6 +711,7 @@ IpcServer::SendResponse(int client, IPC::Message* pMessage) char* pData = null; GError* pGError = null; _ClientInfo* pClientInfo = null; + int ret = 0; SysTryReturn(NID_IO, client >= 0 && pMessage != null, false, E_INVALID_ARG, "[E_INVALID_ARG] pMessage(0x%x) is null or clinet(%d) < 0", pMessage, @@ -723,8 +729,12 @@ IpcServer::SendResponse(int client, IPC::Message* pMessage) while (remain > 0) { pGError = NULL; - g_io_channel_write_chars(pClientInfo->pReverseChannel, (char*) pData, remain, &written, &pGError); - SysTryCatch(NID_IO, pGError == null, , E_SYSTEM, "[E_SYSTEM] Error occurred during writing message to socket."); + ret = g_io_channel_write_chars(pClientInfo->pReverseChannel, (char*) pData, remain, &written, &pGError); + if (ret != G_IO_STATUS_NORMAL) + { + SysLog(NID_IO, "Failed to send a response: %d", ret); + SysTryCatch(NID_IO, ret != G_IO_STATUS_ERROR, , E_SYSTEM, "[E_SYSTEM] Error occurred during writing message to socket."); + } remain -= written; pData += written; @@ -750,6 +760,7 @@ IpcServer::SendResponse(int client, const IPC::Message& message) char* pData = null; GError* pGError = null; _ClientInfo* pClientInfo = null; + int ret = 0; SysTryReturn(NID_IO, client >= 0, false, E_INVALID_ARG, "[E_INVALID_ARG] clinet(%d) < 0", client); SysTryCatch(NID_IO, !message.is_sync(), r = E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] Can't send sync. messagee."); @@ -765,8 +776,12 @@ IpcServer::SendResponse(int client, const IPC::Message& message) while (remain > 0) { pGError = NULL; - g_io_channel_write_chars(pClientInfo->pReverseChannel, (char*) pData, remain, &written, &pGError); - SysTryCatch(NID_IO, pGError == null, , E_SYSTEM, "[E_SYSTEM] Error occurred during writing message to socket."); + ret = g_io_channel_write_chars(pClientInfo->pReverseChannel, (char*) pData, remain, &written, &pGError); + if (ret != G_IO_STATUS_NORMAL) + { + SysLog(NID_IO, "Failed to send a response: %d", ret); + SysTryCatch(NID_IO, ret != G_IO_STATUS_ERROR, , E_SYSTEM, "[E_SYSTEM] Error occurred during writing message to socket."); + } remain -= written; pData += written;