int messageId = 0;
int fd = -1;
+ int ret = 0;
char* pData = null;
int remain = 0;
std::string message;
IPC::Message* pReply = null;
- MessageReplyDeserializer* pReplyDeserializer = null;
IPC::SyncMessage* pSyncMessage = dynamic_cast <IPC::SyncMessage*>(pMessage);
SysTryReturnResult(NID_IO, pSyncMessage != null, E_INVALID_ARG, "pMessage is not a sync message.");
+ MessageReplyDeserializer* pReplyDeserializer = pSyncMessage->GetReplyDeserializer();
messageId = SyncMessage::GetMessageId(*pSyncMessage);
fd = AcquireFd();
- SysTryReturnResult(NID_IO, fd != -1, E_SYSTEM, "Failed to get fd.");
+ if (fd < 0)
+ {
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to get an fd");
+
+ delete pReplyDeserializer;
+ return E_SYSTEM;
+ }
pData = (char*) pSyncMessage->data();
remain = pSyncMessage->size();
written = write(fd, (char*) pData, remain);
if (written < 0)
{
- ReleaseFd(fd);
+ SysTryCatch(NID_IO, errno != EAGAIN, r = E_RESOURCE_UNAVAILABLE, E_RESOURCE_UNAVAILABLE, "[E_RESOURCE_UNAVAILABLE] The socket buffer is full.");
- if (errno == EAGAIN)
- {
- SysLogException(NID_IO, E_RESOURCE_UNAVAILABLE, "[E_RESOURCE_UNAVAILABLE] The socket buffer is full.");
- return E_RESOURCE_UNAVAILABLE;
- }
- else if (errno == EPIPE)
- {
- SysLogException(NID_IO, E_INVALID_CONNECTION, "[E_INVALID_CONNECTION] The socket connection is closed.");
- return E_INVALID_CONNECTION;
- }
+ SysTryCatch(NID_IO, errno != EPIPE, r = E_INVALID_CONNECTION, E_INVALID_CONNECTION, "[E_INVALID_CONNECTION] The socket connection is closed.");
SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to send a request: %d, %s", errno, strerror(errno));
- return E_SYSTEM;
+
+ r = E_SYSTEM;
+ goto CATCH;
}
remain -= written;
pfd.events = POLLIN | POLLRDHUP;
pfd.revents = 0;
- int ret = 0;
-
while (true)
{
ret = poll(&pfd, 1, -1);
SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to poll (%d, %s).", errno, strerror(errno));
- ReleaseFd(fd);
- return E_SYSTEM;
+ r = E_SYSTEM;
+ goto CATCH;
}
if (pfd.revents & POLLRDHUP)
{
SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] POLLRDHUP");
- ReleaseFd(fd);
- return E_SYSTEM;
+ r = E_SYSTEM;
+ goto CATCH;
}
if (pfd.revents & POLLIN)
if (pEndOfMessage)
{
pReply = new (std::nothrow) IPC::Message(message.data(), pEndOfMessage - message.data());
- if (pReply == null)
- {
- SysLogException(NID_IO, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
-
- ReleaseFd(fd);
- return E_OUT_OF_MEMORY;
- }
+ SysTryCatch(NID_IO, pReply != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] The memory is insufficient.");
break;
}
}
- pReplyDeserializer = pSyncMessage->GetReplyDeserializer();
pReplyDeserializer->SerializeOutputParameters(*pReply);
-
delete pReply;
+
+CATCH:
delete pReplyDeserializer;
ReleaseFd(fd);