socklen_t serverLen = 0;
int client = -1;
int ret = 0;
+ int retry = 0;
HelloMessage helloMessage = {0, 0};
std::string socketName;
char* pSocketName = null;
serverLen = sizeof(server);
// Retry if the server is not ready
- int retry = 5;
+ retry = 5;
while (retry > 0)
{
ret = connect(client, (struct sockaddr*) &server, serverLen);
while (remain > 0)
{
written = write(fd, (char*) pData, remain);
+ if (written < 0)
+ {
+ ReleaseFd(fd);
+
+ 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;
+ }
+
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to send a request: %d, %s", errno, strerror(errno));
+ return E_SYSTEM;
+ }
+
remain -= written;
pData += written;
}
written = write(fd, (char*) pData, remain);
if (written < 0)
{
- SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to send a request: %d, %s", errno, strerror(errno));
-
ReleaseFd(fd);
+
+ 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;
+ }
+
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to send a request: %d, %s", errno, strerror(errno));
return E_SYSTEM;
}
}
SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to poll (%d, %s).", errno, strerror(errno));
+
+ ReleaseFd(fd);
return E_SYSTEM;
}
if (pEndOfMessage)
{
pReply = new (std::nothrow) IPC::Message(message.data(), pEndOfMessage - message.data());
- SysTryReturnResult(NID_IO, pReply != null, E_OUT_OF_MEMORY, "The memory is insufficient.");
+ 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;
+ }
+
break;
}
}