annotate src/os/unix/ngx_channel.c @ 3682:e76fbd1a49f3

fix typo
author Igor Sysoev <igor@sysoev.ru>
date Thu, 08 Jul 2010 14:02:09 +0000
parents 2c5e269d0608
children d620f497c50f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 391
diff changeset
1
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 391
diff changeset
2 /*
444
42d11f017717 nginx-0.1.0-2004-09-29-20:00:49 import; remove years from copyright
Igor Sysoev <igor@sysoev.ru>
parents: 441
diff changeset
3 * Copyright (C) Igor Sysoev
441
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 391
diff changeset
4 */
da8c5707af39 nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents: 391
diff changeset
5
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
6
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
7 #include <ngx_config.h>
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
8 #include <ngx_core.h>
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
9 #include <ngx_channel.h>
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
10
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
11
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
12 ngx_int_t
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
13 ngx_write_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size,
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
14 ngx_log_t *log)
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
15 {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
16 ssize_t n;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
17 ngx_err_t err;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
18 struct iovec iov[1];
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
19 struct msghdr msg;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
20
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 465
diff changeset
21 #if (NGX_HAVE_MSGHDR_MSG_CONTROL)
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
22
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
23 union {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
24 struct cmsghdr cm;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
25 char space[CMSG_SPACE(sizeof(int))];
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
26 } cmsg;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
27
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
28 if (ch->fd == -1) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
29 msg.msg_control = NULL;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
30 msg.msg_controllen = 0;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
31
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
32 } else {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
33 msg.msg_control = (caddr_t) &cmsg;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
34 msg.msg_controllen = sizeof(cmsg);
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
35
1901
d880fa02fb65 use CMSG_LEN(), this fixes an alert "sendmsg() failed (9: Bad file descriptor)"
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
36 cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int));
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
37 cmsg.cm.cmsg_level = SOL_SOCKET;
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
38 cmsg.cm.cmsg_type = SCM_RIGHTS;
3396
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
39
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
40 /*
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
41 * We have to use ngx_memcpy() instead of simple
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
42 * *(int *) CMSG_DATA(&cmsg.cm) = ch->fd;
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
43 * because some gcc 4.4 with -O2/3/s optimization issues the warning:
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
44 * dereferencing type-punned pointer will break strict-aliasing rules
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
45 *
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
46 * Fortunately, gcc with -O1 compiles this ngx_memcpy()
3682
e76fbd1a49f3 fix typo
Igor Sysoev <igor@sysoev.ru>
parents: 3396
diff changeset
47 * in the same simple assignment as in the code above
3396
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
48 */
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
49
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
50 ngx_memcpy(CMSG_DATA(&cmsg.cm), &ch->fd, sizeof(int));
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
51 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
52
483
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
53 msg.msg_flags = 0;
621229427cba nginx-0.1.16-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 481
diff changeset
54
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
55 #else
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
56
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
57 if (ch->fd == -1) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
58 msg.msg_accrights = NULL;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
59 msg.msg_accrightslen = 0;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
60
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
61 } else {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
62 msg.msg_accrights = (caddr_t) &ch->fd;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
63 msg.msg_accrightslen = sizeof(int);
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
64 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
65
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
66 #endif
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
67
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
68 iov[0].iov_base = (char *) ch;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
69 iov[0].iov_len = size;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
70
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
71 msg.msg_name = NULL;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
72 msg.msg_namelen = 0;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
73 msg.msg_iov = iov;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
74 msg.msg_iovlen = 1;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
75
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
76 n = sendmsg(s, &msg, 0);
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
77
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
78 if (n == -1) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
79 err = ngx_errno;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
80 if (err == NGX_EAGAIN) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
81 return NGX_AGAIN;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
82 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
83
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
84 ngx_log_error(NGX_LOG_ALERT, log, err, "sendmsg() failed");
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
85 return NGX_ERROR;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
86 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
87
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
88 return NGX_OK;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
89 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
90
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
91
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
92 ngx_int_t
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
93 ngx_read_channel(ngx_socket_t s, ngx_channel_t *ch, size_t size, ngx_log_t *log)
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
94 {
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
95 ssize_t n;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
96 ngx_err_t err;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
97 struct iovec iov[1];
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
98 struct msghdr msg;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
99
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 465
diff changeset
100 #if (NGX_HAVE_MSGHDR_MSG_CONTROL)
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
101 union {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
102 struct cmsghdr cm;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
103 char space[CMSG_SPACE(sizeof(int))];
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
104 } cmsg;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
105 #else
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
106 int fd;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
107 #endif
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
108
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
109 iov[0].iov_base = (char *) ch;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
110 iov[0].iov_len = size;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
111
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
112 msg.msg_name = NULL;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
113 msg.msg_namelen = 0;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
114 msg.msg_iov = iov;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
115 msg.msg_iovlen = 1;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
116
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 465
diff changeset
117 #if (NGX_HAVE_MSGHDR_MSG_CONTROL)
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
118 msg.msg_control = (caddr_t) &cmsg;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
119 msg.msg_controllen = sizeof(cmsg);
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
120 #else
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
121 msg.msg_accrights = (caddr_t) &fd;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
122 msg.msg_accrightslen = sizeof(int);
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
123 #endif
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
124
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
125 n = recvmsg(s, &msg, 0);
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
126
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
127 if (n == -1) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
128 err = ngx_errno;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
129 if (err == NGX_EAGAIN) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
130 return NGX_AGAIN;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
131 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
132
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
133 ngx_log_error(NGX_LOG_ALERT, log, err, "recvmsg() failed");
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
134 return NGX_ERROR;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
135 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
136
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
137 if (n == 0) {
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
138 ngx_log_debug0(NGX_LOG_DEBUG_CORE, log, 0, "recvmsg() returned zero");
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
139 return NGX_ERROR;
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
140 }
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
141
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
142 if ((size_t) n < sizeof(ngx_channel_t)) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
143 ngx_log_error(NGX_LOG_ALERT, log, 0,
461
a88a3e4e158f nginx-0.1.5-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 444
diff changeset
144 "recvmsg() returned not enough data: %uz", n);
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
145 return NGX_ERROR;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
146 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
147
469
2ff194b74f1e nginx-0.1.9-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 465
diff changeset
148 #if (NGX_HAVE_MSGHDR_MSG_CONTROL)
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
149
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
150 if (ch->command == NGX_CMD_OPEN_CHANNEL) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
151
1901
d880fa02fb65 use CMSG_LEN(), this fixes an alert "sendmsg() failed (9: Bad file descriptor)"
Igor Sysoev <igor@sysoev.ru>
parents: 577
diff changeset
152 if (cmsg.cm.cmsg_len < (socklen_t) CMSG_LEN(sizeof(int))) {
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
153 ngx_log_error(NGX_LOG_ALERT, log, 0,
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
154 "recvmsg() returned too small ancillary data");
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
155 return NGX_ERROR;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
156 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
157
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
158 if (cmsg.cm.cmsg_level != SOL_SOCKET || cmsg.cm.cmsg_type != SCM_RIGHTS)
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
159 {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
160 ngx_log_error(NGX_LOG_ALERT, log, 0,
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
161 "recvmsg() returned invalid ancillary data "
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
162 "level %d or type %d",
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
163 cmsg.cm.cmsg_level, cmsg.cm.cmsg_type);
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
164 return NGX_ERROR;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
165 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
166
3396
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
167 /* ch->fd = *(int *) CMSG_DATA(&cmsg.cm); */
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
168
2c5e269d0608 fix building by gcc 4.x with -O2/3/s in some Linux distributions:
Igor Sysoev <igor@sysoev.ru>
parents: 1901
diff changeset
169 ngx_memcpy(&ch->fd, CMSG_DATA(&cmsg.cm), sizeof(int));
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
170 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
171
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
172 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
173 ngx_log_error(NGX_LOG_ALERT, log, 0,
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
174 "recvmsg() truncated data");
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
175 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
176
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
177 #else
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
178
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
179 if (ch->command == NGX_CMD_OPEN_CHANNEL) {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
180 if (msg.msg_accrightslen != sizeof(int)) {
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
181 ngx_log_error(NGX_LOG_ALERT, log, 0,
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
182 "recvmsg() returned no ancillary data");
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
183 return NGX_ERROR;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
184 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
185
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
186 ch->fd = fd;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
187 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
188
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
189 #endif
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
190
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
191 return n;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
192 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
193
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
194
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
195 ngx_int_t
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
196 ngx_add_channel_event(ngx_cycle_t *cycle, ngx_fd_t fd, ngx_int_t event,
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
197 ngx_event_handler_pt handler)
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
198 {
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
199 ngx_event_t *ev, *rev, *wev;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
200 ngx_connection_t *c;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
201
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
202 c = ngx_get_connection(fd, cycle->log);
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
203
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
204 if (c == NULL) {
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
205 return NGX_ERROR;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
206 }
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
207
561
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
208 c->pool = cycle->pool;
e48ebafc6939 nginx-0.3.2-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 543
diff changeset
209
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
210 rev = c->read;
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
211 wev = c->write;
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
212
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
213 rev->log = cycle->log;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
214 wev->log = cycle->log;
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
215
381
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 366
diff changeset
216 #if (NGX_THREADS)
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 366
diff changeset
217 rev->lock = &c->lock;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 366
diff changeset
218 wev->lock = &c->lock;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 366
diff changeset
219 rev->own_lock = &c->lock;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 366
diff changeset
220 wev->own_lock = &c->lock;
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 366
diff changeset
221 #endif
02a511569afb nginx-0.0.7-2004-07-07-19:01:00 import
Igor Sysoev <igor@sysoev.ru>
parents: 366
diff changeset
222
563
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
223 rev->channel = 1;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
224 wev->channel = 1;
9c2f3ed7a247 nginx-0.3.3-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 561
diff changeset
225
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
226 ev = (event == NGX_READ_EVENT) ? rev : wev;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
227
509
9b8c906f6e63 nginx-0.1.29-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 483
diff changeset
228 ev->handler = handler;
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
229
391
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
230 if (ngx_add_conn && (ngx_event_flags & NGX_USE_EPOLL_EVENT) == 0) {
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
231 if (ngx_add_conn(c) == NGX_ERROR) {
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
232 ngx_free_connection(c);
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
233 return NGX_ERROR;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
234 }
577
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
235
4d9ea73a627a nginx-0.3.10-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 563
diff changeset
236 } else {
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
237 if (ngx_add_event(ev, event, 0) == NGX_ERROR) {
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
238 ngx_free_connection(c);
366
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
239 return NGX_ERROR;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
240 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
241 }
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
242
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
243 return NGX_OK;
e411b1482ee3 nginx-0.0.7-2004-06-23-19:18:17 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff changeset
244 }
391
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
245
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
246
543
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
247 void
511a89da35ad nginx-0.2.0-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 509
diff changeset
248 ngx_close_channel(ngx_fd_t *fd, ngx_log_t *log)
391
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
249 {
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
250 if (close(fd[0]) == -1) {
465
5aecc125bc33 nginx-0.1.7-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 461
diff changeset
251 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() channel failed");
391
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
252 }
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
253
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
254 if (close(fd[1]) == -1) {
465
5aecc125bc33 nginx-0.1.7-RELEASE import
Igor Sysoev <igor@sysoev.ru>
parents: 461
diff changeset
255 ngx_log_error(NGX_LOG_ALERT, log, ngx_errno, "close() channel failed");
391
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
256 }
b670db10cbbd nginx-0.0.7-2004-07-14-20:01:42 import
Igor Sysoev <igor@sysoev.ru>
parents: 381
diff changeset
257 }