clean up exception handling in java-nio.cpp

This commit is contained in:
Joel Dice 2008-07-21 15:35:14 -06:00
parent 522e2ebc9f
commit 5b94b17ea2

View File

@ -95,8 +95,7 @@ init(JNIEnv* e, sockaddr_in* address, jstring hostString, jint port)
hostent* host = gethostbyname(chars);
e->ReleaseStringUTFChars(hostString, chars);
if (host == 0) {
// herror("init: gethostbyname");
throwIOException(e);
throwIOException(e, hstrerror(h_errno));
return;
}
memset(address, 0, sizeof(sockaddr_in));
@ -236,7 +235,10 @@ makeSocket(JNIEnv* e, bool blocking = false)
#endif
int s = ::socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (s < 0) { throwIOException(e); return s; }
if (s < 0) {
throwIOException(e);
return s;
}
if (not blocking) makeNonblocking(e, s);
@ -260,9 +262,11 @@ Java_java_nio_channels_ServerSocketChannel_natDoListen(JNIEnv *e,
{
int s = makeSocket(e);
if (s < 0) return s;
if (e->ExceptionOccurred()) return 0;
sockaddr_in address;
init(e, &address, host, port);
if (e->ExceptionOccurred()) return 0;
::doListen(e, s, &address);
return s;
@ -276,9 +280,11 @@ Java_java_nio_channels_SocketChannel_natDoConnect(JNIEnv *e,
jbooleanArray retVal)
{
int s = makeSocket(e);
if (e->ExceptionOccurred()) return 0;
sockaddr_in address;
init(e, &address, host, port);
if (e->ExceptionOccurred()) return 0;
jboolean connected = ::doConnect(e, s, &address);
e->SetBooleanArrayRegion(retVal, 0, 1, &connected);