src/os/unix/ngx_socket.c - nginx-1.7.10

Functions defined

Source code


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


  5. #include <ngx_config.h>
  6. #include <ngx_core.h>


  7. /*
  8. * ioctl(FIONBIO) sets a non-blocking mode with the single syscall
  9. * while fcntl(F_SETFL, O_NONBLOCK) needs to learn the current state
  10. * using fcntl(F_GETFL).
  11. *
  12. * ioctl() and fcntl() are syscalls at least in FreeBSD 2.x, Linux 2.2
  13. * and Solaris 7.
  14. *
  15. * ioctl() in Linux 2.4 and 2.6 uses BKL, however, fcntl(F_SETFL) uses it too.
  16. */


  17. #if (NGX_HAVE_FIONBIO)

  18. int
  19. ngx_nonblocking(ngx_socket_t s)
  20. {
  21.     int  nb;

  22.     nb = 1;

  23.     return ioctl(s, FIONBIO, &nb);
  24. }


  25. int
  26. ngx_blocking(ngx_socket_t s)
  27. {
  28.     int  nb;

  29.     nb = 0;

  30.     return ioctl(s, FIONBIO, &nb);
  31. }

  32. #endif


  33. #if (NGX_FREEBSD)

  34. int
  35. ngx_tcp_nopush(ngx_socket_t s)
  36. {
  37.     int  tcp_nopush;

  38.     tcp_nopush = 1;

  39.     return setsockopt(s, IPPROTO_TCP, TCP_NOPUSH,
  40.                       (const void *) &tcp_nopush, sizeof(int));
  41. }


  42. int
  43. ngx_tcp_push(ngx_socket_t s)
  44. {
  45.     int  tcp_nopush;

  46.     tcp_nopush = 0;

  47.     return setsockopt(s, IPPROTO_TCP, TCP_NOPUSH,
  48.                       (const void *) &tcp_nopush, sizeof(int));
  49. }

  50. #elif (NGX_LINUX)


  51. int
  52. ngx_tcp_nopush(ngx_socket_t s)
  53. {
  54.     int  cork;

  55.     cork = 1;

  56.     return setsockopt(s, IPPROTO_TCP, TCP_CORK,
  57.                       (const void *) &cork, sizeof(int));
  58. }


  59. int
  60. ngx_tcp_push(ngx_socket_t s)
  61. {
  62.     int  cork;

  63.     cork = 0;

  64.     return setsockopt(s, IPPROTO_TCP, TCP_CORK,
  65.                       (const void *) &cork, sizeof(int));
  66. }

  67. #else

  68. int
  69. ngx_tcp_nopush(ngx_socket_t s)
  70. {
  71.     return 0;
  72. }


  73. int
  74. ngx_tcp_push(ngx_socket_t s)
  75. {
  76.     return 0;
  77. }

  78. #endif