8035949: Remove unused macro USE_SELECT and clean up Unix version of net_util_md.{c,h}

Reviewed-by: chegar, alanb
This commit is contained in:
Volker Simonis 2014-02-28 17:14:08 +01:00
parent e2ab209b12
commit 3eb1d7659f
9 changed files with 49 additions and 176 deletions

View File

@ -374,17 +374,9 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) ); BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
} }
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) { int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) ); BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
} }
#else
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
BLOCKING_IO_RETURN_INT( s-1,
select(s, readfds, writefds, exceptfds, timeout) );
}
#endif
/* /*
* Wrapper for poll(s, timeout). * Wrapper for poll(s, timeout).

View File

@ -164,7 +164,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
if (error) { if (error) {
/* report error */ /* report error */
ThrowUnknownHostExceptionWithGaiError(env, hostname, error); NET_ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
JNU_ReleaseStringPlatformChars(env, host, hostname); JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL; return NULL;
} else { } else {
@ -416,7 +416,7 @@ Java_java_net_Inet4AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
if (error) { if (error) {
/* report error */ /* report error */
ThrowUnknownHostExceptionWithGaiError(env, hostname, error); NET_ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
JNU_ReleaseStringPlatformChars(env, host, hostname); JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL; return NULL;
} else { } else {

View File

@ -305,7 +305,7 @@ Java_java_net_Inet6AddressImpl_lookupAllHostAddr(JNIEnv *env, jobject this,
if (error) { if (error) {
/* report error */ /* report error */
ThrowUnknownHostExceptionWithGaiError(env, hostname, error); NET_ThrowUnknownHostExceptionWithGaiError(env, hostname, error);
JNU_ReleaseStringPlatformChars(env, host, hostname); JNU_ReleaseStringPlatformChars(env, host, hostname);
return NULL; return NULL;
} else { } else {

View File

@ -27,7 +27,7 @@
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/socket.h> #include <sys/socket.h>
#if defined(__linux__) && !defined(USE_SELECT) #if defined(__linux__)
#include <sys/poll.h> #include <sys/poll.h>
#endif #endif
#include <netinet/tcp.h> /* Defines TCP_NODELAY, needed for 2.6 */ #include <netinet/tcp.h> /* Defines TCP_NODELAY, needed for 2.6 */
@ -309,26 +309,11 @@ Java_java_net_PlainSocketImpl_socketConnect(JNIEnv *env, jobject this,
* See 6343810. * See 6343810.
*/ */
while (1) { while (1) {
#ifndef USE_SELECT struct pollfd pfd;
{ pfd.fd = fd;
struct pollfd pfd; pfd.events = POLLOUT;
pfd.fd = fd;
pfd.events = POLLOUT;
connect_rv = NET_Poll(&pfd, 1, -1); connect_rv = NET_Poll(&pfd, 1, -1);
}
#else
{
fd_set wr, ex;
FD_ZERO(&wr);
FD_SET(fd, &wr);
FD_ZERO(&ex);
FD_SET(fd, &ex);
connect_rv = NET_Select(fd+1, 0, &wr, &ex, 0);
}
#endif
if (connect_rv == -1) { if (connect_rv == -1) {
if (errno == EINTR) { if (errno == EINTR) {
@ -381,38 +366,18 @@ Java_java_net_PlainSocketImpl_socketConnect(JNIEnv *env, jobject this,
/* /*
* Wait for the connection to be established or a * Wait for the connection to be established or a
* timeout occurs. poll/select needs to handle EINTR in * timeout occurs. poll needs to handle EINTR in
* case lwp sig handler redirects any process signals to * case lwp sig handler redirects any process signals to
* this thread. * this thread.
*/ */
while (1) { while (1) {
jlong newTime; jlong newTime;
#ifndef USE_SELECT struct pollfd pfd;
{ pfd.fd = fd;
struct pollfd pfd; pfd.events = POLLOUT;
pfd.fd = fd;
pfd.events = POLLOUT;
errno = 0; errno = 0;
connect_rv = NET_Poll(&pfd, 1, timeout); connect_rv = NET_Poll(&pfd, 1, timeout);
}
#else
{
fd_set wr, ex;
struct timeval t;
t.tv_sec = timeout / 1000;
t.tv_usec = (timeout % 1000) * 1000;
FD_ZERO(&wr);
FD_SET(fd, &wr);
FD_ZERO(&ex);
FD_SET(fd, &ex);
errno = 0;
connect_rv = NET_Select(fd+1, 0, &wr, &ex, &t);
}
#endif
if (connect_rv >= 0) { if (connect_rv >= 0) {
break; break;

View File

@ -322,17 +322,9 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) ); BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
} }
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) { int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) ); BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
} }
#else
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
BLOCKING_IO_RETURN_INT( s-1,
select(s, readfds, writefds, exceptfds, timeout) );
}
#endif
/* /*
* Wrapper for select(s, timeout). We are using select() on Mac OS due to Bug 7131399. * Wrapper for select(s, timeout). We are using select() on Mac OS due to Bug 7131399.

View File

@ -304,17 +304,9 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen) {
BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) ); BLOCKING_IO_RETURN_INT( s, connect(s, addr, addrlen) );
} }
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) { int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) ); BLOCKING_IO_RETURN_INT( ufds[0].fd, poll(ufds, nfds, timeout) );
} }
#else
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
BLOCKING_IO_RETURN_INT( s-1,
select(s, readfds, writefds, exceptfds, timeout) );
}
#endif
/* /*
* Wrapper for poll(s, timeout). * Wrapper for poll(s, timeout).

View File

@ -75,13 +75,6 @@
#include "java_net_SocketOptions.h" #include "java_net_SocketOptions.h"
/* needed from libsocket on Solaris 8 */
getaddrinfo_f getaddrinfo_ptr = NULL;
freeaddrinfo_f freeaddrinfo_ptr = NULL;
gai_strerror_f gai_strerror_ptr = NULL;
getnameinfo_f getnameinfo_ptr = NULL;
/* /*
* EXCLBIND socket options only on Solaris * EXCLBIND socket options only on Solaris
*/ */
@ -446,15 +439,14 @@ jint IPv6_supported()
} }
#endif /* DONT_ENABLE_IPV6 */ #endif /* DONT_ENABLE_IPV6 */
void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env, void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
const char* hostname, const char* hostname,
int gai_error) int gai_error)
{ {
int size; int size;
char *buf; char *buf;
const char *format = "%s: %s"; const char *format = "%s: %s";
const char *error_string = const char *error_string = gai_strerror(gai_error);
(gai_strerror_ptr == NULL) ? NULL : (*gai_strerror_ptr)(gai_error);
if (error_string == NULL) if (error_string == NULL)
error_string = "unknown error"; error_string = "unknown error";
@ -1614,7 +1606,7 @@ NET_Bind(int fd, struct sockaddr *him, int len)
} }
/** /**
* Wrapper for select/poll with timeout on a single file descriptor. * Wrapper for poll with timeout on a single file descriptor.
* *
* flags (defined in net_util_md.h can be any combination of * flags (defined in net_util_md.h can be any combination of
* NET_WAIT_READ, NET_WAIT_WRITE & NET_WAIT_CONNECT. * NET_WAIT_READ, NET_WAIT_WRITE & NET_WAIT_CONNECT.
@ -1633,47 +1625,18 @@ NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout)
while (1) { while (1) {
jlong newTime; jlong newTime;
#ifndef USE_SELECT struct pollfd pfd;
{ pfd.fd = fd;
struct pollfd pfd; pfd.events = 0;
pfd.fd = fd; if (flags & NET_WAIT_READ)
pfd.events = 0; pfd.events |= POLLIN;
if (flags & NET_WAIT_READ) if (flags & NET_WAIT_WRITE)
pfd.events |= POLLIN; pfd.events |= POLLOUT;
if (flags & NET_WAIT_WRITE) if (flags & NET_WAIT_CONNECT)
pfd.events |= POLLOUT; pfd.events |= POLLOUT;
if (flags & NET_WAIT_CONNECT)
pfd.events |= POLLOUT;
errno = 0; errno = 0;
read_rv = NET_Poll(&pfd, 1, timeout); read_rv = NET_Poll(&pfd, 1, timeout);
}
#else
{
fd_set rd, wr, ex;
struct timeval t;
t.tv_sec = timeout / 1000;
t.tv_usec = (timeout % 1000) * 1000;
FD_ZERO(&rd);
FD_ZERO(&wr);
FD_ZERO(&ex);
if (flags & NET_WAIT_READ) {
FD_SET(fd, &rd);
}
if (flags & NET_WAIT_WRITE) {
FD_SET(fd, &wr);
}
if (flags & NET_WAIT_CONNECT) {
FD_SET(fd, &wr);
FD_SET(fd, &ex);
}
errno = 0;
read_rv = NET_Select(fd+1, &rd, &wr, &ex, &t);
}
#endif
newTime = JVM_CurrentTimeMillis(env, 0); newTime = JVM_CurrentTimeMillis(env, 0);
timeout -= (newTime - prevTime); timeout -= (newTime - prevTime);

View File

@ -32,9 +32,7 @@
#include <netinet/in.h> #include <netinet/in.h>
#include <unistd.h> #include <unistd.h>
#ifndef USE_SELECT
#include <sys/poll.h> #include <sys/poll.h>
#endif
int NET_Timeout(int s, long timeout); int NET_Timeout(int s, long timeout);
int NET_Read(int s, void* buf, size_t len); int NET_Read(int s, void* buf, size_t len);
@ -43,54 +41,26 @@ int NET_RecvFrom(int s, void *buf, int len, unsigned int flags,
int NET_ReadV(int s, const struct iovec * vector, int count); int NET_ReadV(int s, const struct iovec * vector, int count);
int NET_Send(int s, void *msg, int len, unsigned int flags); int NET_Send(int s, void *msg, int len, unsigned int flags);
int NET_SendTo(int s, const void *msg, int len, unsigned int int NET_SendTo(int s, const void *msg, int len, unsigned int
flags, const struct sockaddr *to, int tolen); flags, const struct sockaddr *to, int tolen);
int NET_Writev(int s, const struct iovec * vector, int count); int NET_Writev(int s, const struct iovec * vector, int count);
int NET_Connect(int s, struct sockaddr *addr, int addrlen); int NET_Connect(int s, struct sockaddr *addr, int addrlen);
int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen); int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int NET_SocketClose(int s); int NET_SocketClose(int s);
int NET_Dup2(int oldfd, int newfd); int NET_Dup2(int oldfd, int newfd);
#ifdef USE_SELECT int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
extern int NET_Select(int s, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout);
#else
extern int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
#endif
int NET_SocketAvailable(int s, jint *pbytes); int NET_SocketAvailable(int s, jint *pbytes);
#if defined(__linux__) && defined(AF_INET6) void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
int getDefaultIPv6Interface(struct in6_addr *target_addr); const char* hostname,
#endif int gai_error);
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
const char *defaultDetail);
#ifdef __solaris__ #define NET_WAIT_READ 0x01
extern int net_getParam(char *driver, char *param); #define NET_WAIT_WRITE 0x02
#endif #define NET_WAIT_CONNECT 0x04
/* needed from libsocket on Solaris 8 */ jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
typedef int (*getaddrinfo_f)(const char *nodename, const char *servname,
const struct addrinfo *hints, struct addrinfo **res);
typedef void (*freeaddrinfo_f)(struct addrinfo *);
typedef const char * (*gai_strerror_f)(int ecode);
typedef int (*getnameinfo_f)(const struct sockaddr *, size_t,
char *, size_t, char *, size_t, int);
extern getaddrinfo_f getaddrinfo_ptr;
extern freeaddrinfo_f freeaddrinfo_ptr;
extern getnameinfo_f getnameinfo_ptr;
void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
const char* hostname,
int gai_error);
#define NET_WAIT_READ 0x01
#define NET_WAIT_WRITE 0x02
#define NET_WAIT_CONNECT 0x04
extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
/************************************************************************ /************************************************************************
* Macros and constants * Macros and constants
@ -127,12 +97,16 @@ extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
/************************************************************************ /************************************************************************
* Utilities * Utilities
*/ */
#ifdef __linux__ #ifdef __linux__
extern int kernelIsV24(); int kernelIsV24();
#ifdef AF_INET6
int getDefaultIPv6Interface(struct in6_addr *target_addr);
#endif
#endif #endif
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name, #ifdef __solaris__
const char *defaultDetail); int net_getParam(char *driver, char *param);
#endif
#endif /* NET_UTILS_MD_H */ #endif /* NET_UTILS_MD_H */

View File

@ -86,11 +86,6 @@ int NET_Poll(struct pollfd *ufds, unsigned int nfds, int timeout) {
RESTARTABLE_RETURN_INT(poll(ufds, nfds, timeout)); RESTARTABLE_RETURN_INT(poll(ufds, nfds, timeout));
} }
int NET_Select(int s, fd_set *readfds, fd_set *writefds,
fd_set *exceptfds, struct timeval *timeout) {
RESTARTABLE_RETURN_INT(select(s, readfds, writefds, exceptfds, timeout));
}
int NET_Timeout(int s, long timeout) { int NET_Timeout(int s, long timeout) {
int result; int result;
struct timeval t; struct timeval t;