| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- /************************************************************************
- * AUTHOR: NiuJiuRu
- * FILENAME: swtcp.h
- * DESCRIPTION: TCP socket
- * NOTE:
- * HISTORY:
- * 1, [2010-11-30] created by NiuJiuRu
- ***********************************************************************/
- #ifndef __SWTCP_H__
- #define __SWTCP_H__
- #ifdef __cplusplus
- extern "C"
- {
- #endif
- /* 创建一个tcp socket */
- int sw_tcp_socket();
- /* 关闭一个tcp socket */
- void sw_tcp_close(int skt);
- /* 连接远端 */
- int sw_tcp_connect(int skt, unsigned int ip, unsigned short port);
- /* 绑定接收地址和端口, sever使用bind()与本机绑定, client使用connect()与远程主机连接 */
- int sw_tcp_bind(int skt, unsigned int ip, unsigned short port);
- /* 开始监听, max为处理连接的队列长度, 建议设置为: SOMAXCONN */
- int sw_tcp_listen(int skt, int max);
- /* 等待远程连接(从连接队列中读取第一个已完成的连接, 队列长度减一) */
- int sw_tcp_accept(int skt, unsigned int *ip, unsigned short *port);
- /* 发送数据 */
- int sw_tcp_send(int skt, const char *buf, int send_len);
- /* 接收数据 */
- int sw_tcp_recv(int skt, char *buf, int buf_size);
- /* 配置tcp socket */
- int sw_tcp_ioctl(int skt, int type, unsigned long *val);
- /* 检测tcp socket的状态, timeout单位为ms */
- int sw_tcp_select(int skt, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, int timeout);
- #ifdef __cplusplus
- }
- #endif
- #endif /*__SWTCP_H__*/
|