Win32: MinGW GCC compatibility.
Several warnings silenced, notably (ngx_socket_t) -1 is now checked
on socket operations instead of -1, as ngx_socket_t is unsigned on win32
and gcc complains on comparison.
With this patch, it's now possible to compile nginx using mingw gcc,
with options we normally compile on win32.
Maxim Dounin
8 years ago
32 | 32 |
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
|
33 | 33 |
CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
|
34 | 34 |
CORE_LIBS="$CORE_LIBS $NGX_LIBDL"
|
|
35 |
|
|
36 |
if [ "$NGX_PLATFORM" = win32 ]; then
|
|
37 |
CORE_LIBS="$CORE_LIBS -lgdi32 -lcrypt32 -lws2_32"
|
|
38 |
fi
|
35 | 39 |
;;
|
36 | 40 |
esac
|
37 | 41 |
|
72 | 72 |
|
73 | 73 |
*)
|
74 | 74 |
have=NGX_PCRE . auto/have
|
|
75 |
|
|
76 |
if [ "$NGX_PLATFORM" = win32 ]; then
|
|
77 |
have=PCRE_STATIC . auto/have
|
|
78 |
fi
|
|
79 |
|
75 | 80 |
CORE_DEPS="$CORE_DEPS $PCRE/pcre.h"
|
76 | 81 |
LINK_DEPS="$LINK_DEPS $PCRE/.libs/libpcre.a"
|
77 | 82 |
CORE_LIBS="$CORE_LIBS $PCRE/.libs/libpcre.a"
|
23 | 23 |
ngx_zlib=`echo \-DZLIB=\"$ZLIB\" | sed -e "s/\//$ngx_regex_dirsep/g"`
|
24 | 24 |
;;
|
25 | 25 |
|
|
26 |
*)
|
|
27 |
ngx_makefile=
|
|
28 |
;;
|
|
29 |
|
26 | 30 |
esac
|
27 | 31 |
|
28 | 32 |
|
|
32 | 36 |
case "$NGX_PLATFORM" in
|
33 | 37 |
|
34 | 38 |
win32)
|
35 | |
cat << END >> $NGX_MAKEFILE
|
|
39 |
|
|
40 |
if [ -n "$ngx_makefile" ]; then
|
|
41 |
cat << END >> $NGX_MAKEFILE
|
36 | 42 |
|
37 | 43 |
`echo "$ZLIB/zlib.lib: $NGX_MAKEFILE" | sed -e "s/\//$ngx_regex_dirsep/g"`
|
38 | 44 |
\$(MAKE) -f auto/lib/zlib/$ngx_makefile $ngx_opt $ngx_zlib
|
39 | 45 |
|
40 | 46 |
END
|
|
47 |
|
|
48 |
else
|
|
49 |
|
|
50 |
cat << END >> $NGX_MAKEFILE
|
|
51 |
|
|
52 |
$ZLIB/libz.a: $NGX_MAKEFILE
|
|
53 |
cd $ZLIB \\
|
|
54 |
&& \$(MAKE) distclean \\
|
|
55 |
&& \$(MAKE) -f win32/Makefile.gcc \\
|
|
56 |
CFLAGS="$ZLIB_OPT" CC="\$(CC)" \\
|
|
57 |
libz.a
|
|
58 |
|
|
59 |
END
|
|
60 |
|
|
61 |
fi
|
41 | 62 |
|
42 | 63 |
done=YES
|
43 | 64 |
;;
|
8 | 8 |
CORE_DEPS="$WIN32_DEPS"
|
9 | 9 |
CORE_SRCS="$WIN32_SRCS $IOCP_SRCS"
|
10 | 10 |
OS_CONFIG="$WIN32_CONFIG"
|
11 | |
CORE_LIBS="$CORE_LIBS advapi32.lib ws2_32.lib"
|
12 | 11 |
NGX_ICONS="$NGX_WIN32_ICONS"
|
13 | 12 |
SELECT_SRCS=$WIN32_SELECT_SRCS
|
|
13 |
|
|
14 |
case "$NGX_CC_NAME" in
|
|
15 |
|
|
16 |
gcc)
|
|
17 |
CORE_LIBS="$CORE_LIBS -ladvapi32 -lws2_32"
|
|
18 |
;;
|
|
19 |
|
|
20 |
*)
|
|
21 |
CORE_LIBS="$CORE_LIBS advapi32.lib ws2_32.lib"
|
|
22 |
;;
|
|
23 |
|
|
24 |
esac
|
14 | 25 |
|
15 | 26 |
EVENT_MODULES="$EVENT_MODULES $IOCP_MODULE"
|
16 | 27 |
EVENT_FOUND=YES
|
296 | 296 |
continue;
|
297 | 297 |
}
|
298 | 298 |
|
299 | |
if (ls[i].fd != -1) {
|
|
299 |
if (ls[i].fd != (ngx_socket_t) -1) {
|
300 | 300 |
continue;
|
301 | 301 |
}
|
302 | 302 |
|
|
311 | 311 |
|
312 | 312 |
s = ngx_socket(ls[i].sockaddr->sa_family, ls[i].type, 0);
|
313 | 313 |
|
314 | |
if (s == -1) {
|
|
314 |
if (s == (ngx_socket_t) -1) {
|
315 | 315 |
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
316 | 316 |
ngx_socket_n " %V failed", &ls[i].addr_text);
|
317 | 317 |
return NGX_ERROR;
|
|
862 | 862 |
ngx_uint_t log_error, level;
|
863 | 863 |
ngx_socket_t fd;
|
864 | 864 |
|
865 | |
if (c->fd == -1) {
|
|
865 |
if (c->fd == (ngx_socket_t) -1) {
|
866 | 866 |
ngx_log_error(NGX_LOG_ALERT, c->log, 0, "connection already closed");
|
867 | 867 |
return;
|
868 | 868 |
}
|
147 | 147 |
return NGX_ERROR;
|
148 | 148 |
}
|
149 | 149 |
|
150 | |
if ((event == NGX_READ_EVENT) && (max_read >= FD_SETSIZE)
|
151 | |
|| (event == NGX_WRITE_EVENT) && (max_write >= FD_SETSIZE))
|
|
150 |
if ((event == NGX_READ_EVENT && max_read >= FD_SETSIZE)
|
|
151 |
|| (event == NGX_WRITE_EVENT && max_write >= FD_SETSIZE))
|
152 | 152 |
{
|
153 | 153 |
ngx_log_error(NGX_LOG_ERR, ev->log, 0,
|
154 | 154 |
"maximum number of descriptors "
|
69 | 69 |
s = accept(lc->fd, (struct sockaddr *) sa, &socklen);
|
70 | 70 |
#endif
|
71 | 71 |
|
72 | |
if (s == -1) {
|
|
72 |
if (s == (ngx_socket_t) -1) {
|
73 | 73 |
err = ngx_socket_errno;
|
74 | 74 |
|
75 | 75 |
if (err == NGX_EAGAIN) {
|
107 | 107 |
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, &ls->log, 0,
|
108 | 108 |
ngx_socket_n " s:%d", s);
|
109 | 109 |
|
110 | |
if (s == -1) {
|
|
110 |
if (s == (ngx_socket_t) -1) {
|
111 | 111 |
ngx_log_error(NGX_LOG_ALERT, &ls->log, ngx_socket_errno,
|
112 | 112 |
ngx_socket_n " failed");
|
113 | 113 |
|
30 | 30 |
|
31 | 31 |
ngx_log_debug1(NGX_LOG_DEBUG_EVENT, pc->log, 0, "socket %d", s);
|
32 | 32 |
|
33 | |
if (s == -1) {
|
|
33 |
if (s == (ngx_socket_t) -1) {
|
34 | 34 |
ngx_log_error(NGX_LOG_ALERT, pc->log, ngx_socket_errno,
|
35 | 35 |
ngx_socket_n " failed");
|
36 | 36 |
return NGX_ERROR;
|
56 | 56 |
do_write = 1;
|
57 | 57 |
}
|
58 | 58 |
|
59 | |
if (p->upstream->fd != -1) {
|
|
59 |
if (p->upstream->fd != (ngx_socket_t) -1) {
|
60 | 60 |
rev = p->upstream->read;
|
61 | 61 |
|
62 | 62 |
flags = (rev->eof || rev->error) ? NGX_CLOSE_EVENT : 0;
|
|
73 | 73 |
}
|
74 | 74 |
}
|
75 | 75 |
|
76 | |
if (p->downstream->fd != -1 && p->downstream->data == p->output_ctx) {
|
|
76 |
if (p->downstream->fd != (ngx_socket_t) -1
|
|
77 |
&& p->downstream->data == p->output_ctx)
|
|
78 |
{
|
77 | 79 |
wev = p->downstream->write;
|
78 | 80 |
if (ngx_handle_write_event(wev, p->send_lowat) != NGX_OK) {
|
79 | 81 |
return NGX_ABORT;
|
20 | 20 |
#define NGX_ATOMIC_T_LEN (sizeof("-2147483648") - 1)
|
21 | 21 |
|
22 | 22 |
|
23 | |
#if defined( __WATCOMC__ ) || defined( __BORLANDC__ ) || ( _MSC_VER >= 1300 )
|
|
23 |
#if defined( __WATCOMC__ ) || defined( __BORLANDC__ ) || defined(__GNUC__) \
|
|
24 |
|| ( _MSC_VER >= 1300 )
|
24 | 25 |
|
25 | 26 |
/* the new SDK headers */
|
26 | 27 |
|
814 | 814 |
|
815 | 815 |
/* THREAD: lock */
|
816 | 816 |
|
817 | |
if (c[i].fd != -1 && c[i].idle) {
|
|
817 |
if (c[i].fd != (ngx_socket_t) -1 && c[i].idle) {
|
818 | 818 |
c[i].close = 1;
|
819 | 819 |
c[i].read->handler(c[i].read);
|
820 | 820 |
}
|
|
873 | 873 |
if (ngx_exiting) {
|
874 | 874 |
c = cycle->connections;
|
875 | 875 |
for (i = 0; i < cycle->connection_n; i++) {
|
876 | |
if (c[i].fd != -1
|
|
876 |
if (c[i].fd != (ngx_socket_t) -1
|
877 | 877 |
&& c[i].read
|
878 | 878 |
&& !c[i].read->accept
|
879 | 879 |
&& !c[i].read->channel
|
8 | 8 |
#define _NGX_WIN32_CONFIG_H_INCLUDED_
|
9 | 9 |
|
10 | 10 |
|
|
11 |
#undef WIN32
|
11 | 12 |
#define WIN32 0x0400
|
12 | 13 |
#define _WIN32_WINNT 0x0501
|
13 | 14 |
|
|
34 | 35 |
#include <mswsock.h>
|
35 | 36 |
#include <shellapi.h>
|
36 | 37 |
#include <stddef.h> /* offsetof() */
|
|
38 |
|
|
39 |
#ifdef __GNUC__
|
|
40 |
/* GCC MinGW's stdio.h includes sys/types.h */
|
|
41 |
#define _OFF_T_
|
|
42 |
#endif
|
|
43 |
|
37 | 44 |
#include <stdio.h>
|
38 | 45 |
#include <stdlib.h>
|
39 | 46 |
#include <stdarg.h>
|
140 | 140 |
*/
|
141 | 141 |
|
142 | 142 |
s = ngx_socket(AF_INET, SOCK_STREAM, IPPROTO_IP);
|
143 | |
if (s == -1) {
|
|
143 |
if (s == (ngx_socket_t) -1) {
|
144 | 144 |
ngx_log_error(NGX_LOG_EMERG, log, ngx_socket_errno,
|
145 | 145 |
ngx_socket_n " falied");
|
146 | 146 |
return NGX_ERROR;
|
16 | 16 |
u_long bytes, flags;
|
17 | 17 |
WSABUF wsabuf[1];
|
18 | 18 |
ngx_err_t err;
|
19 | |
ngx_uint_t n;
|
|
19 |
ngx_int_t n;
|
20 | 20 |
ngx_event_t *rev;
|
21 | 21 |
|
22 | 22 |
wsabuf[0].buf = (char *) buf;
|
|
69 | 69 |
u_long bytes, flags;
|
70 | 70 |
WSABUF wsabuf[1];
|
71 | 71 |
ngx_err_t err;
|
72 | |
ngx_uint_t n;
|
|
72 |
ngx_int_t n;
|
73 | 73 |
ngx_event_t *rev;
|
74 | 74 |
LPWSAOVERLAPPED ovlp;
|
75 | 75 |
|