Change-Id: I539d3602c0081b6b34cfc6a49a59d6e3bcaacd1b
Signed-off-by: yanghao <yanghao236@huawei.com>
This commit is contained in:
yanghao 2024-07-02 10:55:44 +08:00
parent 6068bcbabb
commit f989306062
3 changed files with 10 additions and 1 deletions

View File

@ -101,6 +101,7 @@ typedef void (*LE_ConnectComplete)(const TaskHandle client);
typedef void (*LE_SendMessageComplete)(const TaskHandle taskHandle, BufferHandle handle);
typedef void (*LE_RecvMessage)(const TaskHandle taskHandle, const uint8_t *buffer, uint32_t buffLen);
typedef int (*LE_IncommingConnect)(const LoopHandle loopHandle, const TaskHandle serverTask);
typedef int (*LE_HandleRecvMsg)(const TaskHandle taskHandle, uint8_t* buffer, int bufferSize, int flags);
typedef struct {
LE_BaseInfo baseInfo;
char *server;
@ -118,6 +119,7 @@ typedef struct {
LE_ConnectComplete connectComplete;
LE_SendMessageComplete sendMessageComplete;
LE_RecvMessage recvMessage;
LE_HandleRecvMsg handleRecvMsg;
} LE_StreamInfo;
LE_STATUS LE_CreateStreamServer(const LoopHandle loopHandle,

View File

@ -55,9 +55,14 @@ static LE_STATUS HandleRecvMsg_(const LoopHandle loopHandle,
{
LE_STATUS status = LE_SUCCESS;
LE_Buffer *buffer = CreateBuffer(LOOP_DEFAULT_BUFFER);
StreamConnectTask *stream = (StreamConnectTask *)taskHandle;
int readLen = 0;
while (1) {
readLen = recv(GetSocketFd(taskHandle), buffer->data, LOOP_DEFAULT_BUFFER, 0);
if (stream->handleRecvMsg != NULL) {
readLen = stream->handleRecvMsg(taskHandle, buffer->data, LOOP_DEFAULT_BUFFER, 0);
} else {
readLen = recv(GetSocketFd(taskHandle), buffer->data, LOOP_DEFAULT_BUFFER, 0);
}
LE_LOGV("HandleRecvMsg fd:%d read msg len %d", GetSocketFd(taskHandle), readLen);
if (readLen < 0) {
if (errno == EINTR || errno == EWOULDBLOCK || errno == EAGAIN) {
@ -278,6 +283,7 @@ LE_STATUS LE_AcceptStreamClient(const LoopHandle loopHandle, const TaskHandle se
task->sendMessageComplete = info->sendMessageComplete;
task->recvMessage = info->recvMessage;
task->serverTask = (StreamServerTask *)server;
task->handleRecvMsg = info->handleRecvMsg;
OH_ListInit(&task->stream.buffHead);
LoopMutexInit(&task->stream.mutex);
if ((info->baseInfo.flags & TASK_TEST) != TASK_TEST) {

View File

@ -97,6 +97,7 @@ typedef struct {
LE_SendMessageComplete sendMessageComplete;
LE_RecvMessage recvMessage;
LE_DisConnectComplete disConnectComplete;
LE_HandleRecvMsg handleRecvMsg;
} StreamConnectTask;
typedef struct {