mirror of
https://github.com/openjdk/jdk.git
synced 2026-05-19 01:47:52 +00:00
8036584: Review comments from 8035897
Reviewed-by: alanb
This commit is contained in:
parent
c96fd46a4c
commit
15411a6579
@ -63,8 +63,6 @@
|
||||
#include <errno.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
/*
|
||||
* Stack allocated by thread when doing blocking operation
|
||||
*/
|
||||
@ -384,7 +382,7 @@ int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
|
||||
* Auto restarts with adjusted timeout if interrupted by
|
||||
* signal other than our wakeup signal.
|
||||
*/
|
||||
int NET_Timeout(JNIEnv *unused, int s, long timeout) {
|
||||
int NET_Timeout(int s, long timeout) {
|
||||
long prevtime = 0, newtime;
|
||||
struct timeval t;
|
||||
fdEntry_t *fdEntry = getFdEntry(s);
|
||||
|
||||
@ -501,8 +501,7 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
|
||||
return -1;
|
||||
}
|
||||
if (timeout) {
|
||||
int ret = NET_Timeout(env, fd, timeout);
|
||||
JNU_CHECK_EXCEPTION_RETURN(env, -1);
|
||||
int ret = NET_Timeout(fd, timeout);
|
||||
if (ret == 0) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
|
||||
"Peek timed out");
|
||||
@ -510,6 +509,8 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
|
||||
} else if (ret == -1) {
|
||||
if (errno == EBADF) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
} else if (errno == ENOMEM) {
|
||||
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
|
||||
} else {
|
||||
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Peek failed");
|
||||
}
|
||||
@ -595,22 +596,24 @@ Java_java_net_PlainDatagramSocketImpl_peekData(JNIEnv *env, jobject this,
|
||||
packetBufferOffset = (*env)->GetIntField(env, packet, dp_offsetID);
|
||||
packetBufferLen = (*env)->GetIntField(env, packet, dp_bufLengthID);
|
||||
if (timeout) {
|
||||
int ret = NET_Timeout(env, fd, timeout);
|
||||
JNU_CHECK_EXCEPTION_RETURN(env, -1);
|
||||
int ret = NET_Timeout(fd, timeout);
|
||||
if (ret == 0) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
|
||||
"Receive timed out");
|
||||
return -1;
|
||||
} else if (ret == -1) {
|
||||
if (errno == ENOMEM) {
|
||||
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
|
||||
#ifdef __linux__
|
||||
if (errno == EBADF) {
|
||||
} else if (errno == EBADF) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
} else {
|
||||
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
|
||||
}
|
||||
#else
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
} else {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
#endif
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -804,23 +807,24 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this,
|
||||
retry = JNI_FALSE;
|
||||
|
||||
if (timeout) {
|
||||
int ret = NET_Timeout(env, fd, timeout);
|
||||
int ret = NET_Timeout(fd, timeout);
|
||||
if (ret <= 0) {
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// fall-through, to potentially free, then return
|
||||
} else if (ret == 0) {
|
||||
if (ret == 0) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
|
||||
"Receive timed out");
|
||||
} else if (ret == -1) {
|
||||
if (errno == ENOMEM) {
|
||||
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
|
||||
#ifdef __linux__
|
||||
if (errno == EBADF) {
|
||||
} else if (errno == EBADF) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
} else {
|
||||
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
|
||||
}
|
||||
} else {
|
||||
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
|
||||
#else
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
} else {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
if (mallocedPacket) {
|
||||
|
||||
@ -670,11 +670,10 @@ Java_java_net_PlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
||||
/* passing a timeout of 0 to poll will return immediately,
|
||||
but in the case of ServerSocket 0 means infinite. */
|
||||
if (timeout <= 0) {
|
||||
ret = NET_Timeout(env, fd, -1);
|
||||
ret = NET_Timeout(fd, -1);
|
||||
} else {
|
||||
ret = NET_Timeout(env, fd, timeout);
|
||||
ret = NET_Timeout(fd, timeout);
|
||||
}
|
||||
JNU_CHECK_EXCEPTION(env);
|
||||
if (ret == 0) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
|
||||
"Accept timed out");
|
||||
@ -682,6 +681,8 @@ Java_java_net_PlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
|
||||
} else if (ret == -1) {
|
||||
if (errno == EBADF) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
} else if (errno == ENOMEM) {
|
||||
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
|
||||
} else {
|
||||
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed");
|
||||
}
|
||||
|
||||
@ -100,20 +100,20 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this,
|
||||
}
|
||||
|
||||
if (timeout) {
|
||||
nread = NET_Timeout(env, fd, timeout);
|
||||
nread = NET_Timeout(fd, timeout);
|
||||
if (nread <= 0) {
|
||||
if ((*env)->ExceptionCheck(env)) {
|
||||
// fall-through, to potentially free, then return
|
||||
} else if (nread == 0) {
|
||||
if (nread == 0) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
|
||||
"Read timed out");
|
||||
} else if (nread == -1) {
|
||||
if (errno == EBADF) {
|
||||
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
|
||||
} else {
|
||||
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
|
||||
} else if (errno == ENOMEM) {
|
||||
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
|
||||
} else {
|
||||
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
|
||||
"select/poll failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (bufP != BUF) {
|
||||
free(bufP);
|
||||
|
||||
@ -38,8 +38,6 @@
|
||||
#include <errno.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include "jni_util.h"
|
||||
|
||||
/*
|
||||
* Stack allocated by thread when doing blocking operation
|
||||
*/
|
||||
@ -333,7 +331,7 @@ int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
|
||||
* Auto restarts with adjusted timeout if interrupted by
|
||||
* signal other than our wakeup signal.
|
||||
*/
|
||||
int NET_Timeout(JNIEnv *env, int s, long timeout) {
|
||||
int NET_Timeout(int s, long timeout) {
|
||||
long prevtime = 0, newtime;
|
||||
struct timeval t, *tp = &t;
|
||||
fd_set fds;
|
||||
@ -376,8 +374,7 @@ int NET_Timeout(JNIEnv *env, int s, long timeout) {
|
||||
int length = (howmany(s+1, NFDBITS)) * sizeof(int);
|
||||
fdsp = (fd_set *) calloc(1, length);
|
||||
if (fdsp == NULL) {
|
||||
JNU_ThrowOutOfMemoryError(env, "NET_Select native heap allocation failed");
|
||||
return 0;
|
||||
return -1; // errno will be set to ENOMEM
|
||||
}
|
||||
allocated = 1;
|
||||
}
|
||||
|
||||
@ -36,8 +36,6 @@
|
||||
#include <errno.h>
|
||||
#include <sys/poll.h>
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
/*
|
||||
* Stack allocated by thread when doing blocking operation
|
||||
*/
|
||||
@ -314,7 +312,7 @@ int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
|
||||
* Auto restarts with adjusted timeout if interrupted by
|
||||
* signal other than our wakeup signal.
|
||||
*/
|
||||
int NET_Timeout(JNIEnv *unused, int s, long timeout) {
|
||||
int NET_Timeout(int s, long timeout) {
|
||||
long prevtime = 0, newtime;
|
||||
struct timeval t;
|
||||
fdEntry_t *fdEntry = getFdEntry(s);
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
|
||||
#include <sys/poll.h>
|
||||
|
||||
int NET_Timeout(JNIEnv *env, int s, long timeout);
|
||||
int NET_Timeout(int s, long timeout);
|
||||
int NET_Read(int s, void* buf, size_t len);
|
||||
int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
|
||||
struct sockaddr *from, socklen_t *fromlen);
|
||||
|
||||
@ -28,8 +28,6 @@
|
||||
#include <stropts.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "jni.h"
|
||||
|
||||
/* Support for restartable system calls on Solaris. */
|
||||
|
||||
#define RESTARTABLE_RETURN_INT(_cmd) do { \
|
||||
@ -88,7 +86,7 @@ int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
|
||||
RESTARTABLE_RETURN_INT(poll(ufds, nfds, timeout));
|
||||
}
|
||||
|
||||
int NET_Timeout(JNIEnv *unused, int s, long timeout) {
|
||||
int NET_Timeout(int s, long timeout) {
|
||||
int result;
|
||||
struct timeval t;
|
||||
long prevtime, newtime;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user