src/solaris/native/java/net/PlainSocketImpl.c
Print this page
*** 109,120 ****
/*
* Finally shutdown sv[0] (any reads to this fd will get
* EOF; any writes will get an error).
*/
! JVM_SocketShutdown(sv[0], 2);
! JVM_SocketClose(sv[1]);
return sv[0];
}
/*
--- 109,120 ----
/*
* Finally shutdown sv[0] (any reads to this fd will get
* EOF; any writes will get an error).
*/
! shutdown(sv[0], 2);
! close(sv[1]);
return sv[0];
}
/*
*** 203,213 ****
if (fdObj == NULL) {
(*env)->ThrowNew(env, socketExceptionCls, "null fd object");
return;
}
! if ((fd = JVM_Socket(domain, type, 0)) == JVM_IO_ERR) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
NET_ThrowNew(env, errno, "can't create socket");
--- 203,213 ----
if (fdObj == NULL) {
(*env)->ThrowNew(env, socketExceptionCls, "null fd object");
return;
}
! if ((fd = socket(domain, type, 0)) == -1) {
/* note: if you run out of fds, you may not be able to load
* the exception class, and get a NoClassDefFoundError
* instead.
*/
NET_ThrowNew(env, errno, "can't create socket");
*** 233,243 ****
*/
ssObj = (*env)->GetObjectField(env, this, psi_serverSocketID);
if (ssObj != NULL) {
int arg = 1;
SET_NONBLOCKING(fd);
! if (JVM_SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
sizeof(arg)) < 0) {
NET_ThrowNew(env, errno, "cannot set SO_REUSEADDR");
close(fd);
return;
}
--- 233,243 ----
*/
ssObj = (*env)->GetObjectField(env, this, psi_serverSocketID);
if (ssObj != NULL) {
int arg = 1;
SET_NONBLOCKING(fd);
! if (NET_SetSockOpt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
sizeof(arg)) < 0) {
NET_ThrowNew(env, errno, "cannot set SO_REUSEADDR");
close(fd);
return;
}
*** 301,311 ****
}
#endif /* AF_INET6 */
if (timeout <= 0) {
connect_rv = NET_Connect(fd, (struct sockaddr *)&him, len);
#ifdef __solaris__
! if (connect_rv == JVM_IO_ERR && errno == EINPROGRESS ) {
/* This can happen if a blocking connect is interrupted by a signal.
* See 6343810.
*/
while (1) {
--- 301,311 ----
}
#endif /* AF_INET6 */
if (timeout <= 0) {
connect_rv = NET_Connect(fd, (struct sockaddr *)&him, len);
#ifdef __solaris__
! if (connect_rv == -1 && errno == EINPROGRESS ) {
/* This can happen if a blocking connect is interrupted by a signal.
* See 6343810.
*/
while (1) {
*** 328,357 ****
connect_rv = NET_Select(fd+1, 0, &wr, &ex, 0);
}
#endif
! if (connect_rv == JVM_IO_ERR) {
if (errno == EINTR) {
continue;
} else {
break;
}
}
if (connect_rv > 0) {
! int optlen;
/* has connection been established */
optlen = sizeof(connect_rv);
! if (JVM_GetSockOpt(fd, SOL_SOCKET, SO_ERROR,
(void*)&connect_rv, &optlen) <0) {
connect_rv = errno;
}
if (connect_rv != 0) {
/* restore errno */
errno = connect_rv;
! connect_rv = JVM_IO_ERR;
}
break;
}
}
}
--- 328,357 ----
connect_rv = NET_Select(fd+1, 0, &wr, &ex, 0);
}
#endif
! if (connect_rv == -1) {
if (errno == EINTR) {
continue;
} else {
break;
}
}
if (connect_rv > 0) {
! socklen_t optlen;
/* has connection been established */
optlen = sizeof(connect_rv);
! if (getsockopt(fd, SOL_SOCKET, SO_ERROR,
(void*)&connect_rv, &optlen) <0) {
connect_rv = errno;
}
if (connect_rv != 0) {
/* restore errno */
errno = connect_rv;
! connect_rv = -1;
}
break;
}
}
}
*** 367,377 ****
/* no need to use NET_Connect as non-blocking */
connect_rv = connect(fd, (struct sockaddr *)&him, len);
/* connection not established immediately */
if (connect_rv != 0) {
! int optlen;
jlong prevTime = JVM_CurrentTimeMillis(env, 0);
if (errno != EINPROGRESS) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
--- 367,377 ----
/* no need to use NET_Connect as non-blocking */
connect_rv = connect(fd, (struct sockaddr *)&him, len);
/* connection not established immediately */
if (connect_rv != 0) {
! socklen_t optlen;
jlong prevTime = JVM_CurrentTimeMillis(env, 0);
if (errno != EINPROGRESS) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"connect failed");
*** 444,460 ****
* At the high level it should be closed immediately but
* just in case we make the socket blocking again and
* shutdown input & output.
*/
SET_BLOCKING(fd);
! JVM_SocketShutdown(fd, 2);
return;
}
/* has connection been established */
optlen = sizeof(connect_rv);
! if (JVM_GetSockOpt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0) {
connect_rv = errno;
}
}
--- 444,460 ----
* At the high level it should be closed immediately but
* just in case we make the socket blocking again and
* shutdown input & output.
*/
SET_BLOCKING(fd);
! shutdown(fd, 2);
return;
}
/* has connection been established */
optlen = sizeof(connect_rv);
! if (getsockopt(fd, SOL_SOCKET, SO_ERROR, (void*)&connect_rv,
&optlen) <0) {
connect_rv = errno;
}
}
*** 462,472 ****
SET_BLOCKING(fd);
/* restore errno */
if (connect_rv != 0) {
errno = connect_rv;
! connect_rv = JVM_IO_ERR;
}
}
/* report the appropriate exception */
if (connect_rv < 0) {
--- 462,472 ----
SET_BLOCKING(fd);
/* restore errno */
if (connect_rv != 0) {
errno = connect_rv;
! connect_rv = -1;
}
}
/* report the appropriate exception */
if (connect_rv < 0) {
*** 480,504 ****
* fail with EADDRNOTAVAIL. In addition the Linux kernel
* returns the wrong error in this case - it returns EINVAL
* instead of EADDRNOTAVAIL. We handle this here so that
* a more descriptive exception text is used.
*/
! if (connect_rv == JVM_IO_ERR && errno == EINVAL) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Invalid argument or cannot assign requested address");
return;
}
#endif
- if (connect_rv == JVM_IO_INTR) {
- JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
- "operation interrupted");
#if defined(EPROTO)
! } else if (errno == EPROTO) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ProtocolException",
"Protocol error");
#endif
! } else if (errno == ECONNREFUSED) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"Connection refused");
} else if (errno == ETIMEDOUT) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"Connection timed out");
--- 480,503 ----
* fail with EADDRNOTAVAIL. In addition the Linux kernel
* returns the wrong error in this case - it returns EINVAL
* instead of EADDRNOTAVAIL. We handle this here so that
* a more descriptive exception text is used.
*/
! if (connect_rv == -1 && errno == EINVAL) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Invalid argument or cannot assign requested address");
return;
}
#endif
#if defined(EPROTO)
! if (errno == EPROTO) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ProtocolException",
"Protocol error");
+ return;
+ }
#endif
! if (errno == ECONNREFUSED) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"Connection refused");
} else if (errno == ETIMEDOUT) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "ConnectException",
"Connection timed out");
*** 530,541 ****
*/
if (localport == 0) {
/* Now that we're a connected socket, let's extract the port number
* that the system chose for us and store it in the Socket object.
*/
! len = SOCKADDR_LEN;
! if (JVM_GetSockName(fd, (struct sockaddr *)&him, &len) == -1) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"Error getting socket name");
} else {
localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
(*env)->SetIntField(env, this, psi_localportID, localport);
--- 529,540 ----
*/
if (localport == 0) {
/* Now that we're a connected socket, let's extract the port number
* that the system chose for us and store it in the Socket object.
*/
! socklen_t slen = SOCKADDR_LEN;
! if (getsockname(fd, (struct sockaddr *)&him, &slen) == -1) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"Error getting socket name");
} else {
localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
(*env)->SetIntField(env, this, psi_localportID, localport);
*** 592,605 ****
/* set the address */
(*env)->SetObjectField(env, this, psi_addressID, iaObj);
/* initialize the local port */
if (localport == 0) {
/* Now that we're a connected socket, let's extract the port number
* that the system chose for us and store it in the Socket object.
*/
! if (JVM_GetSockName(fd, (struct sockaddr *)&him, &len) == -1) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"Error getting socket name");
return;
}
localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
--- 591,605 ----
/* set the address */
(*env)->SetObjectField(env, this, psi_addressID, iaObj);
/* initialize the local port */
if (localport == 0) {
+ socklen_t slen = sizeof(him);
/* Now that we're a connected socket, let's extract the port number
* that the system chose for us and store it in the Socket object.
*/
! if (getsockname(fd, (struct sockaddr *)&him, &slen) == -1) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"Error getting socket name");
return;
}
localport = NET_GetPortFromSockaddr((struct sockaddr *)&him);
*** 636,646 ****
* If listen backlog is Integer.MAX_VALUE then subtract 1.
*/
if (count == 0x7fffffff)
count -= 1;
! if (JVM_Listen(fd, count) == JVM_IO_ERR) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"Listen failed");
}
}
--- 636,646 ----
* If listen backlog is Integer.MAX_VALUE then subtract 1.
*/
if (count == 0x7fffffff)
count -= 1;
! if (listen(fd, count) == -1) {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"Listen failed");
}
}
*** 669,681 ****
/* accepted fd */
jint newfd;
SOCKADDR him;
! int len;
!
! len = SOCKADDR_LEN;
if (IS_NULL(fdObj)) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Socket closed");
return;
--- 669,679 ----
/* accepted fd */
jint newfd;
SOCKADDR him;
! socklen_t slen = SOCKADDR_LEN;
if (IS_NULL(fdObj)) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException",
"Socket closed");
return;
*** 714,737 ****
if (ret == 0) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Accept timed out");
return;
! } else if (ret == JVM_IO_ERR) {
if (errno == EBADF) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
} else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed");
}
return;
- } else if (ret == JVM_IO_INTR) {
- JNU_ThrowByName(env, JNU_JAVAIOPKG "InterruptedIOException",
- "operation interrupted");
- return;
}
! newfd = NET_Accept(fd, (struct sockaddr *)&him, (jint*)&len);
/* connection accepted */
if (newfd >= 0) {
SET_BLOCKING(newfd);
break;
--- 712,731 ----
if (ret == 0) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketTimeoutException",
"Accept timed out");
return;
! } else if (ret == -1) {
if (errno == EBADF) {
JNU_ThrowByName(env, JNU_JAVANETPKG "SocketException", "Socket closed");
} else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException", "Accept failed");
}
return;
}
! newfd = NET_Accept(fd, (struct sockaddr *)&him, &slen);
/* connection accepted */
if (newfd >= 0) {
SET_BLOCKING(newfd);
break;
*** 814,825 ****
"Socket closed");
return -1;
} else {
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
! /* JVM_SocketAvailable returns 0 for failure, 1 for success */
! if (!JVM_SocketAvailable(fd, &ret)){
if (errno == ECONNRESET) {
JNU_ThrowByName(env, "sun/net/ConnectionResetException", "");
} else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"ioctl FIONREAD failed");
--- 808,819 ----
"Socket closed");
return -1;
} else {
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
! /* NET_SocketAvailable returns 0 for failure, 1 for success */
! if (NET_SocketAvailable(fd, &ret) == 0){
if (errno == ECONNRESET) {
JNU_ThrowByName(env, "sun/net/ConnectionResetException", "");
} else {
NET_ThrowByNameWithLastError(env, JNU_JAVANETPKG "SocketException",
"ioctl FIONREAD failed");
*** 879,889 ****
"socket already closed");
return;
} else {
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
! JVM_SocketShutdown(fd, howto);
}
/*
* Class: java_net_PlainSocketImpl
--- 873,883 ----
"socket already closed");
return;
} else {
fd = (*env)->GetIntField(env, fdObj, IO_fd_fdID);
}
! shutdown(fd, howto);
}
/*
* Class: java_net_PlainSocketImpl
*** 1099,1113 ****
JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
return;
}
}
! n = JVM_Send(fd, (char *)&d, 1, MSG_OOB);
! if (n == JVM_IO_ERR) {
NET_ThrowByNameWithLastError(env, "java/io/IOException", "Write failed");
- return;
- }
- if (n == JVM_IO_INTR) {
- JNU_ThrowByName(env, "java/io/InterruptedIOException", 0);
- return;
}
}
--- 1093,1102 ----
JNU_ThrowByName(env, "java/net/SocketException", "Socket closed");
return;
}
}
! n = NET_Send(fd, (char *)&d, 1, MSG_OOB);
! if (n == -1) {
NET_ThrowByNameWithLastError(env, "java/io/IOException", "Write failed");
}
}