src/os/unix/ngx_socket.h - nginx source code

Data types defined

Macros defined

Source code


  1. /*
  2. * Copyright (C) Igor Sysoev
  3. * Copyright (C) Nginx, Inc.
  4. */


  5. #ifndef _NGX_SOCKET_H_INCLUDED_
  6. #define _NGX_SOCKET_H_INCLUDED_


  7. #include <ngx_config.h>


  8. #define NGX_WRITE_SHUTDOWN SHUT_WR
  9. #define NGX_READ_SHUTDOWN  SHUT_RD
  10. #define NGX_RDWR_SHUTDOWN  SHUT_RDWR

  11. typedef int  ngx_socket_t;

  12. #define ngx_socket          socket
  13. #define ngx_socket_n        "socket()"


  14. #if (NGX_HAVE_FIONBIO)

  15. int ngx_nonblocking(ngx_socket_t s);
  16. int ngx_blocking(ngx_socket_t s);

  17. #define ngx_nonblocking_n   "ioctl(FIONBIO)"
  18. #define ngx_blocking_n      "ioctl(!FIONBIO)"

  19. #else

  20. #define ngx_nonblocking(s)  fcntl(s, F_SETFL, fcntl(s, F_GETFL) | O_NONBLOCK)
  21. #define ngx_nonblocking_n   "fcntl(O_NONBLOCK)"

  22. #define ngx_blocking(s)     fcntl(s, F_SETFL, fcntl(s, F_GETFL) & ~O_NONBLOCK)
  23. #define ngx_blocking_n      "fcntl(!O_NONBLOCK)"

  24. #endif

  25. #if (NGX_HAVE_FIONREAD)

  26. #define ngx_socket_nread(s, n)  ioctl(s, FIONREAD, n)
  27. #define ngx_socket_nread_n      "ioctl(FIONREAD)"

  28. #endif

  29. int ngx_tcp_nopush(ngx_socket_t s);
  30. int ngx_tcp_push(ngx_socket_t s);

  31. #if (NGX_LINUX)

  32. #define ngx_tcp_nopush_n   "setsockopt(TCP_CORK)"
  33. #define ngx_tcp_push_n     "setsockopt(!TCP_CORK)"

  34. #else

  35. #define ngx_tcp_nopush_n   "setsockopt(TCP_NOPUSH)"
  36. #define ngx_tcp_push_n     "setsockopt(!TCP_NOPUSH)"

  37. #endif


  38. #define ngx_shutdown_socket    shutdown
  39. #define ngx_shutdown_socket_n  "shutdown()"

  40. #define ngx_close_socket    close
  41. #define ngx_close_socket_n  "close() socket"


  42. #endif /* _NGX_SOCKET_H_INCLUDED_ */