src/solaris/native/java/net/net_util_md.c

Print this page

        

*** 38,59 **** --- 38,62 ---- #include <values.h> #else #include <limits.h> #include <sys/param.h> #include <sys/sysctl.h> + #include <sys/ioctl.h> #ifndef MAXINT #define MAXINT INT_MAX #endif #endif #ifdef __solaris__ + #include <sys/filio.h> #include <sys/sockio.h> #include <stropts.h> #include <inet/nd.h> #endif #ifdef __linux__ + #include <sys/ioctl.h> #include <arpa/inet.h> #include <net/route.h> #include <sys/utsname.h> #ifndef IPV6_FLOWINFO_SEND
*** 108,117 **** --- 111,121 ---- } #endif } int getDefaultScopeID(JNIEnv *env) { + int defaultIndex = 0; static jclass ni_class = NULL; static jfieldID ni_defaultIndexID; if (ni_class == NULL) { jclass c = (*env)->FindClass(env, "java/net/NetworkInterface"); CHECK_NULL_RETURN(c, 0);
*** 119,134 **** CHECK_NULL_RETURN(c, 0); ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I"); ni_class = c; } - int defaultIndex = 0; defaultIndex = (*env)->GetStaticIntField(env, ni_class, ni_defaultIndexID); return defaultIndex; } #ifdef __solaris__ static int init_tcp_max_buf, init_udp_max_buf; static int tcp_max_buf; static int udp_max_buf; static int useExclBind = 0; --- 123,151 ---- CHECK_NULL_RETURN(c, 0); ni_defaultIndexID = (*env)->GetStaticFieldID(env, c, "defaultIndex", "I"); ni_class = c; } defaultIndex = (*env)->GetStaticIntField(env, ni_class, ni_defaultIndexID); return defaultIndex; } + #define RESTARTABLE(_cmd, _result) do { \ + do { \ + _result = _cmd; \ + } while((_result == -1) && (errno == EINTR)); \ + } while(0) + + int NET_SocketAvailable(int s, jint *pbytes) { + int result; + RESTARTABLE(ioctl(s, FIONREAD, pbytes), result); + // note: ioctl can return 0 when successful, NET_SocketAvailable + // is expected to return 0 on failure and 1 on success. + return (result == -1) ? 0 : 1; + } + #ifdef __solaris__ static int init_tcp_max_buf, init_udp_max_buf; static int tcp_max_buf; static int udp_max_buf; static int useExclBind = 0;
*** 320,330 **** int fd; void *ipv6_fn; SOCKADDR sa; socklen_t sa_len = sizeof(sa); ! fd = JVM_Socket(AF_INET6, SOCK_STREAM, 0) ; if (fd < 0) { /* * TODO: We really cant tell since it may be an unrelated error * for now we will assume that AF_INET6 is not available */ --- 337,347 ---- int fd; void *ipv6_fn; SOCKADDR sa; socklen_t sa_len = sizeof(sa); ! fd = socket(AF_INET6, SOCK_STREAM, 0) ; if (fd < 0) { /* * TODO: We really cant tell since it may be an unrelated error * for now we will assume that AF_INET6 is not available */
*** 1205,1214 **** --- 1222,1232 ---- int NET_GetSockOpt(int fd, int level, int opt, void *result, int *len) { int rv; + socklen_t socklen = *len; #ifdef AF_INET6 if ((level == IPPROTO_IP) && (opt == IP_TOS)) { if (ipv6_available()) {
*** 1221,1239 **** return 0; } } #endif - #ifdef __solaris__ - rv = getsockopt(fd, level, opt, result, len); - #else - { - socklen_t socklen = *len; rv = getsockopt(fd, level, opt, result, &socklen); *len = socklen; - } - #endif if (rv < 0) { return rv; } --- 1239,1250 ----
*** 1340,1350 **** * the value when it exceeds the system limit. */ #ifdef __solaris__ if (level == SOL_SOCKET) { if (opt == SO_SNDBUF || opt == SO_RCVBUF) { ! int sotype=0, arglen; int *bufsize, maxbuf; int ret; /* Attempt with the original size */ ret = setsockopt(fd, level, opt, arg, len); --- 1351,1362 ---- * the value when it exceeds the system limit. */ #ifdef __solaris__ if (level == SOL_SOCKET) { if (opt == SO_SNDBUF || opt == SO_RCVBUF) { ! int sotype=0; ! socklen_t arglen; int *bufsize, maxbuf; int ret; /* Attempt with the original size */ ret = setsockopt(fd, level, opt, arg, len);
*** 1544,1554 **** * to IPv4 mapped addresses whereby the socket conversion * results in a late bind that fails because the * corresponding IPv4 port is in use. */ if (ipv6_available()) { ! int arg, len; len = sizeof(arg); if (useExclBind || getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&arg, &len) == 0) { if (useExclBind || arg == 0) { --- 1556,1567 ---- * to IPv4 mapped addresses whereby the socket conversion * results in a late bind that fails because the * corresponding IPv4 port is in use. */ if (ipv6_available()) { ! int arg; ! socklen_t len; len = sizeof(arg); if (useExclBind || getsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char *)&arg, &len) == 0) { if (useExclBind || arg == 0) {