//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
{
int pid;
bool reverse;
- char pkgId[256];
- char appExecutableName[256];
+ char appId[256];
};
result
socklen_t serverLen = 0;
int client = -1;
int ret = 0;
+ int retry = 0;
HelloMessage helloMessage = {0, 0};
std::string socketName;
char* pSocketName = null;
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
+ 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));
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;
}
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;
+ int ret = 0;
+
while (true)
{
- poll(&pfd, 1, -1);
+ ret = poll(&pfd, 1, -1);
+ if (ret < 0)
+ {
+ if (errno == EINTR)
+ {
+ continue;
+ }
+
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] Failed to poll (%d, %s).", errno, strerror(errno));
+ return E_SYSTEM;
+ }
if (pfd.revents & POLLRDHUP)
{
+ SysLogException(NID_IO, E_SYSTEM, "[E_SYSTEM] POLLRDHUP");
+
ReleaseFd(fd);
return E_SYSTEM;
}
readSize = read(fd, buffer, 1024);
}
- message.append(buffer, readSize);
+ if (readSize > 0)
+ {
+ message.append(buffer, readSize);
+ }
pEndOfMessage = (char*) IPC::Message::FindNext(message.data(), message.data() + message.size());
if (pEndOfMessage)