Mercurial > hg > nginx-mail
comparison src/os/unix/ngx_socket.c @ 0:f0b350454894 NGINX_0_1_0
nginx 0.1.0
*) The first public version.
author | Igor Sysoev <http://sysoev.ru> |
---|---|
date | Mon, 04 Oct 2004 00:00:00 +0400 |
parents | |
children | cc9f381affaa |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0b350454894 |
---|---|
1 | |
2 /* | |
3 * Copyright (C) Igor Sysoev | |
4 */ | |
5 | |
6 | |
7 #include <ngx_config.h> | |
8 #include <ngx_core.h> | |
9 | |
10 | |
11 /* | |
12 * ioctl(FIONBIO) sets a blocking mode with the single syscall | |
13 * while fcntl(F_SETFL, ~O_NONBLOCK) needs to learn before | |
14 * the previous state using fcntl(F_GETFL). | |
15 * | |
16 * ioctl() and fcntl() are syscalls on at least FreeBSD 2.x, Linux 2.2 | |
17 * and Solaris 7. | |
18 * | |
19 * ioctl() in Linux 2.4 and 2.6 uses BKL, however fcntl(F_SETFL) uses it too. | |
20 */ | |
21 | |
22 | |
23 #if (HAVE_FIONBIO) | |
24 | |
25 int ngx_nonblocking(ngx_socket_t s) | |
26 { | |
27 u_long nb; | |
28 | |
29 nb = 1; | |
30 | |
31 return ioctl(s, FIONBIO, &nb); | |
32 } | |
33 | |
34 | |
35 int ngx_blocking(ngx_socket_t s) | |
36 { | |
37 u_long nb; | |
38 | |
39 nb = 0; | |
40 | |
41 return ioctl(s, FIONBIO, &nb); | |
42 } | |
43 | |
44 #endif | |
45 | |
46 | |
47 #ifdef __FreeBSD__ | |
48 | |
49 int ngx_tcp_nopush(ngx_socket_t s) | |
50 { | |
51 int tcp_nopush; | |
52 | |
53 tcp_nopush = 1; | |
54 | |
55 return setsockopt(s, IPPROTO_TCP, TCP_NOPUSH, | |
56 (const void *) &tcp_nopush, sizeof(int)); | |
57 } | |
58 | |
59 | |
60 int ngx_tcp_push(ngx_socket_t s) | |
61 { | |
62 int tcp_nopush; | |
63 | |
64 tcp_nopush = 0; | |
65 | |
66 return setsockopt(s, IPPROTO_TCP, TCP_NOPUSH, | |
67 (const void *) &tcp_nopush, sizeof(int)); | |
68 } | |
69 | |
70 #elif __linux__ | |
71 | |
72 int ngx_tcp_nopush(ngx_socket_t s) | |
73 { | |
74 int cork; | |
75 | |
76 cork = 1; | |
77 | |
78 return setsockopt(s, IPPROTO_TCP, TCP_CORK, | |
79 (const void *) &cork, sizeof(int)); | |
80 } | |
81 | |
82 int ngx_tcp_push(ngx_socket_t s) | |
83 { | |
84 int cork; | |
85 | |
86 cork = 0; | |
87 | |
88 return setsockopt(s, IPPROTO_TCP, TCP_CORK, | |
89 (const void *) &cork, sizeof(int)); | |
90 } | |
91 | |
92 #else | |
93 | |
94 int ngx_tcp_nopush(ngx_socket_t s) | |
95 { | |
96 return NGX_OK; | |
97 } | |
98 | |
99 int ngx_tcp_push(ngx_socket_t s) | |
100 { | |
101 return NGX_OK; | |
102 } | |
103 | |
104 #endif |