|
xt-sdk 文档 v1.0.3
xt-sdk 嵌入式 SDK API 参考
|
跨平台 Socket 抽象层 更多...
宏定义 | |
| #define | XT_SOCKET_INVALID (-1) |
| #define | XT_SOCKET_ERROR (-1) |
| #define | closesocket(s) |
| #define | XT_SELECT_NFDS(fd) |
类型定义 | |
| typedef int | xt_socket_t |
函数 | |
| xt_err_t | xt_socket_setup (void) |
| 初始化 Socket 平台层 | |
| void | xt_socket_cleanup (void) |
| 反初始化 Socket 平台层 | |
| int | xt_socket_errno (void) |
| 获取最近一次 Socket 操作的错误码 | |
| const char * | xt_socket_strerror (int err) |
| 将 Socket 错误码转为可读字符串 | |
| xt_err_t | xt_socket_set_nonblock (xt_socket_t s, int nonblock) |
| 设置或清除 Socket 非阻塞模式 | |
| static int | xt_socket_read (xt_socket_t s, void *buf, size_t len) |
| 从 Socket 读取数据(POSIX read 的跨平台封装) | |
| static int | xt_socket_write (xt_socket_t s, const void *buf, size_t len) |
| 向 Socket 写入数据(POSIX write 的跨平台封装) | |
跨平台 Socket 抽象层
| #define closesocket | ( | s | ) |
在文件 xt_socket.h 第 195 行定义.
| #define XT_SELECT_NFDS | ( | fd | ) |
在文件 xt_socket.h 第 211 行定义.
| #define XT_SOCKET_ERROR (-1) |
在文件 xt_socket.h 第 192 行定义.
| #define XT_SOCKET_INVALID (-1) |
在文件 xt_socket.h 第 191 行定义.
| typedef int xt_socket_t |
在文件 xt_socket.h 第 190 行定义.
| void xt_socket_cleanup | ( | void | ) |
反初始化 Socket 平台层
释放 Socket 子系统占用的平台资源。所有 Socket 操作完成后调用, 与 xt_socket_setup() 配对使用。
| int xt_socket_errno | ( | void | ) |
获取最近一次 Socket 操作的错误码
当 BSD Socket API(如 socket、bind、connect 等)返回 XT_SOCKET_ERROR 或 其他错误指示时,调用此函数获取具体的错误码。
| >0 | 错误编号 |
| 0 | 无错误 |
|
inlinestatic |
从 Socket 读取数据(POSIX read 的跨平台封装)
| s | Socket 句柄 |
| buf | 接收缓冲区 |
| len | 缓冲区大小 |
在文件 xt_socket.h 第 323 行定义.
| xt_err_t xt_socket_set_nonblock | ( | xt_socket_t | s, |
| int | nonblock ) |
设置或清除 Socket 非阻塞模式
控制指定 Socket 的 I/O 模式为阻塞或非阻塞。非阻塞模式下,send、recv 等操作 立即返回而不等待,通过返回值判断操作完成状态。
| s | Socket 句柄 |
| nonblock | 非阻塞标志
|
| xt_err_t xt_socket_setup | ( | void | ) |
初始化 Socket 平台层
在不同平台上执行 Socket 子系统初始化。必须在任何 Socket API 调用之前调用, 且只需调用一次。
| const char * xt_socket_strerror | ( | int | err | ) |
将 Socket 错误码转为可读字符串
将 xt_socket_errno() 返回的错误码转换为人类可读的字符串描述,用于日志输出 和调试。
| err | 错误码(由 xt_socket_errno() 返回) |
|
inlinestatic |
向 Socket 写入数据(POSIX write 的跨平台封装)
| s | Socket 句柄 |
| buf | 数据缓冲区 |
| len | 写入大小 |
在文件 xt_socket.h 第 347 行定义.