已合并
fix proxy data recv time #11704
wangJE创建于 3月4日
fix proxy data recv time #11704
已合并
共 1 个文件变更+61-15
| @@ -49,6 +49,12 @@ typedef struct { | |||
| 49 | int32_t state; | 49 | int32_t state; |
| 50 | } ProxyChannelAclStateContext; | 50 | } ProxyChannelAclStateContext; |
| 51 | 51 | ||
| 52 | +typedef struct { | ||
| 53 | + uint32_t channelId; | ||
| 54 | + uint32_t dataLen; | ||
| 55 | + uint8_t *data; | ||
| 56 | +} ProxyChannelDataContext; | ||
| 57 | + | ||
| 52 | enum BrProxyLooperMsgType { | 58 | enum BrProxyLooperMsgType { |
| 53 | MSG_OPEN_PROXY_CHANNEL = 100, | 59 | MSG_OPEN_PROXY_CHANNEL = 100, |
| 54 | MSG_OPEN_PROXY_CHANNEL_TIMEOUT, | 60 | MSG_OPEN_PROXY_CHANNEL_TIMEOUT, |
| @@ -60,6 +66,7 @@ enum BrProxyLooperMsgType { | |||
| 60 | MSG_PROXY_BT_TURN_OFF, | 66 | MSG_PROXY_BT_TURN_OFF, |
| 61 | MSG_PROXY_BT_TURN_ON, | 67 | MSG_PROXY_BT_TURN_ON, |
| 62 | MSG_PROXY_UNPAIRED, | 68 | MSG_PROXY_UNPAIRED, |
| 69 | + MSG_DATA_RECEIVED, | ||
| 63 | }; | 70 | }; |
| 64 | 71 | ||
| 65 | static void ProxyChannelMsgHandler(SoftBusMessage *msg); | 72 | static void ProxyChannelMsgHandler(SoftBusMessage *msg); |
| @@ -192,7 +199,7 @@ static void AttemptPostChannelCloseEvent(struct ProxyChannel *channel, bool isCl | |||
| 192 | } | 199 | } |
| 193 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_CLOSE_PROXY_CHANNEL, | 200 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_CLOSE_PROXY_CHANNEL, |
| 194 | channel->requestId, 0, copyAddr, 0); | 201 | channel->requestId, 0, copyAddr, 0); |
| 195 | - if (ret < 0) { | 202 | + if (ret != SOFTBUS_OK) { |
| 196 | // fall-through | 203 | // fall-through |
| 197 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); | 204 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); |
| 198 | SoftBusFree(copyAddr); | 205 | SoftBusFree(copyAddr); |
| @@ -361,7 +368,7 @@ static void BrChannelConnectSuccess(uint32_t channelId) | |||
| 361 | ctx->channelId = channelId; | 368 | ctx->channelId = channelId; |
| 362 | ctx->isSuccess = true; | 369 | ctx->isSuccess = true; |
| 363 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL_CONNECT_RESULT, 0, 0, ctx, 0); | 370 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL_CONNECT_RESULT, 0, 0, ctx, 0); |
| 364 | - if (ret < 0) { | 371 | + if (ret != SOFTBUS_OK) { |
| 365 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); | 372 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); |
| 366 | SoftBusFree(ctx); | 373 | SoftBusFree(ctx); |
| 367 | } | 374 | } |
| @@ -375,7 +382,7 @@ static void BrChannelConnectFail(uint32_t channelId, int32_t errorCode) | |||
| 375 | ctx->status = errorCode; | 382 | ctx->status = errorCode; |
| 376 | ctx->isSuccess = false; | 383 | ctx->isSuccess = false; |
| 377 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL_CONNECT_RESULT, 0, 0, ctx, 0); | 384 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL_CONNECT_RESULT, 0, 0, ctx, 0); |
| 378 | - if (ret < 0) { | 385 | + if (ret != SOFTBUS_OK) { |
| 379 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); | 386 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); |
| 380 | SoftBusFree(ctx); | 387 | SoftBusFree(ctx); |
| 381 | } | 388 | } |
| @@ -509,7 +516,7 @@ static bool IsNeedReuseOrWait(ProxyConnectInfo *connectInfo) | |||
| 509 | CONN_CHECK_AND_RETURN_RET_LOGE(copyConnectInfo != NULL, false, CONN_PROXY, "copyProxyChannel err"); | 516 | CONN_CHECK_AND_RETURN_RET_LOGE(copyConnectInfo != NULL, false, CONN_PROXY, "copyProxyChannel err"); |
| 510 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL, 0, 0, | 517 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL, 0, 0, |
| 511 | copyConnectInfo, OPEN_PROXY_CHANNEL_WAIT_MS); | 518 | copyConnectInfo, OPEN_PROXY_CHANNEL_WAIT_MS); |
| 512 | - if (ret < 0) { | 519 | + if (ret != SOFTBUS_OK) { |
| 513 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); | 520 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); |
| 514 | DestoryProxyConnectInfo(©ConnectInfo); | 521 | DestoryProxyConnectInfo(©ConnectInfo); |
| 515 | return false; | 522 | return false; |
| @@ -637,7 +644,7 @@ static void OpenProxyChannelHandler(ProxyConnectInfo *connectInfo) | |||
| 637 | 644 | ||
| 638 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL_TIMEOUT, | 645 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL_TIMEOUT, |
| 639 | connection->channelId, 0, NULL, connectInfo->timeoutMs); | 646 | connection->channelId, 0, NULL, connectInfo->timeoutMs); |
| 640 | - if (ret < 0) { | 647 | + if (ret != SOFTBUS_OK) { |
| 641 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); | 648 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); |
| 642 | DestoryProxyConnectInfo(&GetProxyChannelManager()->proxyChannelRequestInfo); | 649 | DestoryProxyConnectInfo(&GetProxyChannelManager()->proxyChannelRequestInfo); |
| 643 | RemoveProxyChannelByChannelId(connection->channelId); | 650 | RemoveProxyChannelByChannelId(connection->channelId); |
| @@ -754,7 +761,7 @@ static int32_t OpenProxyChannel(ProxyChannelParam *param, const OpenProxyChannel | |||
| 754 | CONN_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, CONN_PROXY, | 761 | CONN_CHECK_AND_RETURN_RET_LOGE(ret == SOFTBUS_OK, ret, CONN_PROXY, |
| 755 | "createProxyConnectInfo fail, ret=%{public}d", ret); | 762 | "createProxyConnectInfo fail, ret=%{public}d", ret); |
| 756 | ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL, 0, 0, connectInfo, 0); | 763 | ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL, 0, 0, connectInfo, 0); |
| 757 | - if (ret < 0) { | 764 | + if (ret != SOFTBUS_OK) { |
| 758 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); | 765 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); |
| 759 | DestoryProxyConnectInfo(&connectInfo); | 766 | DestoryProxyConnectInfo(&connectInfo); |
| 760 | return ret; | 767 | return ret; |
| @@ -762,16 +769,50 @@ static int32_t OpenProxyChannel(ProxyChannelParam *param, const OpenProxyChannel | |||
| 762 | return SOFTBUS_OK; | 769 | return SOFTBUS_OK; |
| 763 | } | 770 | } |
| 764 | 771 | ||
| 765 | -static void OnProxyChannelDataReceived(uint32_t channelId, uint8_t *data, uint32_t dataLen) | 772 | +static void ProxyChannelDataReceivedHandler(ProxyChannelDataContext *context) |
| 766 | { | 773 | { |
| 774 | + uint32_t channelId = context->channelId; | ||
| 767 | struct ProxyConnection *proxyConnection = GetProxyChannelByChannelId(channelId); | 775 | struct ProxyConnection *proxyConnection = GetProxyChannelByChannelId(channelId); |
| 768 | - CONN_CHECK_AND_RETURN_LOGE(proxyConnection != NULL, CONN_PROXY, | 776 | + if (proxyConnection == NULL) { |
| 769 | - "get proxyConnection fail, channelId=%{public}u", channelId); | 777 | + CONN_LOGE(CONN_PROXY, "get proxyConnection fail, channelId=%{public}u", channelId); |
| 770 | - CONN_LOGI(CONN_PROXY, "channelId=%{public}u, dataLen=%{public}u", channelId, dataLen); | 778 | + SoftBusFree(context->data); |
| 779 | + context->data = NULL; | ||
| 780 | + return; | ||
| 781 | + } | ||
| 782 | + CONN_LOGI(CONN_PROXY, "channelId=%{public}u, dataLen=%{public}u", channelId, context->dataLen); | ||
| 771 | if (g_listener.onProxyChannelDataReceived != NULL) { | 783 | if (g_listener.onProxyChannelDataReceived != NULL) { |
| 772 | - g_listener.onProxyChannelDataReceived(&proxyConnection->proxyChannel, data, dataLen); | 784 | + g_listener.onProxyChannelDataReceived(&proxyConnection->proxyChannel, context->data, context->dataLen); |
| 773 | } | 785 | } |
| 774 | proxyConnection->dereference(proxyConnection); | 786 | proxyConnection->dereference(proxyConnection); |
| 787 | + SoftBusFree(context->data); | ||
S | |||
| 788 | + context->data = NULL; | ||
| 789 | +} | ||
| 790 | + | ||
| 791 | +static void OnProxyChannelDataReceived(uint32_t channelId, uint8_t *data, uint32_t dataLen) | ||
| 792 | +{ | ||
| 793 | + ProxyChannelDataContext *context = (ProxyChannelDataContext *)SoftBusCalloc(sizeof(ProxyChannelDataContext)); | ||
| 794 | + CONN_CHECK_AND_RETURN_LOGE(context != NULL, CONN_PROXY, "context is null"); | ||
| 795 | + context->data = (uint8_t *)SoftBusCalloc(sizeof(uint8_t) * dataLen); | ||
| 796 | + if (context->data == NULL) { | ||
| 797 | + CONN_LOGE(CONN_PROXY, "calloc data fail"); | ||
| 798 | + SoftBusFree(context); | ||
| 799 | + return; | ||
| 800 | + } | ||
| 801 | + context->channelId = channelId; | ||
| 802 | + if (memcpy_s(context->data, dataLen, data, dataLen) != EOK) { | ||
| 803 | + CONN_LOGE(CONN_PROXY, "memcpy data fail"); | ||
| 804 | + SoftBusFree(context->data); | ||
| 805 | + SoftBusFree(context); | ||
| 806 | + return; | ||
| 807 | + } | ||
| 808 | + context->dataLen = dataLen; | ||
| 809 | + int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_DATA_RECEIVED, 0, 0, context, 0); | ||
| 810 | + if (ret != SOFTBUS_OK) { | ||
| 811 | + CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); | ||
| 812 | + SoftBusFree(context->data); | ||
| 813 | + SoftBusFree(context); | ||
| 814 | + return; | ||
| 815 | + } | ||
| 775 | } | 816 | } |
| 776 | 817 | ||
| 777 | static void NotifyDisconnected(struct ProxyChannel *proxyChannel, int32_t reason) | 818 | static void NotifyDisconnected(struct ProxyChannel *proxyChannel, int32_t reason) |
| @@ -804,7 +845,7 @@ static void OnProxyChannelDisconnected(uint32_t channelId, int32_t reason) | |||
| 804 | ctx->channelId = channelId; | 845 | ctx->channelId = channelId; |
| 805 | ctx->status = reason; | 846 | ctx->status = reason; |
| 806 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_CLOSE_PROXY_DISCONNECT, 0, 0, ctx, 0); | 847 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_CLOSE_PROXY_DISCONNECT, 0, 0, ctx, 0); |
| 807 | - if (ret < 0) { | 848 | + if (ret != SOFTBUS_OK) { |
| 808 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); | 849 | CONN_LOGE(CONN_PROXY, "send msg fail, error=%{public}d", ret); |
| 809 | SoftBusFree(ctx); | 850 | SoftBusFree(ctx); |
| 810 | } | 851 | } |
| @@ -916,7 +957,7 @@ static void AttemptReconnectDevice(char *brAddr) | |||
| 916 | proxyChannelRequestInfo->timeoutMs = INNER_RECONNECT_TIMEOUT_MS; | 957 | proxyChannelRequestInfo->timeoutMs = INNER_RECONNECT_TIMEOUT_MS; |
| 917 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL, | 958 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL, |
| 918 | 0, 0, proxyChannelRequestInfo, config.delayMs); | 959 | 0, 0, proxyChannelRequestInfo, config.delayMs); |
| 919 | - if (ret < 0) { | 960 | + if (ret != SOFTBUS_OK) { |
| 920 | CONN_LOGE(CONN_PROXY, "post msg fail, error=%{public}d", ret); | 961 | CONN_LOGE(CONN_PROXY, "post msg fail, error=%{public}d", ret); |
| 921 | DestoryProxyConnectInfo(&proxyChannelRequestInfo); | 962 | DestoryProxyConnectInfo(&proxyChannelRequestInfo); |
| 922 | } | 963 | } |
| @@ -1006,7 +1047,7 @@ static void ProxyRestoreHandler(void) | |||
| 1006 | proxyChannelRequestInfo->timeoutMs = INNER_RECONNECT_TIMEOUT_MS; | 1047 | proxyChannelRequestInfo->timeoutMs = INNER_RECONNECT_TIMEOUT_MS; |
| 1007 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL, | 1048 | int32_t ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_OPEN_PROXY_CHANNEL, |
| 1008 | 0, 0, proxyChannelRequestInfo, RECONNECT_AFTER_BT_OPEN_WAIT_MS); | 1049 | 0, 0, proxyChannelRequestInfo, RECONNECT_AFTER_BT_OPEN_WAIT_MS); |
| 1009 | - if (ret < 0) { | 1050 | + if (ret != SOFTBUS_OK) { |
| 1010 | CONN_LOGE(CONN_PROXY, "post msg fail, error=%{public}d", ret); | 1051 | CONN_LOGE(CONN_PROXY, "post msg fail, error=%{public}d", ret); |
| 1011 | DestoryProxyConnectInfo(&proxyChannelRequestInfo); | 1052 | DestoryProxyConnectInfo(&proxyChannelRequestInfo); |
| 1012 | } | 1053 | } |
| @@ -1064,7 +1105,7 @@ static void OnProxyAclStateChanged( | |||
| 1064 | } | 1105 | } |
| 1065 | context->state = aclState; | 1106 | context->state = aclState; |
| 1066 | ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_ACL_STATE_CHANGE, 0, 0, context, 0); | 1107 | ret = ConnPostMsgToLooper(&g_proxyChannelAsyncHandler, MSG_ACL_STATE_CHANGE, 0, 0, context, 0); |
| 1067 | - if (ret < 0) { | 1108 | + if (ret != SOFTBUS_OK) { |
| 1068 | CONN_LOGE(CONN_PROXY, "post msg fail, error=%{public}d", ret); | 1109 | CONN_LOGE(CONN_PROXY, "post msg fail, error=%{public}d", ret); |
| 1069 | SoftBusFree(context); | 1110 | SoftBusFree(context); |
| 1070 | } | 1111 | } |
| @@ -1145,6 +1186,11 @@ static void ProxyChannelMsgHandler(SoftBusMessage *msg) | |||
| 1145 | CONN_CHECK_AND_RETURN_LOGW(msg->obj != NULL, CONN_PROXY, "msg->obj is NULL"); | 1186 | CONN_CHECK_AND_RETURN_LOGW(msg->obj != NULL, CONN_PROXY, "msg->obj is NULL"); |
| 1146 | ProxyDeviceUnpaired((const char*)msg->obj); | 1187 | ProxyDeviceUnpaired((const char*)msg->obj); |
| 1147 | break; | 1188 | break; |
| 1189 | + case MSG_DATA_RECEIVED: | ||
| 1190 | + CONN_CHECK_AND_RETURN_LOGW(msg->obj != NULL, CONN_PROXY, "msg->obj is NULL"); | ||
| 1191 | + ProxyChannelDataContext *context = (ProxyChannelDataContext *)(msg->obj); | ||
| 1192 | + ProxyChannelDataReceivedHandler(context); | ||
| 1193 | + break; | ||
| 1148 | default: | 1194 | default: |
| 1149 | CONN_LOGW(CONN_PROXY, "receive unexpected msg, what=%{public}d", msg->what); | 1195 | CONN_LOGW(CONN_PROXY, "receive unexpected msg, what=%{public}d", msg->what); |
| 1150 | break; | 1196 | break; |
建议加一个: context->data = NULL;