#include <queue>
#include <map>
+#include "message-port.h"
#include "message-port-log.h"
#include "IpcClient.h"
pthread_mutex_t* pMutex = (pthread_mutex_t*) malloc(sizeof(pthread_mutex_t));
if (pMutex == NULL)
{
- return -2;
+ return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
}
pthread_mutex_init(pMutex, NULL);
}
}
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
if (client < 0)
{
_LOGE("Failed to create a socket : %s.", strerror(errno));
- return -1;
+ return MESSAGEPORT_ERROR_IO_ERROR;
}
int flags = fcntl(client, F_GETFL, 0);
ReleaseFd(client);
}
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
CATCH:
if (client != -1)
close(client);
}
- return -1;
+ return MESSAGEPORT_ERROR_IO_ERROR;
}
if (pMessage == NULL)
{
_LOGE("The memory is insufficient");
- return -2;
+ return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
}
if (__pListener)
if (ret < 0)
{
_LOGE("Failed to connect to the server.");
- return -1;
+ return MESSAGEPORT_ERROR_IO_ERROR;
}
continue;
if (fd == -1)
{
_LOGE("Failed to get fd.");
- return -1;
+ return MESSAGEPORT_ERROR_IO_ERROR;
}
int written = 0;
ReleaseFd(fd);
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
int
if (pSyncMessage == NULL)
{
_LOGE("pMessage is not a sync message.");
- return -1;
+ return MESSAGEPORT_ERROR_IO_ERROR;
}
int messageId = SyncMessage::GetMessageId(*pSyncMessage);
if (fd < 0)
{
_LOGE("Failed to get fd.");
- return -1;
+ return MESSAGEPORT_ERROR_IO_ERROR;
}
char* pData = (char*) pSyncMessage->data();
int readSize = 0;
char* pEndOfMessage = NULL;
+ int ret = 0;
+
while (true)
{
- poll(&pfd, 1, -1);
+ ret = poll(&pfd, 1, -1);
+ if (ret < 0)
+ {
+ if (errno == EINTR)
+ {
+ continue;
+ }
+
+ _LOGE("Failed to poll (%d, %s).", errno, strerror(errno));
+ return MESSAGEPORT_ERROR_IO_ERROR;
+ }
if (pfd.revents & POLLRDHUP)
{
- return -1;
+ _LOGE("POLLRDHUP");
+ return MESSAGEPORT_ERROR_IO_ERROR;
}
if (pfd.revents & POLLIN)
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)
if (pReply == NULL)
{
_LOGE("The memory is insufficient.");
- return -2;
+ return MESSAGEPORT_ERROR_OUT_OF_MEMORY;
}
break;
ReleaseFd(fd);
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
int
free(pAppId);
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
void
_LOGE("The remote message port (%s) is not found.", remotePort.c_str());
*exist = false;
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
else if (return_value == MESSAGEPORT_ERROR_CERTIFICATE_NOT_MATCH)
{
}
*exist = true;
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
int
}
}
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
char*
else
{
*trusted = true;
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
}
else
{
*trusted = false;
- return 0;
+ return MESSAGEPORT_ERROR_NONE;
}
return MESSAGEPORT_ERROR_INVALID_PARAMETER;