(メッセージはありません)
@@ -1268,12 +1268,6 @@ | ||
1268 | 1268 | this->securityStatus = SEC_E_SECURITY_QOS_FAILED; |
1269 | 1269 | break; |
1270 | 1270 | } |
1271 | -#ifdef DEBUG | |
1272 | - { | |
1273 | - LONG flag = uAttrOut & ASC_RET_MUTUAL_AUTH; | |
1274 | - flag = flag; | |
1275 | - } | |
1276 | -#endif | |
1277 | 1271 | } |
1278 | 1272 | if (FAILED(this->securityStatus)) |
1279 | 1273 | { |
@@ -378,10 +378,7 @@ | ||
378 | 378 | SSLEngineHandshakeStatus hs = this->handshakeStatus; |
379 | 379 | if (FINISHED == hs) |
380 | 380 | { |
381 | - // FINISHEDに移行させている | |
382 | - // ToDo: この方法はよくない気がする | |
383 | - // NEED_TASKの直後にFINISHEDにならないように処理を見直すべき | |
384 | - // (証明書の検証を、InitializeSecurityContext()呼び出し中に行う?) | |
381 | + // FINISHEDからNOT_HANDSHAKINGに移行させる | |
385 | 382 | this->handshakeStatus = NOT_HANDSHAKING; |
386 | 383 | } |
387 | 384 | return hs; |
@@ -0,0 +1,339 @@ | ||
1 | +/* WCESelector.cpp | |
2 | + Copyright (C) 2010 Free Software Foundation, Inc. | |
3 | + | |
4 | +This file is part of GNU Classpath. | |
5 | + | |
6 | +GNU Classpath is free software; you can redistribute it and/or modify | |
7 | +it under the terms of the GNU General Public License as published by | |
8 | +the Free Software Foundation; either version 2, or (at your option) | |
9 | +any later version. | |
10 | + | |
11 | +GNU Classpath is distributed in the hope that it will be useful, but | |
12 | +WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | +General Public License for more details. | |
15 | + | |
16 | +You should have received a copy of the GNU General Public License | |
17 | +along with GNU Classpath; see the file COPYING. If not, write to the | |
18 | +Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | |
19 | +02110-1301 USA. | |
20 | + | |
21 | +Linking this library statically or dynamically with other modules is | |
22 | +making a combined work based on this library. Thus, the terms and | |
23 | +conditions of the GNU General Public License cover the whole | |
24 | +combination. | |
25 | + | |
26 | +As a special exception, the copyright holders of this library give you | |
27 | +permission to link this library with independent modules to produce an | |
28 | +executable, regardless of the license terms of these independent | |
29 | +modules, and to copy and distribute the resulting executable under | |
30 | +terms of your choice, provided that you also meet, for each linked | |
31 | +independent module, the terms and conditions of the license of that | |
32 | +module. An independent module is a module which is not derived from | |
33 | +or based on this library. If you modify this library, you may extend | |
34 | +this exception to your version of the library, but you are not | |
35 | +obligated to do so. If you do not wish to do so, delete this | |
36 | +exception statement from your version. */ | |
37 | + | |
38 | +#include <com_mysaifu_jvm_java_nio_channels_WCESelector.h> | |
39 | + | |
40 | +#include <winsock2.h> | |
41 | + | |
42 | +#define OP_ACCEPT 16 | |
43 | +#define OP_CONNECT 8 | |
44 | +#define OP_READ 1 | |
45 | +#define OP_WRITE 4 | |
46 | + | |
47 | +class WCESelector | |
48 | +{ | |
49 | + /** | |
50 | + * wakeup()でシグナル状態にするイベントオブジェクト | |
51 | + */ | |
52 | + WSAEVENT hWakeupEvent; | |
53 | + | |
54 | +public: | |
55 | + WCESelector(); | |
56 | + ~WCESelector(); | |
57 | + | |
58 | + int waitEvents(int count, SOCKET* sockets, long* events, DWORD timeout); | |
59 | + | |
60 | + void wakeup(); | |
61 | + | |
62 | + inline int OPS2EVENTS(int ops) | |
63 | + { | |
64 | + int ev = 0; | |
65 | + | |
66 | + if (ops & OP_ACCEPT) | |
67 | + { | |
68 | + ev |= FD_ACCEPT; | |
69 | + } | |
70 | + if (ops & OP_CONNECT) | |
71 | + { | |
72 | + ev |= FD_CONNECT; | |
73 | + } | |
74 | + if (ops & OP_READ) | |
75 | + { | |
76 | + ev |= FD_READ; | |
77 | + } | |
78 | + if (ops & OP_WRITE) | |
79 | + { | |
80 | + ev |= FD_WRITE; | |
81 | + } | |
82 | + return ev; | |
83 | + } | |
84 | + | |
85 | + inline int EVENTS2OPS(int events) | |
86 | + { | |
87 | + int ops = 0; | |
88 | + if (events & FD_ACCEPT) | |
89 | + { | |
90 | + ops |= OP_ACCEPT; | |
91 | + } | |
92 | + if (events & FD_CONNECT) | |
93 | + { | |
94 | + ops |= OP_CONNECT; | |
95 | + } | |
96 | + if (events & FD_READ) | |
97 | + { | |
98 | + ops |= OP_READ; | |
99 | + } | |
100 | + if (events & FD_WRITE) | |
101 | + { | |
102 | + ops |= OP_WRITE; | |
103 | + } | |
104 | + | |
105 | + return ops; | |
106 | + } | |
107 | + | |
108 | +}; | |
109 | + | |
110 | +WCESelector::WCESelector() | |
111 | +{ | |
112 | + this->hWakeupEvent = ::WSACreateEvent(); | |
113 | +} | |
114 | + | |
115 | +WCESelector::~WCESelector() | |
116 | +{ | |
117 | + ::WSACloseEvent(this->hWakeupEvent); | |
118 | +} | |
119 | + | |
120 | +void | |
121 | +WCESelector::wakeup() | |
122 | +{ | |
123 | + ::WSASetEvent(this->hWakeupEvent); | |
124 | +} | |
125 | + | |
126 | +int | |
127 | +WCESelector::waitEvents(int count, SOCKET* sockets, long* events, DWORD timeout) | |
128 | +{ | |
129 | + // wakeup()イベントの分1つだけ多く確保する | |
130 | + WSAEVENT* wsaEvents = new WSAEVENT[count + 1]; | |
131 | + bool error = false; | |
132 | + for (int i = 0; i < count; ++i) | |
133 | + { | |
134 | + SOCKET sock = sockets[i]; | |
135 | + long event = events[i]; | |
136 | + | |
137 | + WSAEVENT hEvent = ::WSACreateEvent(); | |
138 | + wsaEvents[i] = hEvent; | |
139 | + | |
140 | + int result = ::WSAEventSelect(sock, hEvent, events[i] | FD_CLOSE); | |
141 | + if (SOCKET_ERROR == result) | |
142 | + { | |
143 | + error = true; | |
144 | + break; | |
145 | + } | |
146 | + } | |
147 | + | |
148 | + int result = 0; | |
149 | + if (! error) | |
150 | + { | |
151 | + // wakeup() イベント | |
152 | + wsaEvents[count] = this->hWakeupEvent; | |
153 | + | |
154 | + DWORD ret = ::WSAWaitForMultipleEvents(count + 1, | |
155 | + wsaEvents, | |
156 | + FALSE, // fWaitAll | |
157 | + timeout, // dwTimeout | |
158 | + FALSE // fAlertable | |
159 | + ); | |
160 | + if (WSA_WAIT_FAILED == ret | |
161 | + || WSA_WAIT_TIMEOUT == ret | |
162 | + || WSA_WAIT_EVENT_0 + count == ret) | |
163 | + { | |
164 | + // 失敗またはタイムアウトまたはwakeup()で起こされた場合 | |
165 | + result = 0; | |
166 | + memset(events, 0, sizeof(long) * count); | |
167 | + } | |
168 | + else | |
169 | + { | |
170 | + // ネットワークイベントを列挙する | |
171 | + WSANETWORKEVENTS networkEvents; | |
172 | + | |
173 | + for (int i = 0; i < count; ++i) | |
174 | + { | |
175 | + WSAEVENT hEvent = wsaEvents[i]; | |
176 | + if (SOCKET_ERROR == ::WSAEnumNetworkEvents(sockets[i], // SOCKET | |
177 | + hEvent, // | |
178 | + &networkEvents // | |
179 | + )) | |
180 | + { | |
181 | + break; | |
182 | + } | |
183 | + | |
184 | + const long readyEvents = networkEvents.lNetworkEvents; | |
185 | + if (readyEvents & FD_CLOSE) | |
186 | + { | |
187 | + // クローズされてしまった | |
188 | + events[i] = 0xffffffff; | |
189 | + } | |
190 | + else | |
191 | + { | |
192 | + // 発生したイベントのみを格納する | |
193 | + if ((readyEvents & events[i]) != 0) | |
194 | + { | |
195 | + // 指定されたイベントのうち、1つ以上が発生した | |
196 | + result++; | |
197 | + events[i] = readyEvents; | |
198 | + } | |
199 | + else | |
200 | + { | |
201 | + // 指定されたイベントは発生しなかった | |
202 | + events[i] = 0; | |
203 | + } | |
204 | + } | |
205 | + } | |
206 | + } | |
207 | + } | |
208 | + | |
209 | + // イベントをクローズする | |
210 | + // ただし wakeup()イベントはクローズしない | |
211 | + for (int i = 0; i < count; ++i) | |
212 | + { | |
213 | + WSAEVENT hEvent = wsaEvents[i]; | |
214 | + ::WSAEventSelect(sockets[i], hEvent, 0); | |
215 | + ::WSACloseEvent(hEvent); | |
216 | + } | |
217 | + | |
218 | + // wakeup()イベントを非シグナル状態にする | |
219 | + ::WSAResetEvent(this->hWakeupEvent); | |
220 | + | |
221 | + delete wsaEvents; | |
222 | + | |
223 | + return result; | |
224 | +} | |
225 | + | |
226 | +/* | |
227 | + * Class: com_mysaifu_jvm_java_nio_channels_WCESelector | |
228 | + * Method: openNative | |
229 | + * Signature: ()I | |
230 | + */ | |
231 | +JNIEXPORT jint JNICALL Java_com_mysaifu_jvm_java_nio_channels_WCESelector_openNative | |
232 | + (JNIEnv *env, jobject) | |
233 | +{ | |
234 | + return reinterpret_cast<jint>(new WCESelector()); | |
235 | +} | |
236 | + | |
237 | + | |
238 | +/* | |
239 | + * Class: com_mysaifu_jvm_java_nio_channels_WCESelector | |
240 | + * Method: closeNative | |
241 | + * Signature: (I)V | |
242 | + */ | |
243 | +JNIEXPORT void JNICALL Java_com_mysaifu_jvm_java_nio_channels_WCESelector_closeNative | |
244 | + (JNIEnv *, jobject, jint nativePointer) | |
245 | +{ | |
246 | + if (nativePointer) | |
247 | + { | |
248 | + delete reinterpret_cast<WCESelector*>(nativePointer); | |
249 | + } | |
250 | +} | |
251 | + | |
252 | +/* | |
253 | + * Class: com_mysaifu_jvm_java_nio_channels_WCESelector | |
254 | + * Method: waitNativeEvents | |
255 | + * Signature: (I[I[IJ)I | |
256 | + */ | |
257 | +JNIEXPORT jint JNICALL Java_com_mysaifu_jvm_java_nio_channels_WCESelector_waitNativeEvents | |
258 | + (JNIEnv *env, jobject, jint nativePointer, jintArray sockets, jintArray opts, jlong timeout) | |
259 | +{ | |
260 | + if (! nativePointer) | |
261 | + { | |
262 | + return 0; | |
263 | + } | |
264 | + | |
265 | + const jsize count = env->GetArrayLength(sockets); | |
266 | + if (count != env->GetArrayLength(opts)) | |
267 | + { | |
268 | + env->ThrowNew(env->FindClass("java/lang/IllegalArgumentException"), "sockets.length!=opts.length"); | |
269 | + return 0; | |
270 | + } | |
271 | + | |
272 | + WCESelector* pSelector = reinterpret_cast<WCESelector*>(nativePointer); | |
273 | + | |
274 | + // パラメータをコピーする | |
275 | + SOCKET* socketsArray = new SOCKET[count]; | |
276 | + jint* tmp = static_cast<jint*>(env->GetPrimitiveArrayCritical(sockets, NULL)); | |
277 | + memcpy(socketsArray, tmp, sizeof(SOCKET) * count); | |
278 | + env->ReleasePrimitiveArrayCritical(sockets, tmp, 0); | |
279 | + | |
280 | + int* events = new int[count]; | |
281 | + tmp = static_cast<jint*>(env->GetPrimitiveArrayCritical(opts, NULL)); | |
282 | + for (int i = 0; i < count; ++i) | |
283 | + { | |
284 | + events[i] = pSelector->OPS2EVENTS(tmp[i]); | |
285 | + } | |
286 | + env->ReleasePrimitiveArrayCritical(opts, tmp, 0); | |
287 | + | |
288 | + DWORD t; | |
289 | + if (0 == timeout) | |
290 | + { | |
291 | + t = WSA_INFINITE; | |
292 | + } | |
293 | + else | |
294 | + { | |
295 | + t = (DWORD) timeout; | |
296 | + } | |
297 | + | |
298 | + int result = pSelector->waitEvents(count, socketsArray, reinterpret_cast<long*>(events), t); | |
299 | + | |
300 | + | |
301 | + // 結果を確かめる | |
302 | + tmp = static_cast<jint*>(env->GetPrimitiveArrayCritical(opts, NULL)); | |
303 | + for (int i = 0; i < count; ++i) | |
304 | + { | |
305 | + if (events[i] == 0xffffffff) | |
306 | + { | |
307 | + // クローズされてしまった場合 | |
308 | + tmp[i] = events[i]; | |
309 | + } | |
310 | + else | |
311 | + { | |
312 | + tmp[i] = pSelector->EVENTS2OPS(events[i]); | |
313 | + } | |
314 | + } | |
315 | + env->ReleasePrimitiveArrayCritical(opts, tmp, 0); | |
316 | + | |
317 | + | |
318 | + delete socketsArray; | |
319 | + delete events; | |
320 | + | |
321 | + return result; | |
322 | +} | |
323 | + | |
324 | +/* | |
325 | + * Class: com_mysaifu_jvm_java_nio_channels_WCESelector | |
326 | + * Method: wakeupNative | |
327 | + * Signature: (I)V | |
328 | + */ | |
329 | +JNIEXPORT void JNICALL Java_com_mysaifu_jvm_java_nio_channels_WCESelector_wakeupNative | |
330 | + (JNIEnv *, jobject, jint nativePointer) | |
331 | +{ | |
332 | + if (! nativePointer) | |
333 | + { | |
334 | + return; | |
335 | + } | |
336 | + | |
337 | + WCESelector* pSelector = reinterpret_cast<WCESelector*>(nativePointer); | |
338 | + pSelector->wakeup(); | |
339 | +} |
@@ -543,15 +543,8 @@ | ||
543 | 543 | &dwBytesWritten, NULL, 0); |
544 | 544 | } |
545 | 545 | |
546 | - if (dwBytesWritten == 0) | |
546 | + if (dwError != NOERROR) | |
547 | 547 | { |
548 | - // 1バイトも書き込めなかった | |
549 | - result = -1; | |
550 | - buf.count = 0; | |
551 | - | |
552 | - } | |
553 | - else if (dwError != NOERROR) | |
554 | - { | |
555 | 548 | // 何らかのエラーが発生 |
556 | 549 | buf.count = 0; |
557 | 550 | if (kind != g_Kind_FILE && dwError == WSAETIMEDOUT) |
@@ -2146,14 +2139,6 @@ | ||
2146 | 2139 | { |
2147 | 2140 | |
2148 | 2141 | int ret = cpnet_waitForReadable (sock); |
2149 | -#ifdef DEBUG | |
2150 | - { | |
2151 | - _TCHAR buff[256]; | |
2152 | - _stprintf(buff, _T("sock_receive() socket is %s\r\n"), | |
2153 | - cpnet_is_socket_blocking(sock) ? _T("blocking") : _T("non blocking")); | |
2154 | - OutputDebugString(buff); | |
2155 | - } | |
2156 | -#endif | |
2157 | 2142 | if (NOERROR == ret) |
2158 | 2143 | { |
2159 | 2144 | if (from) |
@@ -2205,13 +2190,6 @@ | ||
2205 | 2190 | ret = NOERROR; |
2206 | 2191 | } |
2207 | 2192 | } |
2208 | -#ifdef DEBUG | |
2209 | - { | |
2210 | - _TCHAR buff[256]; | |
2211 | - _stprintf(buff, _T("sock_receive() returning. ret=%d bytesReceived=%d\r\n"), ret, *bytesReceived); | |
2212 | - OutputDebugString(buff); | |
2213 | - } | |
2214 | -#endif | |
2215 | 2193 | return ret; |
2216 | 2194 | } |
2217 | 2195 |
@@ -2246,6 +2224,8 @@ | ||
2246 | 2224 | ret = WSAGetLastError (); |
2247 | 2225 | if (ret == WSAEWOULDBLOCK && cpnet_is_socket_blocking((SOCKET) sock) == JNI_FALSE) |
2248 | 2226 | { |
2227 | + // ノンブロッキング | |
2228 | + *bytesWritten = 0; | |
2249 | 2229 | ret = NOERROR; |
2250 | 2230 | } |
2251 | 2231 | } |