| | |
| | | #define __NET_MOD_SOCKET_H__ |
| | | |
| | | #include "net_mod_socket.h" |
| | | #include "proc_def.h" |
| | | |
| | | #ifdef __cplusplus |
| | | extern "C" { |
| | |
| | | */ |
| | | void * net_mod_socket_open(); |
| | | |
| | | |
| | | /** |
| | | * @brief 关闭 net_mod_socket |
| | | */ |
| | | void net_mod_socket_close(void *_sockt); |
| | | |
| | | |
| | | /** |
| | | * @brief 停止 net_mod_socket |
| | | */ |
| | | int net_mod_socket_stop(void *_sockt); |
| | | |
| | | /** |
| | | * @brief 绑定端口到socket, 如果不绑定则系统自动分配一个 |
| | |
| | | */ |
| | | int net_mod_socket_force_bind(void * _socket, int key); |
| | | |
| | | int net_mod_socket_reg(void *_socket, void *pData, int len, void **buf, int *size, const int timeout_ms, int flag); |
| | | |
| | | /** |
| | | * @brief 发送信息,发送完成才返回 |
| | | * |
| | |
| | | * |
| | | * @return 0是成功, 其他值是失败的错误码 |
| | | */ |
| | | int net_mod_socket_sendto(void *_socket, const void *buf, const int size, const int key); |
| | | int net_mod_socket_sendto(void *_socket, const void *buf, const int size, const int key, int reset = 0, int data_set = 0); |
| | | |
| | | /** |
| | | * @brief 发送信息,在指定时间内没发送完成也返回。 |
| | |
| | | * |
| | | * @return 0是成功, 其他值是失败的错误码 |
| | | */ |
| | | int net_mod_socket_sendto_timeout(void *_socket, const void *buf, const int size, const int key, int sec, int nsec); |
| | | int net_mod_socket_sendto_timeout(void *_socket, const void *buf, const int size, const int key, int sec, int nsec, int reset = 0, int data_set = 0); |
| | | |
| | | /** |
| | | * @brief 发送信息,无论是否发送完成立刻返回。 |
| | |
| | | * |
| | | * @return 0是成功, 其他值是失败的错误码 |
| | | */ |
| | | int net_mod_socket_sendto_nowait(void *_socket, const void *buf, const int size, const int key); |
| | | int net_mod_socket_sendto_nowait(void *_socket, const void *buf, const int size, const int key, int reset = 0, int data_set = 0); |
| | | |
| | | /** |
| | | * @brief 等待接收信息,直到有消息接受到才返回 |
| | |
| | | * |
| | | * @return 0是成功, 其他值是失败的错误码 |
| | | */ |
| | | int net_mod_socket_recvfrom(void *_socket, void **buf, int *size, int *key); |
| | | int net_mod_socket_recvfrom(void *_socket, void **buf, int *size, int *key, int reset = 0, int data_set = 0); |
| | | |
| | | /** |
| | | * @brief 等待接收信息,在指定的时间内即使没有接受到消息也要返回 |
| | |
| | | * |
| | | * @return 0是成功, 其他值是失败的错误码 |
| | | */ |
| | | int net_mod_socket_recvfrom_timeout(void *_socket, void **buf, int *size, int *key, int sec, int nsec); |
| | | int net_mod_socket_recvfrom_timeout(void *_socket, void **buf, int *size, int *key, int sec, int nsec, int reset = 0, int data_set = 0); |
| | | |
| | | /** |
| | | * @brief 等待接收信息,直到有消息接受到才返回 |
| | |
| | | * |
| | | * @return 0是成功,其他值是失败的错误码 |
| | | */ |
| | | int net_mod_socket_recvfrom_nowait(void *_socket, void **buf, int *size, int *key); |
| | | int net_mod_socket_recvfrom_nowait(void *_socket, void **buf, int *size, int *key, int reset = 0, int data_set = 0); |
| | | |
| | | |
| | | |
| | | void net_mod_socket_int_set(void * _socket, int data); |
| | | void net_mod_socket_svr_set(void * _socket, int data); |
| | | int net_mod_socket_int_get(void * _socket); |
| | | int net_mod_socket_svr_get(void * _socket); |
| | | void net_mod_socket_buf_data_set(void * _socket, std::string str, int val); |
| | | int net_mod_socket_buf_data_get(void * _socket, std::string str); |
| | | void net_mod_socket_buf_data_del(void * _socket, std::string str); |
| | | |
| | | /** |
| | | * @brief 跨机器发送消息并接受返回的应答消息,直到发送完成才返回 |
| | |
| | | * @param node_arr_len该数组长度.如果IP为空则为本地发送。 |
| | | * @param send_buf 发送的消息 |
| | | * @param send_size 该消息体的长度 |
| | | * @param recv_arr 返回的应答消息数组 |
| | | * @param recv_arr 返回的应答消息数组,使用完后需要调用net_mod_socket_free_recv_msg_arr释放掉 |
| | | * @param recv_arr_size 返回的应答消息数组长度 |
| | | * @param err_arr 返回发送错误的节点数组,使用完后需要调用free方法释放掉 |
| | | × @param err_arr_size 返回发送错误的节点数组的长度 |
| | | * |
| | | * @return 成功发送的节点的个数 |
| | | * |
| | | */ |
| | | int net_mod_socket_sendandrecv(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, |
| | | net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ; |
| | | net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, |
| | | net_mod_err_t ** err_arr, int *err_arr_size) ; |
| | | |
| | | |
| | | /** |
| | |
| | | * @param node_arr_len该数组长度.如果IP为空则为本地发送。 |
| | | * @param send_buf 发送的消息 |
| | | * @param send_size 该消息体的长度 |
| | | * @param recv_arr 返回的应答消息数组 |
| | | * @param recv_arr 返回的应答消息数组,使用完后需要调用net_mod_socket_free_recv_msg_arr释放掉 |
| | | * @param recv_arr_size 返回的应答消息数组长度 |
| | | * @param err_arr 返回发送错误的节点数组,使用完后需要调用free方法释放掉 |
| | | × @param err_arr_size 返回发送错误的节点数组的长度 |
| | | * @param timeout 等待时间(豪秒,即千分之一秒) |
| | | * |
| | | * @return 成功发送的节点的个数 |
| | | * |
| | | */ |
| | | int net_mod_socket_sendandrecv_timeout(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, |
| | | net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, int timeout); |
| | | net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, |
| | | net_mod_err_t ** err_arr, int *err_arr_size, int timeout); |
| | | |
| | | |
| | | /** |
| | | * @brief 跨机器发送消息并接受返回的应答消息,不管是否发送完成立刻返回 |
| | | * |
| | | * 向node_arr 中的所有网络节点发送请求消息,节点的返回信息汇总并存储在recv_arr中 |
| | | * @param node_arr 网络节点组, |
| | | * @param node_arr_len该数组长度.如果IP为空则为本地发送。 |
| | | * @param send_buf 发送的消息 |
| | | * @param send_size 该消息体的长度 |
| | | * @param recv_arr 返回的应答消息数组,使用完后需要调用net_mod_socket_free_recv_msg_arr释放掉 |
| | | * @param recv_arr_size 返回的应答消息数组长度 |
| | | * @param err_arr 返回发送错误的节点数组,使用完后需要调用free方法释放掉 |
| | | × @param err_arr_size 返回发送错误的节点数组的长度 |
| | | * |
| | | * @return 成功发送的节点的个数 |
| | | * |
| | | */ |
| | | int net_mod_socket_sendandrecv_nowait(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, |
| | | net_mod_recv_msg_t ** recv_arr, int *recv_arr_size, |
| | | net_mod_err_t ** err_arr, int *err_arr_size) ; |
| | | |
| | | |
| | | |
| | |
| | | int net_mod_socket_recvandsend_nowait(void *_socket, recvandsend_callback_wrapper_fn callback, void * user_data) ; |
| | | |
| | | |
| | | /** |
| | | * @brief 跨机器发送消息并接受返回的应答消息,不管是否发送完成立刻返回 |
| | | * |
| | | * 向node_arr 中的所有网络节点发送请求消息,节点的返回信息汇总并存储在recv_arr中 |
| | | * @param node_arr 网络节点组, |
| | | * @param node_arr_len该数组长度.如果IP为空则为本地发送。 |
| | | * @param send_buf 发送的消息 |
| | | * @param send_size 该消息体的长度 |
| | | * @param recv_arr 返回的应答消息数组 |
| | | * @param recv_arr_size 返回的应答消息数组长度 |
| | | * |
| | | * @return 成功发送的节点的个数 |
| | | * |
| | | */ |
| | | int net_mod_socket_sendandrecv_nowait(void *_sockt, net_node_t *node_arr, int arrlen, void *send_buf, int send_size, |
| | | net_mod_recv_msg_t ** recv_arr, int *recv_arr_size) ; |
| | | |
| | | |
| | | |
| | | /** |
| | | * @brief 向node_arr中的所有网络节点发布消息 |
| | |
| | | * |
| | | * @return 成功发布的节点的个数 |
| | | */ |
| | | int net_mod_socket_pub(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); |
| | | int net_mod_socket_pub(void *_sockt, net_node_t *node_arr, int node_arr_len, const char *topic, int topic_size, const void *content, int content_size); |
| | | |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return 成功发布的节点的个数 |
| | | */ |
| | | int net_mod_socket_pub_timeout(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size, int msec); |
| | | int net_mod_socket_pub_timeout(void *_sockt, net_node_t *node_arr, int node_arr_len, const char *topic, int topic_size, const void *content, int content_size, int msec); |
| | | |
| | | |
| | | /** |
| | |
| | | * |
| | | * @return 成功发布的节点的个数 |
| | | */ |
| | | int net_mod_socket_pub_nowait(void *_sockt, net_node_t *node_arr, int node_arr_len, char *topic, int topic_size, void *content, int content_size); |
| | | int net_mod_socket_pub_nowait(void *_sockt, net_node_t *node_arr, int node_arr_len, const char *topic, int topic_size, const void *content, int content_size); |
| | | |
| | | /** |
| | | * @brief 订阅感兴趣主题的消息 |
| | |
| | | } |
| | | #endif |
| | | |
| | | #endif |
| | | #endif |