LCOV - code coverage report
Current view: top level - base_comm/resources/hccp/rdma_agent/comm - ra_comm.c (source / functions) Coverage Total Hit
Test: coverage.info Lines: 100.0 % 46 46
Test Date: 2026-07-28 12:11:00 Functions: 100.0 % 3 3

            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 "ra_comm.h"
      12              : #include <errno.h>
      13              : #include "securec.h"
      14              : #include "ra_rs_err.h"
      15              : 
      16            6 : int RaGetSocketConnectInfo(const struct SocketConnectInfoT conn[], unsigned int num,
      17              :     struct SocketConnectInfo rsConn[], unsigned int rsNum)
      18              : {
      19            6 :     struct RaSocketHandle *socketHandle = NULL;
      20              :     unsigned int i;
      21              :     int ret;
      22              : 
      23            6 :     CHK_PRT_RETURN(num > rsNum || num > MAX_SOCKET_NUM || num == 0 || conn == NULL || rsConn == NULL, hccp_err("[get]"
      24              :         "[ra_socket_connect_info]num(%u) > rs_num(%u) or num == 0 or conn or rs_conn is NULL, invalid", num, rsNum), -EINVAL);
      25            9 :     for (i = 0; i < num; i++) {
      26            5 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
      27            5 :         CHK_PRT_RETURN(socketHandle == NULL,
      28              :             hccp_err("[get][ra_socket_connect_info] conn[%u].socketHandle is null", i), -EINVAL);
      29            5 :         rsConn[i].phyId = socketHandle->rdevInfo.phyId;
      30            5 :         rsConn[i].family = socketHandle->rdevInfo.family;
      31            5 :         rsConn[i].port = conn[i].port;
      32            5 :         ret = memcpy_s(&(rsConn[i].localIp), sizeof(union HccpIpAddr),
      33            5 :             &(socketHandle->rdevInfo.localIp), sizeof(union HccpIpAddr));
      34            5 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_connect_info]memcpy_s for local_ip failed, ret(%d)",
      35              :             ret), -ESAFEFUNC);
      36            4 :         ret = memcpy_s(&(rsConn[i].remoteIp), sizeof(union HccpIpAddr),
      37            4 :             &(conn[i].remoteIp), sizeof(union HccpIpAddr));
      38            4 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_connect_info]memcpy_s for remote_ip failed, ret(%d)",
      39              :             ret), -ESAFEFUNC);
      40            4 :         ret = memcpy_s(rsConn[i].tag, SOCK_CONN_TAG_SIZE, conn[i].tag, SOCK_CONN_TAG_SIZE);
      41            4 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_connect_info]memcpy_s for tag failed, ret(%d)",
      42              :             ret), -ESAFEFUNC);
      43              :     }
      44            4 :     return 0;
      45              : }
      46              : 
      47           16 : int RaGetSocketListenInfo(const struct SocketListenInfoT conn[], unsigned int num,
      48              :     struct SocketListenInfo rsConn[], unsigned int rsNum)
      49              : {
      50              :     unsigned int i;
      51              :     int ret;
      52           16 :     struct RaSocketHandle *socketHandle = NULL;
      53              : 
      54           16 :     CHK_PRT_RETURN(num > rsNum || num > MAX_SOCKET_NUM || num == 0 || conn == NULL || rsConn == NULL, hccp_err("[get]"
      55              :         "[ra_socket_listen_info]num(%u) > rs_num(%u) or num == 0 or conn or rsConn is NULL, invalid", num, rsNum), -EINVAL);
      56              : 
      57           29 :     for (i = 0; i < num; i++) {
      58           15 :         rsConn[i].phase = conn[i].phase;
      59           15 :         rsConn[i].err = conn[i].err;
      60           15 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
      61           15 :         rsConn[i].phyId = socketHandle->rdevInfo.phyId;
      62           15 :         rsConn[i].family = socketHandle->rdevInfo.family;
      63           15 :         rsConn[i].port = conn[i].port;
      64           15 :         ret = memcpy_s(&(rsConn[i].localIp), sizeof(union HccpIpAddr),
      65           15 :             &(socketHandle->rdevInfo.localIp), sizeof(union HccpIpAddr));
      66           15 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_listen_info]memcpy_s for local_ip failed, ret(%d)",
      67              :             ret), -ESAFEFUNC);
      68              :     }
      69           14 :     return 0;
      70              : }
      71              : 
      72            4 : int RaGetSocketListenResult(const struct SocketListenInfo rsConn[], unsigned int rsNum,
      73              :     struct SocketListenInfoT conn[], unsigned int num)
      74              : {
      75            4 :     struct RaSocketHandle *socketHandle = NULL;
      76              :     unsigned int i;
      77              :     int ret;
      78              : 
      79            4 :     CHK_PRT_RETURN(rsNum > num || rsNum > MAX_SOCKET_NUM || num == 0 || conn == NULL || rsConn == NULL, hccp_err("[get]"
      80              :         "[ra_socket_listen_result]rs_num(%u) > num(%u) or num == 0 or conn or rs_conn is NULL, invalid", rsNum, num), -EINVAL);
      81              : 
      82            5 :     for (i = 0; i < rsNum; i++) {
      83            3 :         conn[i].phase = rsConn[i].phase;
      84            3 :         conn[i].err = rsConn[i].err;
      85            3 :         conn[i].port = rsConn[i].port;
      86            3 :         socketHandle = (struct RaSocketHandle *)conn[i].socketHandle;
      87            3 :         socketHandle->rdevInfo.phyId = rsConn[i].phyId;
      88            3 :         socketHandle->rdevInfo.family = rsConn[i].family;
      89            3 :         ret = memcpy_s(&(socketHandle->rdevInfo.localIp), sizeof(union HccpIpAddr),
      90            3 :             &(rsConn[i].localIp), sizeof(union HccpIpAddr));
      91            3 :         CHK_PRT_RETURN(ret, hccp_err("[get][ra_socket_listen_result]memcpy_s for local_ip failed, ret(%d)",
      92              :             ret), -ESAFEFUNC);
      93              :     }
      94            2 :     return 0;
      95              : }
        

Generated by: LCOV version 2.0-1