提交 4346feb7 编写于 作者: L laiguizhong

修改conntect为connect

Signed-off-by: Nlaiguizhong <laiguizhong@huawei.com>
上级 7815064b
...@@ -93,7 +93,7 @@ static int SendMessage(LoopHandle loop, TaskHandle task, const char *message) ...@@ -93,7 +93,7 @@ static int SendMessage(LoopHandle loop, TaskHandle task, const char *message)
return 0; return 0;
} }
static int CmdOnIncommingConntect(const LoopHandle loop, const TaskHandle server) static int CmdOnIncommingConnect(const LoopHandle loop, const TaskHandle server)
{ {
TaskHandle client = NULL; TaskHandle client = NULL;
LE_StreamInfo info = {}; LE_StreamInfo info = {};
...@@ -128,7 +128,7 @@ void CmdServiceInit(const char *socketPath, CallbackControlFdProcess func) ...@@ -128,7 +128,7 @@ void CmdServiceInit(const char *socketPath, CallbackControlFdProcess func)
info.socketId = -1; info.socketId = -1;
info.baseInfo.close = NULL; info.baseInfo.close = NULL;
info.disConnectComplete = NULL; info.disConnectComplete = NULL;
info.incommingConntect = CmdOnIncommingConntect; info.incommingConnect = CmdOnIncommingConnect;
info.sendMessageComplete = NULL; info.sendMessageComplete = NULL;
info.recvMessage = NULL; info.recvMessage = NULL;
g_controlFdFunc = func; g_controlFdFunc = func;
......
...@@ -93,17 +93,17 @@ typedef struct { ...@@ -93,17 +93,17 @@ typedef struct {
#define TASK_SERVER (0x01 << 16) #define TASK_SERVER (0x01 << 16)
#define TASK_CONNECT (0x02 << 16) #define TASK_CONNECT (0x02 << 16)
#define TASK_TEST (0x01 << 24) #define TASK_TEST (0x01 << 24)
typedef void (*LE_DisConntectComplete)(const TaskHandle client); typedef void (*LE_DisConnectComplete)(const TaskHandle client);
typedef void (*LE_ConntectComplete)(const TaskHandle client); typedef void (*LE_ConnectComplete)(const TaskHandle client);
typedef void (*LE_SendMessageComplete)(const TaskHandle taskHandle, BufferHandle handle); typedef void (*LE_SendMessageComplete)(const TaskHandle taskHandle, BufferHandle handle);
typedef void (*LE_RecvMessage)(const TaskHandle taskHandle, const uint8_t *buffer, uint32_t buffLen); typedef void (*LE_RecvMessage)(const TaskHandle taskHandle, const uint8_t *buffer, uint32_t buffLen);
typedef int (*LE_IncommingConntect)(const LoopHandle loopHandle, const TaskHandle serverTask); typedef int (*LE_IncommingConnect)(const LoopHandle loopHandle, const TaskHandle serverTask);
typedef struct { typedef struct {
LE_BaseInfo baseInfo; LE_BaseInfo baseInfo;
char *server; char *server;
int socketId; int socketId;
LE_DisConntectComplete disConnectComplete; LE_DisConnectComplete disConnectComplete;
LE_IncommingConntect incommingConntect; LE_IncommingConnect incommingConnect;
LE_SendMessageComplete sendMessageComplete; LE_SendMessageComplete sendMessageComplete;
LE_RecvMessage recvMessage; LE_RecvMessage recvMessage;
} LE_StreamServerInfo; } LE_StreamServerInfo;
...@@ -111,8 +111,8 @@ typedef struct { ...@@ -111,8 +111,8 @@ typedef struct {
typedef struct { typedef struct {
LE_BaseInfo baseInfo; LE_BaseInfo baseInfo;
char *server; char *server;
LE_DisConntectComplete disConnectComplete; LE_DisConnectComplete disConnectComplete;
LE_ConntectComplete connectComplete; LE_ConnectComplete connectComplete;
LE_SendMessageComplete sendMessageComplete; LE_SendMessageComplete sendMessageComplete;
LE_RecvMessage recvMessage; LE_RecvMessage recvMessage;
} LE_StreamInfo; } LE_StreamInfo;
......
...@@ -141,9 +141,9 @@ static LE_STATUS HandleServerEvent_(const LoopHandle loopHandle, const TaskHandl ...@@ -141,9 +141,9 @@ static LE_STATUS HandleServerEvent_(const LoopHandle loopHandle, const TaskHandl
return LE_FAILURE; return LE_FAILURE;
} }
StreamServerTask *server = (StreamServerTask *)serverTask; StreamServerTask *server = (StreamServerTask *)serverTask;
LE_ONLY_CHECK(server->incommingConntect != NULL, return LE_SUCCESS); LE_ONLY_CHECK(server->incommingConnect != NULL, return LE_SUCCESS);
int ret = server->incommingConntect(loopHandle, serverTask); int ret = server->incommingConnect(loopHandle, serverTask);
if (ret != LE_SUCCESS) { if (ret != LE_SUCCESS) {
LE_LOGE("HandleServerEvent_ fd %d do not accept socket", GetSocketFd(serverTask)); LE_LOGE("HandleServerEvent_ fd %d do not accept socket", GetSocketFd(serverTask));
} }
...@@ -157,8 +157,8 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle, ...@@ -157,8 +157,8 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle,
{ {
LE_CHECK(loopHandle != NULL && taskHandle != NULL && info != NULL, return LE_INVALID_PARAM, "Invalid parameters"); LE_CHECK(loopHandle != NULL && taskHandle != NULL && info != NULL, return LE_INVALID_PARAM, "Invalid parameters");
LE_CHECK(info->server != NULL, return LE_INVALID_PARAM, "Invalid parameters server"); LE_CHECK(info->server != NULL, return LE_INVALID_PARAM, "Invalid parameters server");
LE_CHECK(info->incommingConntect != NULL, return LE_INVALID_PARAM, LE_CHECK(info->incommingConnect != NULL, return LE_INVALID_PARAM,
"Invalid parameters incommingConntect %s", info->server); "Invalid parameters incommingConnect %s", info->server);
int fd = info->socketId; int fd = info->socketId;
if (info->socketId <= 0) { if (info->socketId <= 0) {
...@@ -173,7 +173,7 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle, ...@@ -173,7 +173,7 @@ LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle,
return LE_NO_MEMORY, "Failed to create task"); return LE_NO_MEMORY, "Failed to create task");
task->base.handleEvent = HandleServerEvent_; task->base.handleEvent = HandleServerEvent_;
task->base.innerClose = HandleStreamTaskClose_; task->base.innerClose = HandleStreamTaskClose_;
task->incommingConntect = info->incommingConntect; task->incommingConnect = info->incommingConnect;
loop->addEvent(loop, (const BaseTask *)task, Event_Read); loop->addEvent(loop, (const BaseTask *)task, Event_Read);
int ret = memcpy_s(task->server, strlen(info->server) + 1, info->server, strlen(info->server) + 1); int 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); LE_CHECK(ret == 0, return LE_FAILURE, "Failed to copy server name %s", info->server);
......
...@@ -72,7 +72,7 @@ typedef struct LiteTask_ { ...@@ -72,7 +72,7 @@ typedef struct LiteTask_ {
typedef struct { typedef struct {
BaseTask base; BaseTask base;
LE_IncommingConntect incommingConntect; LE_IncommingConnect incommingConnect;
char server[0]; char server[0];
} StreamServerTask; } StreamServerTask;
...@@ -91,13 +91,13 @@ typedef struct { ...@@ -91,13 +91,13 @@ typedef struct {
StreamServerTask *serverTask; StreamServerTask *serverTask;
LE_SendMessageComplete sendMessageComplete; LE_SendMessageComplete sendMessageComplete;
LE_RecvMessage recvMessage; LE_RecvMessage recvMessage;
LE_DisConntectComplete disConnectComplete; LE_DisConnectComplete disConnectComplete;
} StreamConnectTask; } StreamConnectTask;
typedef struct { typedef struct {
StreamTask stream; StreamTask stream;
LE_DisConntectComplete disConnectComplete; LE_DisConnectComplete disConnectComplete;
LE_ConntectComplete connectComplete; LE_ConnectComplete connectComplete;
LE_SendMessageComplete sendMessageComplete; LE_SendMessageComplete sendMessageComplete;
LE_RecvMessage recvMessage; LE_RecvMessage recvMessage;
uint32_t connected : 1; uint32_t connected : 1;
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
#include "param_utils.h" #include "param_utils.h"
#include "securec.h" #include "securec.h"
int ConntectServer(int fd, const char *servername) int ConnectServer(int fd, const char *servername)
{ {
PARAM_CHECK(fd >= 0, return -1, "Invalid fd %d", fd); PARAM_CHECK(fd >= 0, return -1, "Invalid fd %d", fd);
int opt = 1; int opt = 1;
...@@ -36,7 +36,7 @@ int ConntectServer(int fd, const char *servername) ...@@ -36,7 +36,7 @@ int ConntectServer(int fd, const char *servername)
int len = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path); int len = offsetof(struct sockaddr_un, sun_path) + strlen(addr.sun_path);
ret = connect(fd, (struct sockaddr *)&addr, len); ret = connect(fd, (struct sockaddr *)&addr, len);
PARAM_CHECK(ret != -1, return -1, "Failed to connect server %s %d", servername, errno); PARAM_CHECK(ret != -1, return -1, "Failed to connect server %s %d", servername, errno);
PARAM_LOGV("ConntectServer %s success", servername); PARAM_LOGV("ConnectServer %s success", servername);
return 0; return 0;
} }
......
...@@ -75,7 +75,7 @@ typedef int (*RecvMessage)(const ParamTaskPtr stream, const ParamMessage *msg); ...@@ -75,7 +75,7 @@ typedef int (*RecvMessage)(const ParamTaskPtr stream, const ParamMessage *msg);
typedef struct { typedef struct {
uint32_t flags; uint32_t flags;
char *server; char *server;
LE_IncommingConntect incomingConnect; LE_IncommingConnect incomingConnect;
RecvMessage recvMessage; RecvMessage recvMessage;
LE_Close close; LE_Close close;
} ParamStreamInfo; } ParamStreamInfo;
...@@ -97,7 +97,7 @@ int FillParamMsgContent(const ParamMessage *request, uint32_t *start, int type, ...@@ -97,7 +97,7 @@ int FillParamMsgContent(const ParamMessage *request, uint32_t *start, int type,
ParamMsgContent *GetNextContent(const ParamMessage *reqest, uint32_t *offset); ParamMsgContent *GetNextContent(const ParamMessage *reqest, uint32_t *offset);
ParamMessage *CreateParamMessage(int type, const char *name, uint32_t msgSize); ParamMessage *CreateParamMessage(int type, const char *name, uint32_t msgSize);
int ConntectServer(int fd, const char *servername); int ConnectServer(int fd, const char *servername);
#ifdef STARTUP_INIT_TEST #ifdef STARTUP_INIT_TEST
int ProcessMessage(const ParamTaskPtr worker, const ParamMessage *msg); int ProcessMessage(const ParamTaskPtr worker, const ParamMessage *msg);
......
...@@ -52,7 +52,7 @@ int ParamServerCreate(ParamTaskPtr *stream, const ParamStreamInfo *streamInfo) ...@@ -52,7 +52,7 @@ int ParamServerCreate(ParamTaskPtr *stream, const ParamStreamInfo *streamInfo)
info.baseInfo.flags = TASK_STREAM | TASK_PIPE | TASK_SERVER; info.baseInfo.flags = TASK_STREAM | TASK_PIPE | TASK_SERVER;
info.server = streamInfo->server; info.server = streamInfo->server;
info.baseInfo.close = streamInfo->close; info.baseInfo.close = streamInfo->close;
info.incommingConntect = streamInfo->incomingConnect; info.incommingConnect = streamInfo->incomingConnect;
return LE_CreateStreamServer(LE_GetDefaultLoop(), stream, &info); return LE_CreateStreamServer(LE_GetDefaultLoop(), stream, &info);
} }
......
...@@ -112,7 +112,7 @@ static int GetClientSocket(int timeout) ...@@ -112,7 +112,7 @@ static int GetClientSocket(int timeout)
time.tv_usec = 0; time.tv_usec = 0;
int clientFd = socket(AF_UNIX, SOCK_STREAM, 0); int clientFd = socket(AF_UNIX, SOCK_STREAM, 0);
PARAM_CHECK(clientFd >= 0, return -1, "Failed to create socket"); PARAM_CHECK(clientFd >= 0, return -1, "Failed to create socket");
int ret = ConntectServer(clientFd, CLIENT_PIPE_NAME); int ret = ConnectServer(clientFd, CLIENT_PIPE_NAME);
if (ret == 0) { if (ret == 0) {
setsockopt(clientFd, SOL_SOCKET, SO_SNDTIMEO, (char *)&time, sizeof(struct timeval)); setsockopt(clientFd, SOL_SOCKET, SO_SNDTIMEO, (char *)&time, sizeof(struct timeval));
setsockopt(clientFd, SOL_SOCKET, SO_RCVTIMEO, (char *)&time, sizeof(struct timeval)); setsockopt(clientFd, SOL_SOCKET, SO_RCVTIMEO, (char *)&time, sizeof(struct timeval));
......
...@@ -296,7 +296,7 @@ int WatcherManager::GetServerFd(bool retry) ...@@ -296,7 +296,7 @@ int WatcherManager::GetServerFd(bool retry)
serverFd_ = socket(PF_UNIX, SOCK_STREAM, 0); serverFd_ = socket(PF_UNIX, SOCK_STREAM, 0);
int flags = fcntl(serverFd_, F_GETFL, 0); int flags = fcntl(serverFd_, F_GETFL, 0);
(void)fcntl(serverFd_, F_SETFL, flags & ~O_NONBLOCK); (void)fcntl(serverFd_, F_SETFL, flags & ~O_NONBLOCK);
ret = ConntectServer(serverFd_, CLIENT_PIPE_NAME); ret = ConnectServer(serverFd_, CLIENT_PIPE_NAME);
if (ret == 0) { if (ret == 0) {
break; break;
} }
......
...@@ -163,7 +163,7 @@ public: ...@@ -163,7 +163,7 @@ public:
info.baseInfo.flags = TASK_STREAM | TASK_PIPE | TASK_SERVER | TASK_TEST; info.baseInfo.flags = TASK_STREAM | TASK_PIPE | TASK_SERVER | TASK_TEST;
info.server = (char *)"/data/testpipe"; info.server = (char *)"/data/testpipe";
info.baseInfo.close = OnClose; info.baseInfo.close = OnClose;
info.incommingConntect = IncomingConnect; info.incommingConnect = IncomingConnect;
LE_CreateStreamServer(LE_GetDefaultLoop(), &serverTask_, &info); LE_CreateStreamServer(LE_GetDefaultLoop(), &serverTask_, &info);
if (serverTask_ == nullptr) { if (serverTask_ == nullptr) {
return; return;
...@@ -246,7 +246,7 @@ public: ...@@ -246,7 +246,7 @@ public:
info.baseInfo.flags = TASK_PIPE | TASK_CONNECT | TASK_TEST; info.baseInfo.flags = TASK_PIPE | TASK_CONNECT | TASK_TEST;
info.server = (char *)"/data/testpipe"; info.server = (char *)"/data/testpipe";
info.baseInfo.close = OnClose; info.baseInfo.close = OnClose;
info.incommingConntect = IncomingConnect; info.incommingConnect = IncomingConnect;
info.socketId = 1111; // 1111 is test fd info.socketId = 1111; // 1111 is test fd
LE_CreateStreamServer(LE_GetDefaultLoop(), &serverTask, &info); LE_CreateStreamServer(LE_GetDefaultLoop(), &serverTask, &info);
EXPECT_NE(serverTask, nullptr); EXPECT_NE(serverTask, nullptr);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册