Mercurial > hg > nginx
annotate src/os/win32/ngx_errno.c @ 2483:29494780d978
free addrs only it has been allocated before: non single address
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Thu, 29 Jan 2009 14:32:58 +0000 |
parents | 3d8ab5957202 |
children | 58399dcc410a |
rev | line source |
---|---|
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
1 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
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:
186
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:
186
diff
changeset
|
5 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
6 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
7 /* |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
8 * TODO: |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
9 * add WSA error messages for NT and 98 |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
10 * test for English only messages |
da8c5707af39
nginx-0.1.0-2004-09-28-12:34:51 import; set copyright and remove unused files
Igor Sysoev <igor@sysoev.ru>
parents:
186
diff
changeset
|
11 */ |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
12 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
13 #include <ngx_config.h> |
98
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
14 #include <ngx_core.h> |
c9b243802a17
nginx-0.0.1-2003-05-30-18:27:59 import
Igor Sysoev <igor@sysoev.ru>
parents:
0
diff
changeset
|
15 |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
16 |
186
c1f3a3c7c5db
nginx-0.0.1-2003-11-17-00:49:42 import
Igor Sysoev <igor@sysoev.ru>
parents:
107
diff
changeset
|
17 static ngx_str_t wsa_errors[] = { |
461 | 18 ngx_string("An invalid argument was supplied"), /* WSAEINVAL 10022 */ |
19 ngx_string("Too many open sockets"), /* WSAEMFILE 10023 */ | |
20 | |
21 ngx_null_string, /* 10024 */ | |
22 ngx_null_string, /* 10025 */ | |
23 ngx_null_string, /* 10026 */ | |
24 ngx_null_string, /* 10027 */ | |
25 ngx_null_string, /* 10028 */ | |
26 ngx_null_string, /* 10029 */ | |
27 ngx_null_string, /* 10030 */ | |
28 ngx_null_string, /* 10031 */ | |
29 ngx_null_string, /* 10032 */ | |
30 ngx_null_string, /* 10033 */ | |
31 ngx_null_string, /* 10034 */ | |
32 | |
33 /* WSAEWOULDBLOCK 10035 */ | |
34 ngx_string("A non-blocking socket operation could not be completed " | |
35 "immediately"), | |
36 | |
37 ngx_null_string, /* 10036 */ | |
38 ngx_null_string, /* 10037 */ | |
39 | |
40 /* WSAENOTSOCK 10038 */ | |
41 ngx_string("An operation was attempted on something that is not a socket"), | |
42 | |
43 ngx_null_string, /* 10039 */ | |
44 ngx_null_string, /* 10040 */ | |
45 ngx_null_string, /* 10041 */ | |
473 | 46 |
47 /* WSAENOPROTOOPT 10042 */ | |
48 ngx_string("An unknown, invalid, or unsupported option or level was " | |
49 "specified in a getsockopt or setsockopt call"), | |
50 | |
461 | 51 ngx_null_string, /* 10043 */ |
52 ngx_null_string, /* 10044 */ | |
53 ngx_null_string, /* 10045 */ | |
54 ngx_null_string, /* 10046 */ | |
55 ngx_null_string, /* 10047 */ | |
56 ngx_null_string, /* 10048 */ | |
57 ngx_null_string, /* 10049 */ | |
58 ngx_null_string, /* 10050 */ | |
59 ngx_null_string, /* 10051 */ | |
60 ngx_null_string, /* 10052 */ | |
61 ngx_null_string, /* 10053 */ | |
62 | |
63 /* WSAECONNRESET 10054 */ | |
64 ngx_string("An existing connection was forcibly closed by the remote host"), | |
65 | |
66 /* WSAENOBUFS 10055 */ | |
67 ngx_string("An operation on a socket could not be performed because " | |
68 "the system lacked sufficient buffer space or " | |
69 "because a queue was full"), | |
70 | |
71 /* WSAEISCONN 10056 */ | |
72 ngx_string("A connect request was made on an already connected socket"), | |
73 | |
74 /* WSAENOTCONN 10057 */ | |
75 ngx_string("A request to send or receive data was disallowed because" | |
76 "the socket is not connected and (when sending on a datagram " | |
77 "socket using a sendto call) no address was supplied"), | |
78 | |
79 ngx_null_string, /* 10058 */ | |
80 ngx_null_string, /* 10059 */ | |
81 | |
82 /* WSAETIMEDOUT 10060 */ | |
83 ngx_string("A connection attempt failed because the connected party " | |
84 "did not properly respond after a period of time, " | |
85 "or established connection failed because connected host " | |
86 "has failed to respond"), | |
87 | |
88 /* WSAECONNREFUSED 10061 */ | |
89 ngx_string("No connection could be made because the target machine " | |
90 "actively refused it") | |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
91 }; |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
92 |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
93 |
2335
3d8ab5957202
ngx_strerror_r() style and size == 0 bug fix
Igor Sysoev <igor@sysoev.ru>
parents:
473
diff
changeset
|
94 u_char * |
3d8ab5957202
ngx_strerror_r() style and size == 0 bug fix
Igor Sysoev <igor@sysoev.ru>
parents:
473
diff
changeset
|
95 ngx_strerror_r(ngx_err_t err, u_char *errstr, size_t size) |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
96 { |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
97 int n; |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
98 u_int len; |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
99 ngx_err_t format_error; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
100 |
461 | 101 if (size == 0) { |
102 return errstr; | |
103 } | |
104 | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
105 len = FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
107
b5be4b0448d3
nginx-0.0.1-2003-07-01-19:00:03 import
Igor Sysoev <igor@sysoev.ru>
parents:
103
diff
changeset
|
106 |FORMAT_MESSAGE_IGNORE_INSERTS, |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
107 NULL, err, |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
108 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), |
461 | 109 (char *) errstr, size, NULL); |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
110 |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
111 if (len == 0) { |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
112 format_error = GetLastError(); |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
113 |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
114 if (format_error == ERROR_MR_MID_NOT_FOUND) { |
461 | 115 n = err - WSAEINVAL; |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
116 |
461 | 117 if (n >= 0 && n <= WSAECONNREFUSED - WSAEINVAL) { |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
118 len = wsa_errors[n].len; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
119 |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
120 if (len) { |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
121 if (len > size) { |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
122 len = size; |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
123 } |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
124 |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
125 ngx_memcpy(errstr, wsa_errors[n].data, len); |
461 | 126 |
127 return errstr + len; | |
103
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
128 } |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
129 } |
6dfda4cf5200
nginx-0.0.1-2003-06-11-19:28:34 import
Igor Sysoev <igor@sysoev.ru>
parents:
98
diff
changeset
|
130 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
131 |
461 | 132 return ngx_snprintf(errstr, size, |
133 "FormatMessage() error:(%d)", format_error); | |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
134 } |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
135 |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
136 /* remove ".\r\n\0" */ |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
137 while (errstr[len] == '\0' || errstr[len] == CR |
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
138 || errstr[len] == LF || errstr[len] == '.') |
461 | 139 { |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
140 --len; |
461 | 141 } |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
142 |
461 | 143 return &errstr[++len]; |
0
4eff17414a43
nginx-0.0.1-2002-08-06-20:39:45 import
Igor Sysoev <igor@sysoev.ru>
parents:
diff
changeset
|
144 } |