src/windows/native/sun/nio/ch/WindowsAsynchronousSocketChannelImpl.c

Print this page




 140 
 141 
 142 JNIEXPORT void JNICALL
 143 Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_closesocket0(JNIEnv* env, jclass this,
 144     jlong socket)
 145 {
 146     SOCKET s = (SOCKET)jlong_to_ptr(socket);
 147     if (closesocket(s) == SOCKET_ERROR)
 148         JNU_ThrowIOExceptionWithLastError(env, "closesocket failed");
 149 }
 150 
 151 
 152 JNIEXPORT jint JNICALL
 153 Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_read0(JNIEnv* env, jclass this,
 154     jlong socket, jint count, jlong address, jlong ov)
 155 {
 156     SOCKET s = (SOCKET) jlong_to_ptr(socket);
 157     WSABUF* lpWsaBuf = (WSABUF*) jlong_to_ptr(address);
 158     OVERLAPPED* lpOverlapped = (OVERLAPPED*) jlong_to_ptr(ov);
 159     BOOL res;
 160     DWORD nread = 0;
 161     DWORD flags = 0;
 162 
 163     ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED));
 164     res = WSARecv(s,
 165                   lpWsaBuf,
 166                   (DWORD)count,
 167                   &nread,
 168                   &flags,
 169                   lpOverlapped,
 170                   NULL);
 171 
 172     if (res == SOCKET_ERROR) {
 173         int error = WSAGetLastError();
 174         if (error == WSA_IO_PENDING) {
 175             return IOS_UNAVAILABLE;
 176         }
 177         if (error == WSAESHUTDOWN) {
 178             return 0;       // input shutdown
 179         }
 180         JNU_ThrowIOExceptionWithLastError(env, "WSARecv failed");
 181         return IOS_THROWN;
 182     }
 183     if (nread == 0) {
 184         // Handle graceful close or bytes not yet available cases
 185         // via completion port notification.
 186         return IOS_UNAVAILABLE;
 187     }
 188     return (jint)nread;
 189 }
 190 
 191 JNIEXPORT jint JNICALL
 192 Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_write0(JNIEnv* env, jclass this,
 193     jlong socket, jint count, jlong address, jlong ov)
 194 {
 195     SOCKET s = (SOCKET) jlong_to_ptr(socket);
 196     WSABUF* lpWsaBuf = (WSABUF*) jlong_to_ptr(address);
 197     OVERLAPPED* lpOverlapped = (OVERLAPPED*) jlong_to_ptr(ov);
 198     BOOL res;
 199     DWORD nwritten;
 200 
 201     ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED));
 202     res = WSASend(s,
 203                   lpWsaBuf,
 204                   (DWORD)count,
 205                   &nwritten,
 206                   0,
 207                   lpOverlapped,
 208                   NULL);
 209 
 210     if (res == SOCKET_ERROR) {
 211         int error = WSAGetLastError();
 212         if (error == WSA_IO_PENDING) {
 213             return IOS_UNAVAILABLE;
 214         }
 215         if (error == WSAESHUTDOWN) {
 216             return IOS_EOF;     // output shutdown
 217         }
 218         JNU_ThrowIOExceptionWithLastError(env, "WSASend failed");
 219         return IOS_THROWN;
 220     }
 221     return (jint)nwritten;
 222 }


 140 
 141 
 142 JNIEXPORT void JNICALL
 143 Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_closesocket0(JNIEnv* env, jclass this,
 144     jlong socket)
 145 {
 146     SOCKET s = (SOCKET)jlong_to_ptr(socket);
 147     if (closesocket(s) == SOCKET_ERROR)
 148         JNU_ThrowIOExceptionWithLastError(env, "closesocket failed");
 149 }
 150 
 151 
 152 JNIEXPORT jint JNICALL
 153 Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_read0(JNIEnv* env, jclass this,
 154     jlong socket, jint count, jlong address, jlong ov)
 155 {
 156     SOCKET s = (SOCKET) jlong_to_ptr(socket);
 157     WSABUF* lpWsaBuf = (WSABUF*) jlong_to_ptr(address);
 158     OVERLAPPED* lpOverlapped = (OVERLAPPED*) jlong_to_ptr(ov);
 159     BOOL res;

 160     DWORD flags = 0;
 161 
 162     ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED));
 163     res = WSARecv(s,
 164                   lpWsaBuf,
 165                   (DWORD)count,
 166                   NULL,
 167                   &flags,
 168                   lpOverlapped,
 169                   NULL);
 170 
 171     if (res == SOCKET_ERROR) {
 172         int error = WSAGetLastError();
 173         if (error == WSA_IO_PENDING) {
 174             return IOS_UNAVAILABLE;
 175         }
 176         if (error == WSAESHUTDOWN) {
 177             return IOS_EOF;       // input shutdown
 178         }
 179         JNU_ThrowIOExceptionWithLastError(env, "WSARecv failed");
 180         return IOS_THROWN;
 181     }



 182     return IOS_UNAVAILABLE;


 183 }
 184 
 185 JNIEXPORT jint JNICALL
 186 Java_sun_nio_ch_WindowsAsynchronousSocketChannelImpl_write0(JNIEnv* env, jclass this,
 187     jlong socket, jint count, jlong address, jlong ov)
 188 {
 189     SOCKET s = (SOCKET) jlong_to_ptr(socket);
 190     WSABUF* lpWsaBuf = (WSABUF*) jlong_to_ptr(address);
 191     OVERLAPPED* lpOverlapped = (OVERLAPPED*) jlong_to_ptr(ov);
 192     BOOL res;

 193 
 194     ZeroMemory((PVOID)lpOverlapped, sizeof(OVERLAPPED));
 195     res = WSASend(s,
 196                   lpWsaBuf,
 197                   (DWORD)count,
 198                   NULL,
 199                   0,
 200                   lpOverlapped,
 201                   NULL);
 202 
 203     if (res == SOCKET_ERROR) {
 204         int error = WSAGetLastError();
 205         if (error == WSA_IO_PENDING) {
 206             return IOS_UNAVAILABLE;
 207         }
 208         if (error == WSAESHUTDOWN) {
 209             return IOS_EOF;     // output shutdown
 210         }
 211         JNU_ThrowIOExceptionWithLastError(env, "WSASend failed");
 212         return IOS_THROWN;
 213     }
 214     return IOS_UNAVAILABLE;
 215 }