You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

47 lines
1.4 KiB

  1. #ifndef NETUTIL_H
  2. #define NETUTIL_H
  3. #include <sys/types.h>
  4. #include <sys/time.h>
  5. #include <fcntl.h>
  6. #ifdef __WIN32__
  7. # include <winsock2.h>
  8. # include <ws2tcpip.h>
  9. # define socklen_t int
  10. # define in_addr_t uint32_t
  11. # define in_port_t uint16_t
  12. #else
  13. # include <sys/socket.h>
  14. # include <netinet/in.h>
  15. # include <arpa/inet.h>
  16. # include <netdb.h>
  17. #endif
  18. /* Initialize networking */
  19. void net_init (void);
  20. /* Set socket blocking/nonblocking */
  21. int soblock (int socket, int blocking);
  22. /* Like send(2), recv(2), connect(2), but with timeouts.
  23. Socket must be O_NONBLOCK. */
  24. int connect_timeout (int s, const struct sockaddr *serv_addr,
  25. socklen_t addrlen, struct timeval *timeout);
  26. ssize_t send_timeout (int s, const void *buf, size_t len, int flags,
  27. struct timeval *timeout);
  28. ssize_t recv_timeout (int s, void *buf, size_t len, int flags,
  29. struct timeval *timeout);
  30. ssize_t recvfrom_timeout (int s, void *buf, size_t len, int flags,
  31. struct sockaddr *address, socklen_t * address_len,
  32. struct timeval *timeout);
  33. /* Like send_timeout and recv_timeout, but they retry (with the same timeout)
  34. in case of partial transfers, in order to try to transfer all data. */
  35. ssize_t send_all_timeout (int s, const void *buf, size_t len, int flags,
  36. struct timeval *timeout);
  37. ssize_t recv_all_timeout (int s, void *buf, size_t len, int flags,
  38. struct timeval *timeout);
  39. #endif