{
int pid;
bool reverse;
- char pkgId[256];
- char appExecutableName[256];
+ char appId[256];
};
result
if (__fdCount == 0)
{
- // Set an pkgId
- String pkgId = _AppInfo::GetPackageId();
- int length = (pkgId.GetLength() + 1) * sizeof(wchar_t);
+ // Set an appId
+ String appId = _AppInfo::GetApplicationId();
+ int length = (appId.GetLength() + 1) * sizeof(wchar_t);
if (length > 255)
{
length = 255;
}
- SysTryReturnResult(NID_IO, pkgId.GetLength() > 0, E_SYSTEM, "AppId dose not exist.");
+ SysTryReturnResult(NID_IO, appId.GetLength() > 0, E_SYSTEM, "AppId dose not exist.");
- memcpy(helloMessage.pkgId, pkgId.GetPointer(), length);
-
- // Set an executableName
- String appExecutableName = _AppInfo::GetAppExecutableName();
- length = (appExecutableName.GetLength() + 1) * sizeof(wchar_t);
- if (length > 255)
- {
- length = 255;
- }
-
- if (appExecutableName.GetLength() != 0)
- {
- memcpy(helloMessage.appExecutableName, appExecutableName.GetPointer(), length);
- }
+ memcpy(helloMessage.appId, appId.GetPointer(), length);
}
client = socket(AF_UNIX, SOCK_STREAM, 0);
strncpy(server.sun_path, socketName.c_str(), socketNameLength);
serverLen = sizeof(server);
- ret = connect(client, (struct sockaddr*) &server, serverLen);
- if (ret != 0)
+ // Retry if the server is not ready
+ int retry = 5;
+ while (retry > 0)
+ {
+ ret = connect(client, (struct sockaddr*) &server, serverLen);
+ if (ret < 0 && errno == ENOENT)
+ {
+ SysLog(NID_IO, "The server is not ready. %d", retry);
+
+ usleep(1000 * 1000);
+
+ --retry;
+ }
+ else
+ {
+ break;
+ }
+ }
+
+ if (ret < 0)
{
SysTryCatch(NID_IO, errno == EINPROGRESS, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] Failed to connect to server(%s) : %s",
socketName.c_str(), strerror(errno));
std::string message;
- struct pollfd pfd;
-
IPC::Message* pReply = null;
MessageReplyDeserializer* pReplyDeserializer = null;
IPC::SyncMessage* pSyncMessage = dynamic_cast <IPC::SyncMessage*>(pMessage);
while (remain > 0)
{
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);
+ return E_SYSTEM;
+ }
+
remain -= written;
pData += written;
}
// Wait reply
+ struct pollfd pfd;
+
pfd.fd = fd;
pfd.events = POLLIN | POLLRDHUP;
pfd.revents = 0;
if (pfd.revents & POLLRDHUP)
{
SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] POLLRDHUP");
+
+ ReleaseFd(fd);
return E_SYSTEM;
}
{
int pid;
bool reverse; // true if the connection is for reverse message
- char pkgId[256];
- char appExecutableName[256];
+ char appId[256];
};
gboolean
SysTryCatch(NID_IO, client != -1, , E_SYSTEM, "[E_SYSTEM] Accept failed.");
read(client, &helloMessage, sizeof(helloMessage));
- helloMessage.pkgId[255] = '\0';
- helloMessage.appExecutableName[255] = '\0';
+ helloMessage.appId[255] = '\0';
pChannel = g_io_channel_unix_new(client);
SysTryCatch(NID_IO, pChannel != null, , E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY] Not enough memory.");
pClientInfo->pIpcServer = pIpcServer;
pClientInfo->clientId = helloMessage.pid;
- pClientInfo->pkgId.Append((wchar_t*) helloMessage.pkgId);
- pClientInfo->appExecutableName.Append((wchar_t*) helloMessage.appExecutableName);
+ pClientInfo->appId.Append((wchar_t*) helloMessage.appId);
pClientInfo->pReverseChannel = null;
pIpcServer->__clients[helloMessage.pid] = pClientInfo;
if (__pCurrentClientInfo)
{
- return __pCurrentClientInfo->pkgId;
+ String pkgId;
+ __pCurrentClientInfo->appId.SubString(0, 10, pkgId);
+
+ return pkgId;
}
return nullString;
if (__pCurrentClientInfo)
{
- String appId(__pCurrentClientInfo->pkgId);
- appId.Append(L'.');
- appId.Append(__pCurrentClientInfo->appExecutableName);
-
- return appId;
+ return __pCurrentClientInfo->appId;
}
return nullString;