LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/client/async - ra_socket.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 88 88
Test Date: 2026-08-04 10:52:23 Functions: 100.0 % 6 6

            Line data    Source code
       1              : /**
       2              :  * Copyright (c) 2025 Huawei Technologies Co., Ltd.
       3              :  * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
       4              :  * CANN Open Software License Agreement Version 2.0 (the "License").
       5              :  * Please refer to the License for details. You may not use this file except in compliance with the License.
       6              :  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
       7              :  * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
       8              :  * See LICENSE in the root of the software repository for the full text of the License.
       9              :  */
      10              : 
      11              : #include "user_log.h"
      12              : #include "hccp_common.h"
      13              : #include "hccp_async.h"
      14              : #include "ra.h"
      15              : #include "ra_hdc_async_socket.h"
      16              : #include "ra_client_host.h"
      17              : 
      18            5 : HCCP_ATTRI_VISI_DEF int RaSocketBatchConnectAsync(struct SocketConnectInfoT conn[], unsigned int num,
      19              :     void **reqHandle)
      20              : {
      21            5 :     struct RaSocketHandle *socketHandle = NULL;
      22            5 :     char remoteIp[MAX_IP_LEN] = {0};
      23            5 :     char localIp[MAX_IP_LEN] = {0};
      24            5 :     unsigned int phyId = 0;
      25            5 :     unsigned int i = 0;
      26            5 :     int ret = 0;
      27              : 
      28            5 :     CHK_PRT_RETURN(conn == NULL || reqHandle == NULL, hccp_err("[batch_connect][ra_socket]conn or "
      29              :         "req_handle is NULL"), ConverReturnCode(SOCKET_OP, -EINVAL));
      30              : 
      31            3 :     CHK_PRT_RETURN(num == 0 || num > MAX_SOCKET_NUM, hccp_err("[batch_connect][ra_socket]num[%u] invalid, "
      32              :         "must in range of (0, %u]", num, MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
      33              : 
      34            3 :     for (i = 0; i < num; i++) {
      35            2 :         socketHandle = (struct RaSocketHandle *)(conn[i].socketHandle);
      36            2 :         CHK_PRT_RETURN(socketHandle == NULL, hccp_err("[batch_connect][ra_socket]socket_handle is NULL"),
      37              :             ConverReturnCode(SOCKET_OP, -EINVAL));
      38              : 
      39            1 :         phyId = socketHandle->rdevInfo.phyId;
      40            1 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[batch_connect][ra_socket]phyId[%u]invalid, "
      41              :             "must in range of [0, %u)", phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
      42              : 
      43            1 :         CHK_PRT_RETURN(strlen(conn[i].tag) >= SOCK_CONN_TAG_SIZE,
      44              :             hccp_err("[batch_connect][ra_socket]conn tag len(%d) more than max len(%u)",
      45              :             strlen(conn[i].tag), SOCK_CONN_TAG_SIZE), ConverReturnCode(SOCKET_OP, -EINVAL));
      46              : 
      47            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
      48            1 :         CHK_PRT_RETURN(ret != 0, hccp_err("[batch_connect][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
      49              :             ConverReturnCode(SOCKET_OP, ret));
      50              : 
      51            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, conn[i].remoteIp, remoteIp, MAX_IP_LEN);
      52            1 :         CHK_PRT_RETURN(ret != 0, hccp_err("[batch_connect][ra_socket]ra_inet_pton for remote_ip failed, ret(%d)", ret),
      53              :             ConverReturnCode(SOCKET_OP, ret));
      54              : 
      55            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], remoteIp[%s], port[%u], tag[%s], cnt[%u]",
      56              :             i, socketHandle->rdevInfo.phyId, localIp, remoteIp, conn[i].port, conn[i].tag,
      57              :             socketHandle->connectCnt);
      58              :     }
      59              : 
      60            1 :     socketHandle->connectCnt++;
      61            1 :     ret = RaHdcSocketBatchConnectAsync(phyId, conn, num, reqHandle);
      62            1 :     return ConverReturnCode(SOCKET_OP, ret);
      63              : }
      64              : 
      65            5 : HCCP_ATTRI_VISI_DEF int RaSocketListenStartAsync(struct SocketListenInfoT conn[], unsigned int num,
      66              :     void **reqHandle)
      67              : {
      68            5 :     struct RaSocketHandle *socketHandle = NULL;
      69            5 :     char localIp[MAX_IP_LEN] = {0};
      70            5 :     unsigned int phyId = 0;
      71            5 :     unsigned int i = 0;
      72            5 :     int ret = 0;
      73              : 
      74            5 :     CHK_PRT_RETURN(conn == NULL || reqHandle == NULL, hccp_err("[listen_start][ra_socket]conn or req_handle is NULL"),
      75              :         ConverReturnCode(SOCKET_OP, -EINVAL));
      76              : 
      77            3 :     CHK_PRT_RETURN(num == 0 || num > MAX_SOCKET_NUM, hccp_err("[listen_start][ra_socket]num[%u] invalid, "
      78              :         "must in range of (0, %u]", num, MAX_SOCKET_NUM),
      79              :         ConverReturnCode(SOCKET_OP, -EINVAL));
      80              : 
      81            3 :     for (i = 0; i < num; i++) {
      82            2 :         socketHandle = (struct RaSocketHandle *)(conn[i].socketHandle);
      83            2 :         CHK_PRT_RETURN(socketHandle == NULL, hccp_err("[listen_start][ra_socket]socket_handle is NULL"),
      84              :             ConverReturnCode(SOCKET_OP, -EINVAL));
      85              : 
      86            1 :         phyId = socketHandle->rdevInfo.phyId;
      87            1 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[listen_start][ra_socket]phyId[%u]invalid, "
      88              :             "must in range of [0, %u)", phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
      89              : 
      90            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
      91            1 :         CHK_PRT_RETURN(ret != 0, hccp_err("[listen_start][ra_socket]ra_inet_pton for server_ip failed, ret(%d)", ret),
      92              :             ConverReturnCode(SOCKET_OP, ret));
      93              : 
      94            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], port[%u]", i, phyId, localIp,
      95              :             conn[i].port);
      96              :     }
      97              : 
      98            1 :     ret = RaHdcSocketListenStartAsync(phyId, conn, num, reqHandle);
      99            1 :     return ConverReturnCode(SOCKET_OP, ret);
     100              : }
     101              : 
     102            5 : HCCP_ATTRI_VISI_DEF int RaSocketListenStopAsync(struct SocketListenInfoT conn[], unsigned int num,
     103              :     void **reqHandle)
     104              : {
     105            5 :     struct RaSocketHandle *socketHandle = NULL;
     106            5 :     char localIp[MAX_IP_LEN] = {0};
     107            5 :     unsigned int phyId = 0;
     108            5 :     unsigned int i = 0;
     109            5 :     int ret = 0;
     110              : 
     111            5 :     CHK_PRT_RETURN(conn == NULL || reqHandle == NULL, hccp_err("[listen_stop][ra_socket]conn or req_handle is NULL"),
     112              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     113              : 
     114            3 :     CHK_PRT_RETURN(num == 0 || num > MAX_SOCKET_NUM, hccp_err("[listen_stop][ra_socket]num[%u] invalid, "
     115              :         "must in range of (0, %u]", num, MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     116              : 
     117            3 :     for (i = 0; i < num; i++) {
     118            2 :         socketHandle = (struct RaSocketHandle *)(conn[i].socketHandle);
     119            2 :         CHK_PRT_RETURN(socketHandle == NULL, hccp_err("[listen_stop][ra_socket]socket_handle is NULL"),
     120              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     121              : 
     122            1 :         phyId = socketHandle->rdevInfo.phyId;
     123            1 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[listen_stop][ra_socket]phyId[%u]invalid, "
     124              :             "must in range of [0, %u)", phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     125              : 
     126            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     127            1 :         CHK_PRT_RETURN(ret != 0, hccp_err("[listen_stop][ra_socket]ra_inet_pton for server_ip failed, ret(%d)", ret),
     128              :             ConverReturnCode(SOCKET_OP, ret));
     129              : 
     130            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s]", i, phyId, localIp);
     131              :     }
     132              : 
     133            1 :     ret = RaHdcSocketListenStopAsync(phyId, conn, num, reqHandle);
     134            1 :     return ConverReturnCode(SOCKET_OP, ret);
     135              : }
     136              : 
     137            5 : HCCP_ATTRI_VISI_DEF int RaSocketBatchCloseAsync(struct SocketCloseInfoT conn[], unsigned int num,
     138              :     void **reqHandle)
     139              : {
     140            5 :     struct RaSocketHandle *socketHandle = NULL;
     141            5 :     char localIp[MAX_IP_LEN] = {0};
     142            5 :     unsigned int phyId = 0;
     143            5 :     unsigned int i = 0;
     144            5 :     int ret = 0;
     145              : 
     146            5 :     CHK_PRT_RETURN(conn == NULL || reqHandle == NULL, hccp_err("[batch_close][ra_socket]conn or req_handle is NULL"),
     147              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     148              : 
     149            3 :     CHK_PRT_RETURN(num == 0 || num > MAX_SOCKET_NUM, hccp_err("[batch_close][ra_socket]num[%u] invalid, "
     150              :         "must in range of (0, %u]", num, MAX_SOCKET_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     151              : 
     152            3 :     for (i = 0; i < num; i++) {
     153            2 :         socketHandle = (struct RaSocketHandle *)(conn[i].socketHandle);
     154            2 :         CHK_PRT_RETURN(socketHandle == NULL, hccp_err("[batch_close][ra_socket]socket_handle is NULL"),
     155              :             ConverReturnCode(SOCKET_OP, -EINVAL));
     156              : 
     157            1 :         phyId = socketHandle->rdevInfo.phyId;
     158            1 :         CHK_PRT_RETURN(phyId >= RA_MAX_PHY_ID_NUM, hccp_err("[batch_close][ra_socket]phyId[%u]invalid, "
     159              :             "must in range of [0, %u)", phyId, RA_MAX_PHY_ID_NUM), ConverReturnCode(SOCKET_OP, -EINVAL));
     160              : 
     161            1 :         ret = RaInetPton(socketHandle->rdevInfo.family, socketHandle->rdevInfo.localIp, localIp, MAX_IP_LEN);
     162            1 :         CHK_PRT_RETURN(ret != 0, hccp_err("[batch_close][ra_socket]ra_inet_pton for local_ip failed, ret(%d)", ret),
     163              :             ConverReturnCode(SOCKET_OP, ret));
     164              : 
     165            1 :         hccp_run_info("Input parameters: [%u]th, phyId[%u], localIp[%s], cnt[%u]", i, phyId, localIp,
     166              :             socketHandle->closeCnt);
     167              :     }
     168              : 
     169            1 :     socketHandle->closeCnt++;
     170            1 :     ret = RaHdcSocketBatchCloseAsync(phyId, conn, num, reqHandle);
     171            1 :     return ConverReturnCode(SOCKET_OP, ret);
     172              : }
     173              : 
     174            1 : HCCP_ATTRI_VISI_DEF int RaSocketSendAsync(const void *fdHandle, const void *data, unsigned long long size,
     175              :     unsigned long long *sentSize, void **reqHandle)
     176              : {
     177            1 :     int ret = 0;
     178              : 
     179            1 :     CHK_PRT_RETURN(fdHandle == NULL || data == NULL || sentSize == NULL || size == 0 || reqHandle == NULL,
     180              :         hccp_err("[send][ra_socket]fd_handle or data or sent_size or req_handle is NULL or size[%llu] is 0", size),
     181              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     182              : 
     183            1 :     ret = RaHdcSocketSendAsync((const struct SocketHdcInfo *)fdHandle, data, size, sentSize, reqHandle);
     184            1 :     return ConverReturnCode(SOCKET_OP, ret);
     185              : }
     186              : 
     187            1 : HCCP_ATTRI_VISI_DEF int RaSocketRecvAsync(const void *fdHandle, void *data, unsigned long long size,
     188              :     unsigned long long *receivedSize, void **reqHandle)
     189              : {
     190            1 :     int ret = 0;
     191              : 
     192            1 :     CHK_PRT_RETURN(fdHandle == NULL || data == NULL || receivedSize == NULL || size == 0 || reqHandle == NULL,
     193              :         hccp_err("[recv][ra_socket]fd_handle or data or received_size or req_handle is NULL or size[%llu] is 0", size),
     194              :         ConverReturnCode(SOCKET_OP, -EINVAL));
     195              : 
     196            1 :     ret = RaHdcSocketRecvAsync((const struct SocketHdcInfo *)fdHandle, data, size, receivedSize, reqHandle);
     197            1 :     return ConverReturnCode(SOCKET_OP, ret);
     198              : }
        

Generated by: LCOV version 2.0-1