author | igerasim |
Mon, 02 Mar 2015 11:07:47 +0300 | |
changeset 29228 | dfa75715dfa7 |
parent 26732 | 9b27273e6131 |
child 41601 | d04193dcb0f7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7668 | 2 |
* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
#include <windows.h> |
|
27 |
#include "jni.h" |
|
28 |
#include "jni_util.h" |
|
29 |
#include "jvm.h" |
|
30 |
#include "jlong.h" |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
31 |
#include "sun_nio_ch_FileDispatcherImpl.h" |
2 | 32 |
#include <io.h> |
33 |
#include "nio.h" |
|
34 |
#include "nio_util.h" |
|
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
35 |
#include "jlong.h" |
2 | 36 |
|
37 |
||
38 |
/************************************************************** |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
39 |
* FileDispatcherImpl.c |
2 | 40 |
*/ |
41 |
||
42 |
JNIEXPORT jint JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
43 |
Java_sun_nio_ch_FileDispatcherImpl_read0(JNIEnv *env, jclass clazz, jobject fdo, |
2 | 44 |
jlong address, jint len) |
45 |
{ |
|
46 |
DWORD read = 0; |
|
47 |
BOOL result = 0; |
|
48 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
|
49 |
||
50 |
if (h == INVALID_HANDLE_VALUE) { |
|
51 |
JNU_ThrowIOExceptionWithLastError(env, "Invalid handle"); |
|
52 |
return IOS_THROWN; |
|
53 |
} |
|
54 |
result = ReadFile(h, /* File handle to read */ |
|
55 |
(LPVOID)address, /* address to put data */ |
|
56 |
len, /* number of bytes to read */ |
|
57 |
&read, /* number of bytes read */ |
|
58 |
NULL); /* no overlapped struct */ |
|
59 |
if (result == 0) { |
|
60 |
int error = GetLastError(); |
|
61 |
if (error == ERROR_BROKEN_PIPE) { |
|
62 |
return IOS_EOF; |
|
63 |
} |
|
64 |
if (error == ERROR_NO_DATA) { |
|
65 |
return IOS_UNAVAILABLE; |
|
66 |
} |
|
67 |
JNU_ThrowIOExceptionWithLastError(env, "Read failed"); |
|
68 |
return IOS_THROWN; |
|
69 |
} |
|
70 |
return convertReturnVal(env, (jint)read, JNI_TRUE); |
|
71 |
} |
|
72 |
||
73 |
JNIEXPORT jlong JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
74 |
Java_sun_nio_ch_FileDispatcherImpl_readv0(JNIEnv *env, jclass clazz, jobject fdo, |
2 | 75 |
jlong address, jint len) |
76 |
{ |
|
77 |
DWORD read = 0; |
|
78 |
BOOL result = 0; |
|
79 |
jlong totalRead = 0; |
|
80 |
LPVOID loc; |
|
81 |
int i = 0; |
|
82 |
DWORD num = 0; |
|
83 |
struct iovec *iovecp = (struct iovec *)jlong_to_ptr(address); |
|
84 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
|
85 |
||
86 |
if (h == INVALID_HANDLE_VALUE) { |
|
87 |
JNU_ThrowIOExceptionWithLastError(env, "Invalid handle"); |
|
88 |
return IOS_THROWN; |
|
89 |
} |
|
90 |
||
91 |
for(i=0; i<len; i++) { |
|
92 |
loc = (LPVOID)jlong_to_ptr(iovecp[i].iov_base); |
|
93 |
num = iovecp[i].iov_len; |
|
94 |
result = ReadFile(h, /* File handle to read */ |
|
95 |
loc, /* address to put data */ |
|
96 |
num, /* number of bytes to read */ |
|
97 |
&read, /* number of bytes read */ |
|
98 |
NULL); /* no overlapped struct */ |
|
99 |
if (read > 0) { |
|
100 |
totalRead += read; |
|
101 |
} |
|
102 |
if (read < num) { |
|
103 |
break; |
|
104 |
} |
|
105 |
} |
|
106 |
||
107 |
if (result == 0) { |
|
108 |
int error = GetLastError(); |
|
109 |
if (error == ERROR_BROKEN_PIPE) { |
|
110 |
return IOS_EOF; |
|
111 |
} |
|
112 |
if (error == ERROR_NO_DATA) { |
|
113 |
return IOS_UNAVAILABLE; |
|
114 |
} |
|
115 |
JNU_ThrowIOExceptionWithLastError(env, "Read failed"); |
|
116 |
return IOS_THROWN; |
|
117 |
} |
|
118 |
||
119 |
return convertLongReturnVal(env, totalRead, JNI_TRUE); |
|
120 |
} |
|
121 |
||
122 |
JNIEXPORT jint JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
123 |
Java_sun_nio_ch_FileDispatcherImpl_pread0(JNIEnv *env, jclass clazz, jobject fdo, |
2 | 124 |
jlong address, jint len, jlong offset) |
125 |
{ |
|
126 |
DWORD read = 0; |
|
127 |
BOOL result = 0; |
|
128 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
|
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
129 |
LARGE_INTEGER currPos; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
130 |
OVERLAPPED ov; |
2 | 131 |
|
132 |
if (h == INVALID_HANDLE_VALUE) { |
|
133 |
JNU_ThrowIOExceptionWithLastError(env, "Invalid handle"); |
|
134 |
return IOS_THROWN; |
|
135 |
} |
|
136 |
||
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
137 |
currPos.QuadPart = 0; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
138 |
result = SetFilePointerEx(h, currPos, &currPos, FILE_CURRENT); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
139 |
if (result == 0) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
140 |
JNU_ThrowIOExceptionWithLastError(env, "Seek failed"); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
141 |
return IOS_THROWN; |
2 | 142 |
} |
143 |
||
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
144 |
ZeroMemory(&ov, sizeof(ov)); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
145 |
ov.Offset = (DWORD)offset; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
146 |
ov.OffsetHigh = (DWORD)(offset >> 32); |
2 | 147 |
|
148 |
result = ReadFile(h, /* File handle to read */ |
|
149 |
(LPVOID)address, /* address to put data */ |
|
150 |
len, /* number of bytes to read */ |
|
151 |
&read, /* number of bytes read */ |
|
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
152 |
&ov); /* position to read from */ |
2 | 153 |
|
154 |
if (result == 0) { |
|
155 |
int error = GetLastError(); |
|
156 |
if (error == ERROR_BROKEN_PIPE) { |
|
157 |
return IOS_EOF; |
|
158 |
} |
|
159 |
if (error == ERROR_NO_DATA) { |
|
160 |
return IOS_UNAVAILABLE; |
|
161 |
} |
|
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
162 |
if (error != ERROR_HANDLE_EOF) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
163 |
JNU_ThrowIOExceptionWithLastError(env, "Read failed"); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
164 |
return IOS_THROWN; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
165 |
} |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
166 |
} |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
167 |
|
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
168 |
result = SetFilePointerEx(h, currPos, NULL, FILE_BEGIN); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
169 |
if (result == 0) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
170 |
JNU_ThrowIOExceptionWithLastError(env, "Seek failed"); |
2 | 171 |
return IOS_THROWN; |
172 |
} |
|
173 |
||
174 |
return convertReturnVal(env, (jint)read, JNI_TRUE); |
|
175 |
} |
|
176 |
||
177 |
JNIEXPORT jint JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
178 |
Java_sun_nio_ch_FileDispatcherImpl_write0(JNIEnv *env, jclass clazz, jobject fdo, |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
179 |
jlong address, jint len, jboolean append) |
2 | 180 |
{ |
181 |
BOOL result = 0; |
|
182 |
DWORD written = 0; |
|
183 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
|
184 |
||
185 |
if (h != INVALID_HANDLE_VALUE) { |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
186 |
OVERLAPPED ov; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
187 |
LPOVERLAPPED lpOv; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
188 |
if (append == JNI_TRUE) { |
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
189 |
ZeroMemory(&ov, sizeof(ov)); |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
190 |
ov.Offset = (DWORD)0xFFFFFFFF; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
191 |
ov.OffsetHigh = (DWORD)0xFFFFFFFF; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
192 |
lpOv = &ov; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
193 |
} else { |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
194 |
lpOv = NULL; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
195 |
} |
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
196 |
result = WriteFile(h, /* File handle to write */ |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
197 |
(LPCVOID)address, /* pointer to the buffer */ |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
198 |
len, /* number of bytes to write */ |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
199 |
&written, /* receives number of bytes written */ |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
200 |
lpOv); /* overlapped struct */ |
2 | 201 |
} |
202 |
||
203 |
if ((h == INVALID_HANDLE_VALUE) || (result == 0)) { |
|
204 |
JNU_ThrowIOExceptionWithLastError(env, "Write failed"); |
|
205 |
} |
|
206 |
||
207 |
return convertReturnVal(env, (jint)written, JNI_FALSE); |
|
208 |
} |
|
209 |
||
210 |
JNIEXPORT jlong JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
211 |
Java_sun_nio_ch_FileDispatcherImpl_writev0(JNIEnv *env, jclass clazz, jobject fdo, |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
212 |
jlong address, jint len, jboolean append) |
2 | 213 |
{ |
214 |
BOOL result = 0; |
|
215 |
DWORD written = 0; |
|
216 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
|
217 |
jlong totalWritten = 0; |
|
218 |
||
219 |
if (h != INVALID_HANDLE_VALUE) { |
|
220 |
LPVOID loc; |
|
221 |
int i = 0; |
|
222 |
DWORD num = 0; |
|
223 |
struct iovec *iovecp = (struct iovec *)jlong_to_ptr(address); |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
224 |
OVERLAPPED ov; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
225 |
LPOVERLAPPED lpOv; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
226 |
if (append == JNI_TRUE) { |
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
227 |
ZeroMemory(&ov, sizeof(ov)); |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
228 |
ov.Offset = (DWORD)0xFFFFFFFF; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
229 |
ov.OffsetHigh = (DWORD)0xFFFFFFFF; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
230 |
lpOv = &ov; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
231 |
} else { |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
232 |
lpOv = NULL; |
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
233 |
} |
2 | 234 |
for(i=0; i<len; i++) { |
235 |
loc = (LPVOID)jlong_to_ptr(iovecp[i].iov_base); |
|
236 |
num = iovecp[i].iov_len; |
|
237 |
result = WriteFile(h, /* File handle to write */ |
|
238 |
loc, /* pointers to the buffers */ |
|
239 |
num, /* number of bytes to write */ |
|
240 |
&written,/* receives number of bytes written */ |
|
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
241 |
lpOv); /* overlapped struct */ |
2 | 242 |
if (written > 0) { |
243 |
totalWritten += written; |
|
244 |
} |
|
245 |
if (written < num) { |
|
246 |
break; |
|
247 |
} |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
if ((h == INVALID_HANDLE_VALUE) || (result == 0)) { |
|
252 |
JNU_ThrowIOExceptionWithLastError(env, "Write failed"); |
|
253 |
} |
|
254 |
||
255 |
return convertLongReturnVal(env, totalWritten, JNI_FALSE); |
|
256 |
} |
|
257 |
||
258 |
JNIEXPORT jint JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
259 |
Java_sun_nio_ch_FileDispatcherImpl_pwrite0(JNIEnv *env, jclass clazz, jobject fdo, |
2 | 260 |
jlong address, jint len, jlong offset) |
261 |
{ |
|
262 |
BOOL result = 0; |
|
263 |
DWORD written = 0; |
|
264 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
|
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
265 |
LARGE_INTEGER currPos; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
266 |
OVERLAPPED ov; |
2 | 267 |
|
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
268 |
currPos.QuadPart = 0; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
269 |
result = SetFilePointerEx(h, currPos, &currPos, FILE_CURRENT); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
270 |
if (result == 0) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
271 |
JNU_ThrowIOExceptionWithLastError(env, "Seek failed"); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
272 |
return IOS_THROWN; |
2 | 273 |
} |
274 |
||
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
275 |
ZeroMemory(&ov, sizeof(ov)); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
276 |
ov.Offset = (DWORD)offset; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
277 |
ov.OffsetHigh = (DWORD)(offset >> 32); |
2 | 278 |
|
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
279 |
result = WriteFile(h, /* File handle to write */ |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
280 |
(LPCVOID)address, /* pointer to the buffer */ |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
281 |
len, /* number of bytes to write */ |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
282 |
&written, /* receives number of bytes written */ |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
283 |
&ov); /* position to write at */ |
2 | 284 |
|
285 |
if ((h == INVALID_HANDLE_VALUE) || (result == 0)) { |
|
286 |
JNU_ThrowIOExceptionWithLastError(env, "Write failed"); |
|
287 |
return IOS_THROWN; |
|
288 |
} |
|
289 |
||
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
290 |
result = SetFilePointerEx(h, currPos, NULL, FILE_BEGIN); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
291 |
if (result == 0) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
292 |
JNU_ThrowIOExceptionWithLastError(env, "Seek failed"); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
293 |
return IOS_THROWN; |
2 | 294 |
} |
295 |
||
296 |
return convertReturnVal(env, (jint)written, JNI_FALSE); |
|
297 |
} |
|
298 |
||
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
299 |
JNIEXPORT jint JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
300 |
Java_sun_nio_ch_FileDispatcherImpl_force0(JNIEnv *env, jobject this, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
301 |
jobject fdo, jboolean md) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
302 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
303 |
int result = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
304 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
305 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
306 |
if (h != INVALID_HANDLE_VALUE) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
307 |
result = FlushFileBuffers(h); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
308 |
if (result == 0) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
309 |
int error = GetLastError(); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
310 |
if (error != ERROR_ACCESS_DENIED) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
311 |
JNU_ThrowIOExceptionWithLastError(env, "Force failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
312 |
return IOS_THROWN; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
313 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
314 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
315 |
} else { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
316 |
JNU_ThrowIOExceptionWithLastError(env, "Force failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
317 |
return IOS_THROWN; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
318 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
319 |
return 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
320 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
321 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
322 |
JNIEXPORT jint JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
323 |
Java_sun_nio_ch_FileDispatcherImpl_truncate0(JNIEnv *env, jobject this, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
324 |
jobject fdo, jlong size) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
325 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
326 |
BOOL result = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
327 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
29228
dfa75715dfa7
8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
igerasim
parents:
26732
diff
changeset
|
328 |
FILE_END_OF_FILE_INFO eofInfo; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
329 |
|
29228
dfa75715dfa7
8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
igerasim
parents:
26732
diff
changeset
|
330 |
eofInfo.EndOfFile.QuadPart = size; |
dfa75715dfa7
8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
igerasim
parents:
26732
diff
changeset
|
331 |
result = SetFileInformationByHandle(h, |
dfa75715dfa7
8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
igerasim
parents:
26732
diff
changeset
|
332 |
FileEndOfFileInfo, |
dfa75715dfa7
8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
igerasim
parents:
26732
diff
changeset
|
333 |
&eofInfo, |
dfa75715dfa7
8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
igerasim
parents:
26732
diff
changeset
|
334 |
sizeof(eofInfo)); |
dfa75715dfa7
8055915: (ch) FileDispatcherImpl.truncate0 should use SetFileInformationByHandle [win]
igerasim
parents:
26732
diff
changeset
|
335 |
if (result == FALSE) { |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
336 |
JNU_ThrowIOExceptionWithLastError(env, "Truncation failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
337 |
return IOS_THROWN; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
338 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
339 |
return 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
340 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
341 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
342 |
JNIEXPORT jlong JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
343 |
Java_sun_nio_ch_FileDispatcherImpl_size0(JNIEnv *env, jobject this, jobject fdo) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
344 |
{ |
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
345 |
BOOL result = 0; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
346 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
347 |
LARGE_INTEGER size; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
348 |
|
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
349 |
result = GetFileSizeEx(h, &size); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
350 |
if (result == 0) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
351 |
JNU_ThrowIOExceptionWithLastError(env, "Size failed"); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
352 |
return IOS_THROWN; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
353 |
} |
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
354 |
return (jlong)size.QuadPart; |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
355 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
356 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
357 |
JNIEXPORT jint JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
358 |
Java_sun_nio_ch_FileDispatcherImpl_lock0(JNIEnv *env, jobject this, jobject fdo, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
359 |
jboolean block, jlong pos, jlong size, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
360 |
jboolean shared) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
361 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
362 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
363 |
DWORD lowPos = (DWORD)pos; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
364 |
long highPos = (long)(pos >> 32); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
365 |
DWORD lowNumBytes = (DWORD)size; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
366 |
DWORD highNumBytes = (DWORD)(size >> 32); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
367 |
BOOL result; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
368 |
DWORD flags = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
369 |
OVERLAPPED o; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
370 |
o.hEvent = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
371 |
o.Offset = lowPos; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
372 |
o.OffsetHigh = highPos; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
373 |
if (block == JNI_FALSE) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
374 |
flags |= LOCKFILE_FAIL_IMMEDIATELY; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
375 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
376 |
if (shared == JNI_FALSE) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
377 |
flags |= LOCKFILE_EXCLUSIVE_LOCK; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
378 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
379 |
result = LockFileEx(h, flags, 0, lowNumBytes, highNumBytes, &o); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
380 |
if (result == 0) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
381 |
int error = GetLastError(); |
25806
7a0cf527248e
8053931: (fc) FileDispatcherImpl.lock0 does not handle ERROR_IO_PENDING [win]
alanb
parents:
7668
diff
changeset
|
382 |
if (error == ERROR_IO_PENDING) { |
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
383 |
DWORD dwBytes; |
25806
7a0cf527248e
8053931: (fc) FileDispatcherImpl.lock0 does not handle ERROR_IO_PENDING [win]
alanb
parents:
7668
diff
changeset
|
384 |
result = GetOverlappedResult(h, &o, &dwBytes, TRUE); |
7a0cf527248e
8053931: (fc) FileDispatcherImpl.lock0 does not handle ERROR_IO_PENDING [win]
alanb
parents:
7668
diff
changeset
|
385 |
if (result != 0) { |
7a0cf527248e
8053931: (fc) FileDispatcherImpl.lock0 does not handle ERROR_IO_PENDING [win]
alanb
parents:
7668
diff
changeset
|
386 |
return sun_nio_ch_FileDispatcherImpl_LOCKED; |
7a0cf527248e
8053931: (fc) FileDispatcherImpl.lock0 does not handle ERROR_IO_PENDING [win]
alanb
parents:
7668
diff
changeset
|
387 |
} |
7a0cf527248e
8053931: (fc) FileDispatcherImpl.lock0 does not handle ERROR_IO_PENDING [win]
alanb
parents:
7668
diff
changeset
|
388 |
error = GetLastError(); |
7a0cf527248e
8053931: (fc) FileDispatcherImpl.lock0 does not handle ERROR_IO_PENDING [win]
alanb
parents:
7668
diff
changeset
|
389 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
390 |
if (error != ERROR_LOCK_VIOLATION) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
391 |
JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
392 |
return sun_nio_ch_FileDispatcherImpl_NO_LOCK; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
393 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
394 |
if (flags & LOCKFILE_FAIL_IMMEDIATELY) { |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
395 |
return sun_nio_ch_FileDispatcherImpl_NO_LOCK; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
396 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
397 |
JNU_ThrowIOExceptionWithLastError(env, "Lock failed"); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
398 |
return sun_nio_ch_FileDispatcherImpl_NO_LOCK; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
399 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
400 |
return sun_nio_ch_FileDispatcherImpl_LOCKED; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
401 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
402 |
|
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
403 |
JNIEXPORT void JNICALL |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
404 |
Java_sun_nio_ch_FileDispatcherImpl_release0(JNIEnv *env, jobject this, |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
405 |
jobject fdo, jlong pos, jlong size) |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
406 |
{ |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
407 |
HANDLE h = (HANDLE)(handleval(env, fdo)); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
408 |
DWORD lowPos = (DWORD)pos; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
409 |
long highPos = (long)(pos >> 32); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
410 |
DWORD lowNumBytes = (DWORD)size; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
411 |
DWORD highNumBytes = (DWORD)(size >> 32); |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
412 |
jint result = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
413 |
OVERLAPPED o; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
414 |
o.hEvent = 0; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
415 |
o.Offset = lowPos; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
416 |
o.OffsetHigh = highPos; |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
417 |
result = UnlockFileEx(h, 0, lowNumBytes, highNumBytes, &o); |
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
418 |
if (result == 0) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
419 |
int error = GetLastError(); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
420 |
if (error == ERROR_IO_PENDING) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
421 |
DWORD dwBytes; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
422 |
result = GetOverlappedResult(h, &o, &dwBytes, TRUE); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
423 |
if (result == 0) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
424 |
return; |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
425 |
} |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
426 |
error = GetLastError(); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
427 |
} |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
428 |
if (error != ERROR_NOT_LOCKED) { |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
429 |
JNU_ThrowIOExceptionWithLastError(env, "Release failed"); |
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
430 |
} |
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
431 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
432 |
} |
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
433 |
|
2 | 434 |
static void closeFile(JNIEnv *env, jlong fd) { |
435 |
HANDLE h = (HANDLE)fd; |
|
436 |
if (h != INVALID_HANDLE_VALUE) { |
|
437 |
int result = CloseHandle(h); |
|
438 |
if (result < 0) |
|
439 |
JNU_ThrowIOExceptionWithLastError(env, "Close failed"); |
|
440 |
} |
|
441 |
} |
|
442 |
||
443 |
JNIEXPORT void JNICALL |
|
2057
3acf8e5e2ca0
6781363: New I/O: Update socket-channel API to jsr203/nio2-b99
alanb
parents:
2
diff
changeset
|
444 |
Java_sun_nio_ch_FileDispatcherImpl_close0(JNIEnv *env, jclass clazz, jobject fdo) |
2 | 445 |
{ |
446 |
jlong fd = handleval(env, fdo); |
|
447 |
closeFile(env, fd); |
|
448 |
} |
|
449 |
||
450 |
JNIEXPORT void JNICALL |
|
26732
9b27273e6131
8058099: (fc) Cleanup in FileChannel/FileDispatcher native implementation [win]
igerasim
parents:
25859
diff
changeset
|
451 |
Java_sun_nio_ch_FileDispatcherImpl_closeByHandle(JNIEnv *env, jclass clazz, jlong fd) |
2 | 452 |
{ |
453 |
closeFile(env, fd); |
|
454 |
} |
|
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
455 |
|
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
456 |
JNIEXPORT jlong JNICALL |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
457 |
Java_sun_nio_ch_FileDispatcherImpl_duplicateHandle(JNIEnv *env, jclass this, jlong handle) |
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
458 |
{ |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
459 |
HANDLE hProcess = GetCurrentProcess(); |
7515
43202796198e
6709457: (fc) lock/tryLock() throws IOException "Access is denied" when file opened for append [win]
alanb
parents:
7025
diff
changeset
|
460 |
HANDLE hFile = jlong_to_ptr(handle); |
7025
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
461 |
HANDLE hResult; |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
462 |
BOOL res = DuplicateHandle(hProcess, hFile, hProcess, &hResult, 0, FALSE, |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
463 |
DUPLICATE_SAME_ACCESS); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
464 |
if (res == 0) |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
465 |
JNU_ThrowIOExceptionWithLastError(env, "DuplicateHandle failed"); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
466 |
return ptr_to_jlong(hResult); |
6e002f9a2899
6816049: (bf) MappedByteBuffer.force() method does not flush data correctly
alanb
parents:
5506
diff
changeset
|
467 |
} |