comparison src/os/unix/ngx_channel.c @ 665:0b460e61bdcd default tip

Merge with nginx 1.0.0.
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 25 Apr 2011 04:22:17 +0400
parents 53f5f04a64b8
children
comparison
equal deleted inserted replaced
572:06419a2298a9 665:0b460e61bdcd
34 msg.msg_controllen = sizeof(cmsg); 34 msg.msg_controllen = sizeof(cmsg);
35 35
36 cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int)); 36 cmsg.cm.cmsg_len = CMSG_LEN(sizeof(int));
37 cmsg.cm.cmsg_level = SOL_SOCKET; 37 cmsg.cm.cmsg_level = SOL_SOCKET;
38 cmsg.cm.cmsg_type = SCM_RIGHTS; 38 cmsg.cm.cmsg_type = SCM_RIGHTS;
39 *(int *) CMSG_DATA(&cmsg.cm) = ch->fd; 39
40 /*
41 * We have to use ngx_memcpy() instead of simple
42 * *(int *) CMSG_DATA(&cmsg.cm) = ch->fd;
43 * because some gcc 4.4 with -O2/3/s optimization issues the warning:
44 * dereferencing type-punned pointer will break strict-aliasing rules
45 *
46 * Fortunately, gcc with -O1 compiles this ngx_memcpy()
47 * in the same simple assignment as in the code above
48 */
49
50 ngx_memcpy(CMSG_DATA(&cmsg.cm), &ch->fd, sizeof(int));
40 } 51 }
41 52
42 msg.msg_flags = 0; 53 msg.msg_flags = 0;
43 54
44 #else 55 #else
151 "level %d or type %d", 162 "level %d or type %d",
152 cmsg.cm.cmsg_level, cmsg.cm.cmsg_type); 163 cmsg.cm.cmsg_level, cmsg.cm.cmsg_type);
153 return NGX_ERROR; 164 return NGX_ERROR;
154 } 165 }
155 166
156 ch->fd = *(int *) CMSG_DATA(&cmsg.cm); 167 /* ch->fd = *(int *) CMSG_DATA(&cmsg.cm); */
168
169 ngx_memcpy(&ch->fd, CMSG_DATA(&cmsg.cm), sizeof(int));
157 } 170 }
158 171
159 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) { 172 if (msg.msg_flags & (MSG_TRUNC|MSG_CTRUNC)) {
160 ngx_log_error(NGX_LOG_ALERT, log, 0, 173 ngx_log_error(NGX_LOG_ALERT, log, 0,
161 "recvmsg() truncated data"); 174 "recvmsg() truncated data");