mirror of
https://gitee.com/openharmony/startup_init
synced 2024-11-27 18:30:52 +00:00
修改appssawn socket创建流程
Signed-off-by: zhongning5 <zhongning5@huawei.com> Change-Id: I093ffde2662f067c6487c8be6af136e45328d98f
This commit is contained in:
parent
749ff1b9f4
commit
3e65dd03dd
@ -196,3 +196,26 @@ int AcceptSocket(int fd, int flags)
|
||||
SetNoBlock(clientFd);
|
||||
return clientFd;
|
||||
}
|
||||
|
||||
INIT_LOCAL_API
|
||||
int listenSocket(int fd, int flags, const char *server)
|
||||
{
|
||||
int type = flags & 0x0000ff00;
|
||||
LE_LOGV("listenSocket flags %x type %x server %s", flags, type, server);
|
||||
SetNoBlock(fd);
|
||||
if (!LE_TEST_FLAGS(flags, TASK_SERVER)) {
|
||||
return 0;
|
||||
}
|
||||
if (type == TASK_TCP) {
|
||||
int ret = listen(fd, LOOP_MAX_CLIENT);
|
||||
LE_CHECK(ret >= 0, close(fd);
|
||||
return ret, "Failed to listen socket");
|
||||
} else if (type == TASK_PIPE) {
|
||||
int ret = listen(fd, LOOP_MAX_CLIENT);
|
||||
LE_CHECK(ret >= 0, close(fd);
|
||||
return ret, "Failed to listen socket error: %d", errno);
|
||||
ret = chmod(server, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
LE_CHECK(ret == 0, return -1, "Failed to chmod %s, err %d. ", server, errno);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -28,6 +28,8 @@ INIT_LOCAL_API
|
||||
int CreateSocket(int flags, const char *server);
|
||||
INIT_LOCAL_API
|
||||
int AcceptSocket(int fd, int flags);
|
||||
INIT_LOCAL_API
|
||||
int listenSocket(int fd, int flags, const char *server);
|
||||
|
||||
#ifdef __cplusplus
|
||||
#if __cplusplus
|
||||
|
@ -163,9 +163,13 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle,
|
||||
"Invalid parameters incommingConnect %s", info->server);
|
||||
|
||||
int fd = info->socketId;
|
||||
int ret = 0;
|
||||
if (info->socketId <= 0) {
|
||||
fd = CreateSocket(info->baseInfo.flags, info->server);
|
||||
LE_CHECK(fd > 0, return LE_FAILURE, "Failed to create socket %s", info->server);
|
||||
} else {
|
||||
ret = listenSocket(fd, info->baseInfo.flags, info->server);
|
||||
LE_CHECK(ret == 0, return LE_FAILURE, "Failed to listen socket %s", info->server);
|
||||
}
|
||||
|
||||
EventLoop *loop = (EventLoop *)loopHandle;
|
||||
@ -177,7 +181,7 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle,
|
||||
task->base.innerClose = HandleStreamTaskClose_;
|
||||
task->incommingConnect = info->incommingConnect;
|
||||
loop->addEvent(loop, (const BaseTask *)task, Event_Read);
|
||||
int ret = memcpy_s(task->server, strlen(info->server) + 1, info->server, strlen(info->server) + 1);
|
||||
ret = memcpy_s(task->server, strlen(info->server) + 1, info->server, strlen(info->server) + 1);
|
||||
LE_CHECK(ret == 0, return LE_FAILURE, "Failed to copy server name %s", info->server);
|
||||
*taskHandle = (TaskHandle)task;
|
||||
return LE_SUCCESS;
|
||||
|
Loading…
Reference in New Issue
Block a user