swtcp.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /************************************************************************
  2. * AUTHOR: NiuJiuRu
  3. * FILENAME: swtcp.h
  4. * DESCRIPTION: TCP socket
  5. * NOTE:
  6. * HISTORY:
  7. * 1, [2010-11-30] created by NiuJiuRu
  8. ***********************************************************************/
  9. #ifndef __SWTCP_H__
  10. #define __SWTCP_H__
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15. /* 创建一个tcp socket */
  16. int sw_tcp_socket();
  17. /* 关闭一个tcp socket */
  18. void sw_tcp_close(int skt);
  19. /* 连接远端 */
  20. int sw_tcp_connect(int skt, unsigned int ip, unsigned short port);
  21. /* 绑定接收地址和端口, sever使用bind()与本机绑定, client使用connect()与远程主机连接 */
  22. int sw_tcp_bind(int skt, unsigned int ip, unsigned short port);
  23. /* 开始监听, max为处理连接的队列长度, 建议设置为: SOMAXCONN */
  24. int sw_tcp_listen(int skt, int max);
  25. /* 等待远程连接(从连接队列中读取第一个已完成的连接, 队列长度减一) */
  26. int sw_tcp_accept(int skt, unsigned int *ip, unsigned short *port);
  27. /* 发送数据 */
  28. int sw_tcp_send(int skt, const char *buf, int send_len);
  29. /* 接收数据 */
  30. int sw_tcp_recv(int skt, char *buf, int buf_size);
  31. /* 配置tcp socket */
  32. int sw_tcp_ioctl(int skt, int type, unsigned long *val);
  33. /* 检测tcp socket的状态, timeout单位为ms */
  34. int sw_tcp_select(int skt, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, int timeout);
  35. #ifdef __cplusplus
  36. }
  37. #endif
  38. #endif /*__SWTCP_H__*/