Back to home page

Nginx displayed by LXR

Source navigation ]
Diff markup ]
Identifier search ]
general search ]
 
 
Version: nginx-1.15.11 ]​[ nginx-1.14.2 ]​

0001 
0002 /*
0003  * Copyright (C) Igor Sysoev
0004  * Copyright (C) Nginx, Inc.
0005  */
0006 
0007 
0008 #include <ngx_config.h>
0009 #include <ngx_core.h>
0010 
0011 
0012 /*
0013  * ioctl(FIONBIO) sets a non-blocking mode with the single syscall
0014  * while fcntl(F_SETFL, O_NONBLOCK) needs to learn the current state
0015  * using fcntl(F_GETFL).
0016  *
0017  * ioctl() and fcntl() are syscalls at least in FreeBSD 2.x, Linux 2.2
0018  * and Solaris 7.
0019  *
0020  * ioctl() in Linux 2.4 and 2.6 uses BKL, however, fcntl(F_SETFL) uses it too.
0021  */
0022 
0023 
0024 #if (NGX_HAVE_FIONBIO)
0025 
0026 int
0027 ngx_nonblocking(ngx_socket_t s)
0028 {
0029     int  nb;
0030 
0031     nb = 1;
0032 
0033     return ioctl(s, FIONBIO, &nb);
0034 }
0035 
0036 
0037 int
0038 ngx_blocking(ngx_socket_t s)
0039 {
0040     int  nb;
0041 
0042     nb = 0;
0043 
0044     return ioctl(s, FIONBIO, &nb);
0045 }
0046 
0047 #endif
0048 
0049 
0050 #if (NGX_FREEBSD)
0051 
0052 int
0053 ngx_tcp_nopush(ngx_socket_t s)
0054 {
0055     int  tcp_nopush;
0056 
0057     tcp_nopush = 1;
0058 
0059     return setsockopt(s, IPPROTO_TCP, TCP_NOPUSH,
0060                       (const void *) &tcp_nopush, sizeof(int));
0061 }
0062 
0063 
0064 int
0065 ngx_tcp_push(ngx_socket_t s)
0066 {
0067     int  tcp_nopush;
0068 
0069     tcp_nopush = 0;
0070 
0071     return setsockopt(s, IPPROTO_TCP, TCP_NOPUSH,
0072                       (const void *) &tcp_nopush, sizeof(int));
0073 }
0074 
0075 #elif (NGX_LINUX)
0076 
0077 
0078 int
0079 ngx_tcp_nopush(ngx_socket_t s)
0080 {
0081     int  cork;
0082 
0083     cork = 1;
0084 
0085     return setsockopt(s, IPPROTO_TCP, TCP_CORK,
0086                       (const void *) &cork, sizeof(int));
0087 }
0088 
0089 
0090 int
0091 ngx_tcp_push(ngx_socket_t s)
0092 {
0093     int  cork;
0094 
0095     cork = 0;
0096 
0097     return setsockopt(s, IPPROTO_TCP, TCP_CORK,
0098                       (const void *) &cork, sizeof(int));
0099 }
0100 
0101 #else
0102 
0103 int
0104 ngx_tcp_nopush(ngx_socket_t s)
0105 {
0106     return 0;
0107 }
0108 
0109 
0110 int
0111 ngx_tcp_push(ngx_socket_t s)
0112 {
0113     return 0;
0114 }
0115 
0116 #endif