---
title: SendFully
description: "发送数据给对端。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengboostkithistory/230RC2/armnative/kunpengcpsinstruction_17_0014.html
sourcePath: /source/zh/kunpengboostkithistory/230RC2/armnative/kunpengcpsinstruction_17_0014.html
indexId: dc52e92dee58040343b9e2bcc082e8ac9367954fe546ad34690445ae76cf9e4685
---
# SendFully

#### 函数功能

发送数据给对端。


#### 约束说明

指令流引擎要求二次开发者实现通信模块，用于数据的发送和接收。该函数是指令流引擎要求二次开发者在通信模块实现的外部符号，指令流引擎会调用该函数发送数据。通信库需保证SendFully把调用者传入的数据全部发送完或者发生错误才能返回，且需支持多线程互斥调用。


#### 函数原型

ssize_t SendFully(int connection, uint8_t *buf, size_t len)


#### 参数说明

| 参数名称 | 输入/输出 | 参数类型 | 参数描述 |
| --- | --- | --- | --- |
| connection | 输入 | int | 通信连接的标识。 |
| buf | 输入 | uint8\_t \* | 指向待发送数据的内存指针。 |
| len | 输入 | size\_t | 待发送数据长度，不超过64KB。 |


#### 返回值说明

数据类型：ssize_t

取值如下：

- 大于0：表示实际发送的字节数。
- -3：无效参数，如无效的链接句柄、传入的buf为空或len为0。
- -4：连接已经断开。


#### 调用示例

```
// 函数原型声明，实现由客户提供
using OnNewConnectionCallback = void (*)(int connection);
using RegConnectionCBFunc = int (*)(OnNewConnectionCallback newConnCb);
using CloseConnectionFunc = int (*)(int connection);
using SendFullyFunc = ssize_t (*)(int connection, uint8_t *buf, size_t len);
using RecvFunc = ssize_t (*)(int connection, uint8_t *buf, size_t len);
const char *soPath = "./libCommunication.so";
//服务端收到新连接回调函数，由云手机引擎提供
//输入参数connection代表新连接的有效句柄
static void OnNewConnection(int conn);
void Test()
{
// 动态加载通信动态库的函数符号
void *handle = dlopen(soPath, RTLD_GLOBAL | RTLD_LAZY | RTLD_NODELETE);
RegConnectionCBFunc regConnection = (RegConnectionCBFunc)dlsym(handle, "RegConnectionCB");
CloseConnectionFunc closeConnection = (CloseConnectionFunc)dlsym(handle, "CloseConnection");
SendFullyFunc sendFully = (SendFullyFunc)dlsym(handle, "SendFully");
RecvFunc recvData = (RecvFunc)dlsym(handle, "Recv");
size_t bufSize = 1024;
uint8_t *data = malloc(bufSize);
// 创建连接，连接服务端
int connRet = regConnection(OnNewConnection);
// 发送数据
ssize_t ret = sendFully(conn, data, bufSize);
// 接收数据
ret = recvData(conn, data, bufSize);
// 释放资源
free(data);
closeConnection(conn);
dlclose(handle);
}
```
