jdk/src/solaris/native/sun/nio/ch/Net.c
changeset 18535 71b74ae0ab8a
parent 18192 fa6bd0992104
child 22597 7515a991bb37
child 22573 8f0344f13b7f
equal deleted inserted replaced
18534:2d131cf5db63 18535:71b74ae0ab8a
    38 #include "net_util_md.h"
    38 #include "net_util_md.h"
    39 #include "nio_util.h"
    39 #include "nio_util.h"
    40 #include "nio.h"
    40 #include "nio.h"
    41 #include "sun_nio_ch_PollArrayWrapper.h"
    41 #include "sun_nio_ch_PollArrayWrapper.h"
    42 
    42 
       
    43 
       
    44 /**
       
    45  * IP_MULTICAST_ALL supported since 2.6.31 but may not be available at
       
    46  * build time.
       
    47  */
       
    48 #ifdef __linux__
       
    49   #ifndef IP_MULTICAST_ALL
       
    50   #define IP_MULTICAST_ALL    49
       
    51   #endif
       
    52 #endif
       
    53 
    43 #ifdef _ALLBSD_SOURCE
    54 #ifdef _ALLBSD_SOURCE
    44 
    55 
    45 #ifndef IP_BLOCK_SOURCE
    56 #ifndef IP_BLOCK_SOURCE
    46 
    57 
    47 #define IP_ADD_SOURCE_MEMBERSHIP        70   /* join a source-specific group */
    58 #define IP_ADD_SOURCE_MEMBERSHIP        70   /* join a source-specific group */
   173         int arg = 0;
   184         int arg = 0;
   174         if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
   185         if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
   175                        sizeof(int)) < 0) {
   186                        sizeof(int)) < 0) {
   176             JNU_ThrowByNameWithLastError(env,
   187             JNU_ThrowByNameWithLastError(env,
   177                                          JNU_JAVANETPKG "SocketException",
   188                                          JNU_JAVANETPKG "SocketException",
   178                                          "sun.nio.ch.Net.setIntOption");
   189                                          "Unable to set IPV6_V6ONLY");
   179             close(fd);
   190             close(fd);
   180             return -1;
   191             return -1;
   181         }
   192         }
   182     }
   193     }
   183 #endif
   194 #endif
   186         int arg = 1;
   197         int arg = 1;
   187         if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
   198         if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
   188                        sizeof(arg)) < 0) {
   199                        sizeof(arg)) < 0) {
   189             JNU_ThrowByNameWithLastError(env,
   200             JNU_ThrowByNameWithLastError(env,
   190                                          JNU_JAVANETPKG "SocketException",
   201                                          JNU_JAVANETPKG "SocketException",
   191                                          "sun.nio.ch.Net.setIntOption");
   202                                          "Unable to set SO_REUSEADDR");
   192             close(fd);
   203             close(fd);
   193             return -1;
   204             return -1;
   194         }
   205         }
   195     }
   206     }
       
   207 
       
   208 #if defined(__linux__)
       
   209     if (type == SOCK_DGRAM) {
       
   210         int arg = 0;
       
   211         int level = (domain == AF_INET6) ? IPPROTO_IPV6 : IPPROTO_IP;
       
   212         if ((setsockopt(fd, level, IP_MULTICAST_ALL, (char*)&arg, sizeof(arg)) < 0) &&
       
   213             (errno != ENOPROTOOPT)) {
       
   214             JNU_ThrowByNameWithLastError(env,
       
   215                                          JNU_JAVANETPKG "SocketException",
       
   216                                          "Unable to set IP_MULTICAST_ALL");
       
   217             close(fd);
       
   218             return -1;
       
   219         }
       
   220     }
       
   221 #endif
       
   222 
   196 #if defined(__linux__) && defined(AF_INET6)
   223 #if defined(__linux__) && defined(AF_INET6)
   197     /* By default, Linux uses the route default */
   224     /* By default, Linux uses the route default */
   198     if (domain == AF_INET6 && type == SOCK_DGRAM) {
   225     if (domain == AF_INET6 && type == SOCK_DGRAM) {
   199         int arg = 1;
   226         int arg = 1;
   200         if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &arg,
   227         if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &arg,
   201                        sizeof(arg)) < 0) {
   228                        sizeof(arg)) < 0) {
   202             JNU_ThrowByNameWithLastError(env,
   229             JNU_ThrowByNameWithLastError(env,
   203                                          JNU_JAVANETPKG "SocketException",
   230                                          JNU_JAVANETPKG "SocketException",
   204                                          "sun.nio.ch.Net.setIntOption");
   231                                          "Unable to set IPV6_MULTICAST_HOPS");
   205             close(fd);
   232             close(fd);
   206             return -1;
   233             return -1;
   207         }
   234         }
   208     }
   235     }
   209 #endif
   236 #endif
   644 
   671 
   645     if (rv >= 0) {
   672     if (rv >= 0) {
   646         return pfd.revents;
   673         return pfd.revents;
   647     } else if (errno == EINTR) {
   674     } else if (errno == EINTR) {
   648         return IOS_INTERRUPTED;
   675         return IOS_INTERRUPTED;
   649     } else if (rv < 0) {
   676     } else {
   650         handleSocketError(env, errno);
   677         handleSocketError(env, errno);
   651         return IOS_THROWN;
   678         return IOS_THROWN;
   652     }
   679     }
   653 }
   680 }
   654 
   681