author | bpb |
Tue, 12 Dec 2017 15:43:48 -0800 | |
changeset 48255 | 971d83666b23 |
parent 47216 | 71c04702a3d5 |
child 48767 | 0c6ce8fdb50a |
permissions | -rw-r--r-- |
2 | 1 |
/* |
48255
971d83666b23
8170495: JNI primitive type mismatch in SocketDispatcher.c:187
bpb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2000, 2017, 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 <winsock2.h> |
|
28 |
#include <ctype.h> |
|
29 |
#include "jni.h" |
|
30 |
#include "jni_util.h" |
|
31 |
#include "jvm.h" |
|
32 |
#include "jlong.h" |
|
33 |
#include "sun_nio_ch_SocketDispatcher.h" |
|
34 |
#include "nio.h" |
|
35 |
#include "nio_util.h" |
|
36 |
||
37 |
||
38 |
/************************************************************** |
|
39 |
* SocketDispatcher.c |
|
40 |
*/ |
|
41 |
||
42 |
JNIEXPORT jint JNICALL |
|
43 |
Java_sun_nio_ch_SocketDispatcher_read0(JNIEnv *env, jclass clazz, jobject fdo, |
|
44 |
jlong address, jint len) |
|
45 |
{ |
|
46 |
/* set up */ |
|
47 |
int i = 0; |
|
48 |
DWORD read = 0; |
|
49 |
DWORD flags = 0; |
|
50 |
jint fd = fdval(env, fdo); |
|
51 |
WSABUF buf; |
|
52 |
||
5804
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
53 |
/* limit size */ |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
54 |
if (len > MAX_BUFFER_SIZE) |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
55 |
len = MAX_BUFFER_SIZE; |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
56 |
|
2 | 57 |
/* destination buffer and size */ |
58 |
buf.buf = (char *)address; |
|
59 |
buf.len = (u_long)len; |
|
60 |
||
61 |
/* read into the buffers */ |
|
62 |
i = WSARecv((SOCKET)fd, /* Socket */ |
|
63 |
&buf, /* pointers to the buffers */ |
|
64 |
(DWORD)1, /* number of buffers to process */ |
|
65 |
&read, /* receives number of bytes read */ |
|
66 |
&flags, /* no flags */ |
|
67 |
0, /* no overlapped sockets */ |
|
68 |
0); /* no completion routine */ |
|
69 |
||
70 |
if (i == SOCKET_ERROR) { |
|
71 |
int theErr = (jint)WSAGetLastError(); |
|
72 |
if (theErr == WSAEWOULDBLOCK) { |
|
73 |
return IOS_UNAVAILABLE; |
|
74 |
} |
|
75 |
JNU_ThrowIOExceptionWithLastError(env, "Read failed"); |
|
76 |
return IOS_THROWN; |
|
77 |
} |
|
78 |
||
79 |
return convertReturnVal(env, (jint)read, JNI_TRUE); |
|
80 |
} |
|
81 |
||
82 |
JNIEXPORT jlong JNICALL |
|
83 |
Java_sun_nio_ch_SocketDispatcher_readv0(JNIEnv *env, jclass clazz, jobject fdo, |
|
84 |
jlong address, jint len) |
|
85 |
{ |
|
86 |
/* set up */ |
|
87 |
int i = 0; |
|
88 |
DWORD read = 0; |
|
89 |
DWORD flags = 0; |
|
90 |
jint fd = fdval(env, fdo); |
|
91 |
struct iovec *iovp = (struct iovec *)address; |
|
92 |
WSABUF *bufs = malloc(len * sizeof(WSABUF)); |
|
5804
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
93 |
jint rem = MAX_BUFFER_SIZE; |
2 | 94 |
|
95 |
if (bufs == 0) { |
|
96 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
97 |
return IOS_THROWN; |
|
98 |
} |
|
99 |
||
100 |
/* copy iovec into WSABUF */ |
|
101 |
for(i=0; i<len; i++) { |
|
5804
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
102 |
jint iov_len = iovp[i].iov_len; |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
103 |
if (iov_len > rem) |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
104 |
iov_len = rem; |
2 | 105 |
bufs[i].buf = (char *)iovp[i].iov_base; |
5804
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
106 |
bufs[i].len = (u_long)iov_len; |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
107 |
rem -= iov_len; |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
108 |
if (rem == 0) { |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
109 |
len = i+1; |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
110 |
break; |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
111 |
} |
2 | 112 |
} |
113 |
||
114 |
/* read into the buffers */ |
|
115 |
i = WSARecv((SOCKET)fd, /* Socket */ |
|
116 |
bufs, /* pointers to the buffers */ |
|
117 |
(DWORD)len, /* number of buffers to process */ |
|
118 |
&read, /* receives number of bytes read */ |
|
119 |
&flags, /* no flags */ |
|
120 |
0, /* no overlapped sockets */ |
|
121 |
0); /* no completion routine */ |
|
122 |
||
123 |
/* clean up */ |
|
124 |
free(bufs); |
|
125 |
||
126 |
if (i != 0) { |
|
127 |
int theErr = (jint)WSAGetLastError(); |
|
128 |
if (theErr == WSAEWOULDBLOCK) { |
|
129 |
return IOS_UNAVAILABLE; |
|
130 |
} |
|
131 |
JNU_ThrowIOExceptionWithLastError(env, "Vector read failed"); |
|
132 |
return IOS_THROWN; |
|
133 |
} |
|
134 |
||
135 |
return convertLongReturnVal(env, (jlong)read, JNI_TRUE); |
|
136 |
} |
|
137 |
||
138 |
JNIEXPORT jint JNICALL |
|
139 |
Java_sun_nio_ch_SocketDispatcher_write0(JNIEnv *env, jclass clazz, jobject fdo, |
|
13017
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
140 |
jlong address, jint total) |
2 | 141 |
{ |
142 |
/* set up */ |
|
143 |
int i = 0; |
|
144 |
DWORD written = 0; |
|
13017
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
145 |
jint count = 0; |
2 | 146 |
jint fd = fdval(env, fdo); |
147 |
WSABUF buf; |
|
148 |
||
13017
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
149 |
do { |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
150 |
/* limit size */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
151 |
jint len = total - count; |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
152 |
if (len > MAX_BUFFER_SIZE) |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
153 |
len = MAX_BUFFER_SIZE; |
5804
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
154 |
|
13017
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
155 |
/* copy iovec into WSABUF */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
156 |
buf.buf = (char *)address; |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
157 |
buf.len = (u_long)len; |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
158 |
|
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
159 |
/* write from the buffer */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
160 |
i = WSASend((SOCKET)fd, /* Socket */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
161 |
&buf, /* pointers to the buffers */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
162 |
(DWORD)1, /* number of buffers to process */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
163 |
&written, /* receives number of bytes written */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
164 |
0, /* no flags */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
165 |
0, /* no overlapped sockets */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
166 |
0); /* no completion routine */ |
2 | 167 |
|
13017
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
168 |
if (i == SOCKET_ERROR) { |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
169 |
if (count > 0) { |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
170 |
/* can't throw exception when some bytes have been written */ |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
171 |
break; |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
172 |
} else { |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
173 |
int theErr = (jint)WSAGetLastError(); |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
174 |
if (theErr == WSAEWOULDBLOCK) { |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
175 |
return IOS_UNAVAILABLE; |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
176 |
} |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
177 |
JNU_ThrowIOExceptionWithLastError(env, "Write failed"); |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
178 |
return IOS_THROWN; |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
179 |
} |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
180 |
} |
2 | 181 |
|
48255
971d83666b23
8170495: JNI primitive type mismatch in SocketDispatcher.c:187
bpb
parents:
47216
diff
changeset
|
182 |
count += (jint)written; |
13017
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
183 |
address += written; |
2 | 184 |
|
13017
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
185 |
} while ((count < total) && (written == MAX_BUFFER_SIZE)); |
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
186 |
|
2e79ad4fea09
7176630: (sc) SocketChannel.write does not write more than 128k when channel configured blocking [win]
alanb
parents:
11909
diff
changeset
|
187 |
return count; |
2 | 188 |
} |
189 |
||
190 |
JNIEXPORT jlong JNICALL |
|
191 |
Java_sun_nio_ch_SocketDispatcher_writev0(JNIEnv *env, jclass clazz, |
|
192 |
jobject fdo, jlong address, jint len) |
|
193 |
{ |
|
194 |
/* set up */ |
|
21324
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
195 |
int next_index, next_offset, ret=0; |
2 | 196 |
DWORD written = 0; |
197 |
jint fd = fdval(env, fdo); |
|
198 |
struct iovec *iovp = (struct iovec *)address; |
|
199 |
WSABUF *bufs = malloc(len * sizeof(WSABUF)); |
|
21324
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
200 |
jlong count = 0; |
2 | 201 |
|
202 |
if (bufs == 0) { |
|
203 |
JNU_ThrowOutOfMemoryError(env, 0); |
|
204 |
return IOS_THROWN; |
|
205 |
} |
|
206 |
||
21324
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
207 |
// next buffer and offset to consume |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
208 |
next_index = 0; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
209 |
next_offset = 0; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
210 |
|
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
211 |
while (next_index < len) { |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
212 |
DWORD buf_count = 0; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
213 |
|
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
214 |
/* Prepare the WSABUF array to a maximum total size of MAX_BUFFER_SIZE */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
215 |
jint rem = MAX_BUFFER_SIZE; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
216 |
while (next_index < len && rem > 0) { |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
217 |
jint iov_len = iovp[next_index].iov_len - next_offset; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
218 |
char* ptr = (char *)iovp[next_index].iov_base; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
219 |
ptr += next_offset; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
220 |
if (iov_len > rem) { |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
221 |
iov_len = rem; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
222 |
next_offset += rem; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
223 |
} else { |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
224 |
next_index ++; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
225 |
next_offset = 0; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
226 |
} |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
227 |
|
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
228 |
bufs[buf_count].buf = ptr; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
229 |
bufs[buf_count].len = (u_long)iov_len; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
230 |
buf_count++; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
231 |
|
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
232 |
rem -= iov_len; |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
233 |
} |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
234 |
|
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
235 |
/* write the buffers */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
236 |
ret = WSASend((SOCKET)fd, /* Socket */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
237 |
bufs, /* pointers to the buffers */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
238 |
buf_count, /* number of buffers to process */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
239 |
&written, /* receives number of bytes written */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
240 |
0, /* no flags */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
241 |
0, /* no overlapped sockets */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
242 |
0); /* no completion routine */ |
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
243 |
|
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
244 |
if (ret == SOCKET_ERROR) { |
5804
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
245 |
break; |
faf9bd47d6ce
6395224: (so) SocketChannel writer blocked on large buffer is not preempted by close method (vista)
alanb
parents:
5506
diff
changeset
|
246 |
} |
21324
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
247 |
|
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
248 |
count += written; |
2 | 249 |
} |
250 |
||
251 |
/* clean up */ |
|
252 |
free(bufs); |
|
253 |
||
21324
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
254 |
if (ret == SOCKET_ERROR && count == 0) { |
2 | 255 |
int theErr = (jint)WSAGetLastError(); |
256 |
if (theErr == WSAEWOULDBLOCK) { |
|
257 |
return IOS_UNAVAILABLE; |
|
258 |
} |
|
259 |
JNU_ThrowIOExceptionWithLastError(env, "Vector write failed"); |
|
260 |
return IOS_THROWN; |
|
261 |
} |
|
262 |
||
21324
1f9eb351241e
7074436: (sc) SocketChannel can do short gathering writes when channel configured blocking (win)
alanb
parents:
14342
diff
changeset
|
263 |
return convertLongReturnVal(env, count, JNI_FALSE); |
2 | 264 |
} |
265 |
||
266 |
JNIEXPORT void JNICALL |
|
11909
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
267 |
Java_sun_nio_ch_SocketDispatcher_preClose0(JNIEnv *env, jclass clazz, |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
268 |
jobject fdo) |
2 | 269 |
{ |
270 |
jint fd = fdval(env, fdo); |
|
271 |
struct linger l; |
|
272 |
int len = sizeof(l); |
|
11909
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
273 |
if (getsockopt(fd, SOL_SOCKET, SO_LINGER, (char *)&l, &len) == 0) { |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
274 |
if (l.l_onoff == 0) { |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
275 |
WSASendDisconnect(fd, NULL); |
2 | 276 |
} |
277 |
} |
|
278 |
} |
|
11909
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
279 |
|
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
280 |
JNIEXPORT void JNICALL |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
281 |
Java_sun_nio_ch_SocketDispatcher_close0(JNIEnv *env, jclass clazz, |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
282 |
jobject fdo) |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
283 |
{ |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
284 |
jint fd = fdval(env, fdo); |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
285 |
if (closesocket(fd) == SOCKET_ERROR) { |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
286 |
JNU_ThrowIOExceptionWithLastError(env, "Socket close failed"); |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
287 |
} |
a1a7165ac1fa
6346658: (se) Selector briefly spins when asynchronously closing a registered channel [win]
alanb
parents:
7668
diff
changeset
|
288 |
} |