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) );
}
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int 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).

View File

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

View File

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

View File

@ -27,7 +27,7 @@
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#if defined(__linux__) && !defined(USE_SELECT)
#if defined(__linux__)
#include <sys/poll.h>
#endif
#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.
*/
while (1) {
#ifndef USE_SELECT
{
struct pollfd pfd;
pfd.fd = fd;
pfd.events = POLLOUT;
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 (errno == EINTR) {
@ -381,38 +366,18 @@ Java_java_net_PlainSocketImpl_socketConnect(JNIEnv *env, jobject this,
/*
* 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
* this thread.
*/
while (1) {
jlong newTime;
#ifndef USE_SELECT
{
struct pollfd pfd;
pfd.fd = fd;
pfd.events = POLLOUT;
errno = 0;
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) {
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) );
}
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int 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.

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) );
}
#ifndef USE_SELECT
int NET_Poll(struct pollfd *ufds, unsigned int nfds, int 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).

View File

@ -75,13 +75,6 @@
#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
*/
@ -446,15 +439,14 @@ jint IPv6_supported()
}
#endif /* DONT_ENABLE_IPV6 */
void ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
const char* hostname,
int gai_error)
{
int size;
char *buf;
const char *format = "%s: %s";
const char *error_string =
(gai_strerror_ptr == NULL) ? NULL : (*gai_strerror_ptr)(gai_error);
const char *error_string = gai_strerror(gai_error);
if (error_string == NULL)
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
* NET_WAIT_READ, NET_WAIT_WRITE & NET_WAIT_CONNECT.
@ -1633,8 +1625,6 @@ NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout)
while (1) {
jlong newTime;
#ifndef USE_SELECT
{
struct pollfd pfd;
pfd.fd = fd;
pfd.events = 0;
@ -1647,33 +1637,6 @@ NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout)
errno = 0;
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);
timeout -= (newTime - prevTime);

View File

@ -32,9 +32,7 @@
#include <netinet/in.h>
#include <unistd.h>
#ifndef USE_SELECT
#include <sys/poll.h>
#endif
int NET_Timeout(int s, long timeout);
int NET_Read(int s, void* buf, size_t len);
@ -49,48 +47,20 @@ int NET_Connect(int s, struct sockaddr *addr, int addrlen);
int NET_Accept(int s, struct sockaddr *addr, socklen_t *addrlen);
int NET_SocketClose(int s);
int NET_Dup2(int oldfd, int newfd);
#ifdef USE_SELECT
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_Poll(struct pollfd *ufds, unsigned int nfds, int timeout);
int NET_SocketAvailable(int s, jint *pbytes);
#if defined(__linux__) && defined(AF_INET6)
int getDefaultIPv6Interface(struct in6_addr *target_addr);
#endif
#ifdef __solaris__
extern int net_getParam(char *driver, char *param);
#endif
/* needed from libsocket on Solaris 8 */
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,
void NET_ThrowUnknownHostExceptionWithGaiError(JNIEnv *env,
const char* hostname,
int gai_error);
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
const char *defaultDetail);
#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);
jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
/************************************************************************
* Macros and constants
@ -127,12 +97,16 @@ extern jint NET_Wait(JNIEnv *env, jint fd, jint flags, jint timeout);
/************************************************************************
* Utilities
*/
#ifdef __linux__
extern int kernelIsV24();
int kernelIsV24();
#ifdef AF_INET6
int getDefaultIPv6Interface(struct in6_addr *target_addr);
#endif
#endif
void NET_ThrowByNameWithLastError(JNIEnv *env, const char *name,
const char *defaultDetail);
#ifdef __solaris__
int net_getParam(char *driver, char *param);
#endif
#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));
}
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 result;
struct timeval t;