提交 7ea73c94 编写于 作者: C chegar

8036584: Review comments from 8035897

Reviewed-by: alanb
上级 fc8f4ce9
...@@ -509,8 +509,7 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this, ...@@ -509,8 +509,7 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
JNU_ThrowNullPointerException(env, "Null address in peek()"); JNU_ThrowNullPointerException(env, "Null address in peek()");
} }
if (timeout) { if (timeout) {
int ret = NET_Timeout(env, fd, timeout); int ret = NET_Timeout(fd, timeout);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (ret == 0) { if (ret == 0) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Peek timed out"); "Peek timed out");
...@@ -518,6 +517,8 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this, ...@@ -518,6 +517,8 @@ Java_java_net_PlainDatagramSocketImpl_peek(JNIEnv *env, jobject this,
} else if (ret == JVM_IO_ERR) { } else if (ret == JVM_IO_ERR) {
if (errno == EBADF) { if (errno == EBADF) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
} else if (errno == ENOMEM) {
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
} else { } else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Peek failed"); NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Peek failed");
} }
...@@ -612,22 +613,24 @@ Java_java_net_PlainDatagramSocketImpl_peekData(JNIEnv *env, jobject this, ...@@ -612,22 +613,24 @@ Java_java_net_PlainDatagramSocketImpl_peekData(JNIEnv *env, jobject this,
packetBufferOffset = (*env)->GetIntField(env, packet, dp_offsetID); packetBufferOffset = (*env)->GetIntField(env, packet, dp_offsetID);
packetBufferLen = (*env)->GetIntField(env, packet, dp_bufLengthID); packetBufferLen = (*env)->GetIntField(env, packet, dp_bufLengthID);
if (timeout) { if (timeout) {
int ret = NET_Timeout(env, fd, timeout); int ret = NET_Timeout(fd, timeout);
JNU_CHECK_EXCEPTION_RETURN(env, -1);
if (ret == 0) { if (ret == 0) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Receive timed out"); "Receive timed out");
return -1; return -1;
} else if (ret == JVM_IO_ERR) { } else if (ret == JVM_IO_ERR) {
if (errno == ENOMEM) {
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
#ifdef __linux__ #ifdef __linux__
if (errno == EBADF) { } else if (errno == EBADF) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
} else { } else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed"); NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
}
#else #else
} else {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
#endif #endif
}
return -1; return -1;
} else if (ret == JVM_IO_INTR) { } else if (ret == JVM_IO_INTR) {
JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException", JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
...@@ -831,23 +834,24 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this, ...@@ -831,23 +834,24 @@ Java_java_net_PlainDatagramSocketImpl_receive0(JNIEnv *env, jobject this,
retry = JNI_FALSE; retry = JNI_FALSE;
if (timeout) { if (timeout) {
int ret = NET_Timeout(env, fd, timeout); int ret = NET_Timeout(fd, timeout);
if (ret <= 0) { if (ret <= 0) {
if ((*env)->ExceptionCheck(env)) { if (ret == 0) {
// fall-through, to potentially free, then return
} else if (ret == 0) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Receive timed out"); "Receive timed out");
} else if (ret == JVM_IO_ERR) { } else if (ret == JVM_IO_ERR) {
if (errno == ENOMEM) {
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
#ifdef __linux__ #ifdef __linux__
if (errno == EBADF) { } else if (errno == EBADF) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
} else { } else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed"); NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Receive failed");
}
#else #else
} else {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
#endif #endif
}
} else if (ret == JVM_IO_INTR) { } else if (ret == JVM_IO_INTR) {
JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException", JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
"operation interrupted"); "operation interrupted");
......
...@@ -704,11 +704,10 @@ Java_java_net_PlainSocketImpl_socketAccept(JNIEnv *env, jobject this, ...@@ -704,11 +704,10 @@ Java_java_net_PlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
/* passing a timeout of 0 to poll will return immediately, /* passing a timeout of 0 to poll will return immediately,
but in the case of ServerSocket 0 means infinite. */ but in the case of ServerSocket 0 means infinite. */
if (timeout <= 0) { if (timeout <= 0) {
ret = NET_Timeout(env, fd, -1); ret = NET_Timeout(fd, -1);
} else { } else {
ret = NET_Timeout(env, fd, timeout); ret = NET_Timeout(fd, timeout);
} }
JNU_CHECK_EXCEPTION(env);
if (ret == 0) { if (ret == 0) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Accept timed out"); "Accept timed out");
...@@ -716,6 +715,8 @@ Java_java_net_PlainSocketImpl_socketAccept(JNIEnv *env, jobject this, ...@@ -716,6 +715,8 @@ Java_java_net_PlainSocketImpl_socketAccept(JNIEnv *env, jobject this,
} else if (ret == JVM_IO_ERR) { } else if (ret == JVM_IO_ERR) {
if (errno == EBADF) { if (errno == EBADF) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
} else if (errno == ENOMEM) {
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
} else { } else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed"); NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed");
} }
......
...@@ -100,16 +100,16 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this, ...@@ -100,16 +100,16 @@ Java_java_net_SocketInputStream_socketRead0(JNIEnv *env, jobject this,
} }
if (timeout) { if (timeout) {
nread = NET_Timeout(env, fd, timeout); nread = NET_Timeout(fd, timeout);
if (nread <= 0) { if (nread <= 0) {
if ((*env)->ExceptionCheck(env)) { if (nread == 0) {
// fall-through, to potentially free, then return
} else if (nread == 0) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException", JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Read timed out"); "Read timed out");
} else if (nread == JVM_IO_ERR) { } else if (nread == JVM_IO_ERR) {
if (errno == EBADF) { if (errno == EBADF) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed"); JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
} else if (errno == ENOMEM) {
JNU_ThrowOutOfMemoryError(env, "NET_Timeout native heap allocation failed");
} else { } else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"select/poll failed"); "select/poll failed");
......
...@@ -38,8 +38,6 @@ ...@@ -38,8 +38,6 @@
#include <errno.h> #include <errno.h>
#include <sys/poll.h> #include <sys/poll.h>
#include "jni_util.h"
/* /*
* Stack allocated by thread when doing blocking operation * Stack allocated by thread when doing blocking operation
*/ */
...@@ -346,7 +344,7 @@ int NET_Select(int s, fd_set *readfds, fd_set *writefds, ...@@ -346,7 +344,7 @@ int NET_Select(int s, fd_set *readfds, fd_set *writefds,
* Auto restarts with adjusted timeout if interrupted by * Auto restarts with adjusted timeout if interrupted by
* signal other than our wakeup signal. * 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; long prevtime = 0, newtime;
struct timeval t, *tp = &t; struct timeval t, *tp = &t;
fd_set fds; fd_set fds;
...@@ -389,8 +387,7 @@ int NET_Timeout(JNIEnv *env, int s, long timeout) { ...@@ -389,8 +387,7 @@ int NET_Timeout(JNIEnv *env, int s, long timeout) {
int length = (howmany(s+1, NFDBITS)) * sizeof(int); int length = (howmany(s+1, NFDBITS)) * sizeof(int);
fdsp = (fd_set *) calloc(1, length); fdsp = (fd_set *) calloc(1, length);
if (fdsp == NULL) { if (fdsp == NULL) {
JNU_ThrowOutOfMemoryError(env, "NET_Select native heap allocation failed"); return -1; // errno will be set to ENOMEM
return 0;
} }
allocated = 1; allocated = 1;
} }
......
...@@ -36,8 +36,6 @@ ...@@ -36,8 +36,6 @@
#include <errno.h> #include <errno.h>
#include <sys/poll.h> #include <sys/poll.h>
#include "jni.h"
/* /*
* Stack allocated by thread when doing blocking operation * Stack allocated by thread when doing blocking operation
*/ */
...@@ -326,7 +324,7 @@ int NET_Select(int s, fd_set *readfds, fd_set *writefds, ...@@ -326,7 +324,7 @@ int NET_Select(int s, fd_set *readfds, fd_set *writefds,
* Auto restarts with adjusted timeout if interrupted by * Auto restarts with adjusted timeout if interrupted by
* signal other than our wakeup signal. * 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; long prevtime = 0, newtime;
struct timeval t; struct timeval t;
fdEntry_t *fdEntry = getFdEntry(s); fdEntry_t *fdEntry = getFdEntry(s);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册