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

Print this page
rev 8725 : 8024854: Basic changes and files to build the class library on AIX
Contributed-by: luchsh@linux.vnet.ibm.com, spoole@linux.vnet.ibm.com, thomas.stuefe@sap.com
Reviewed-by: alanb, prr, sla, chegar, michaelm, mullan


 970     return 1;
 971 }
 972 
 973 /*
 974  * Map the Java level socket option to the platform specific
 975  * level and option name.
 976  */
 977 int
 978 NET_MapSocketOption(jint cmd, int *level, int *optname) {
 979     static struct {
 980         jint cmd;
 981         int level;
 982         int optname;
 983     } const opts[] = {
 984         { java_net_SocketOptions_TCP_NODELAY,           IPPROTO_TCP,    TCP_NODELAY },
 985         { java_net_SocketOptions_SO_OOBINLINE,          SOL_SOCKET,     SO_OOBINLINE },
 986         { java_net_SocketOptions_SO_LINGER,             SOL_SOCKET,     SO_LINGER },
 987         { java_net_SocketOptions_SO_SNDBUF,             SOL_SOCKET,     SO_SNDBUF },
 988         { java_net_SocketOptions_SO_RCVBUF,             SOL_SOCKET,     SO_RCVBUF },
 989         { java_net_SocketOptions_SO_KEEPALIVE,          SOL_SOCKET,     SO_KEEPALIVE },



 990         { java_net_SocketOptions_SO_REUSEADDR,          SOL_SOCKET,     SO_REUSEADDR },

 991         { java_net_SocketOptions_SO_BROADCAST,          SOL_SOCKET,     SO_BROADCAST },
 992         { java_net_SocketOptions_IP_TOS,                IPPROTO_IP,     IP_TOS },
 993         { java_net_SocketOptions_IP_MULTICAST_IF,       IPPROTO_IP,     IP_MULTICAST_IF },
 994         { java_net_SocketOptions_IP_MULTICAST_IF2,      IPPROTO_IP,     IP_MULTICAST_IF },
 995         { java_net_SocketOptions_IP_MULTICAST_LOOP,     IPPROTO_IP,     IP_MULTICAST_LOOP },
 996     };
 997 
 998     int i;
 999 
1000     /*
1001      * Different multicast options if IPv6 is enabled
1002      */
1003 #ifdef AF_INET6
1004     if (ipv6_available()) {
1005         switch (cmd) {
1006             case java_net_SocketOptions_IP_MULTICAST_IF:
1007             case java_net_SocketOptions_IP_MULTICAST_IF2:
1008                 *level = IPPROTO_IPV6;
1009                 *optname = IPV6_MULTICAST_IF;
1010                 return 0;


1365                     if (tcp_max_buf == -1) {
1366                         return -1;
1367                     }
1368                 }
1369                 init_tcp_max_buf = 1;
1370             } else if (!init_udp_max_buf && sotype == SOCK_DGRAM) {
1371                 udp_max_buf = getParam("/dev/udp", "udp_max_buf");
1372                 if (udp_max_buf == -1) {
1373                     udp_max_buf = findMaxBuf(fd, opt, SOCK_DGRAM);
1374                     if (udp_max_buf == -1) {
1375                         return -1;
1376                     }
1377                 }
1378                 init_udp_max_buf = 1;
1379             }
1380 
1381             maxbuf = (sotype == SOCK_STREAM) ? tcp_max_buf : udp_max_buf;
1382             bufsize = (int *)arg;
1383             if (*bufsize > maxbuf) {
1384                 *bufsize = maxbuf;























1385             }
1386         }
1387     }
1388 #endif
1389 
1390     /*
1391      * On Linux the receive buffer is used for both socket
1392      * structures and the the packet payload. The implication
1393      * is that if SO_RCVBUF is too small then small packets
1394      * must be discard.
1395      */
1396 #ifdef __linux__
1397     if (level == SOL_SOCKET && opt == SO_RCVBUF) {
1398         int *bufsize = (int *)arg;
1399         if (*bufsize < 1024) {
1400             *bufsize = 1024;
1401         }
1402     }
1403 #endif
1404 




 970     return 1;
 971 }
 972 
 973 /*
 974  * Map the Java level socket option to the platform specific
 975  * level and option name.
 976  */
 977 int
 978 NET_MapSocketOption(jint cmd, int *level, int *optname) {
 979     static struct {
 980         jint cmd;
 981         int level;
 982         int optname;
 983     } const opts[] = {
 984         { java_net_SocketOptions_TCP_NODELAY,           IPPROTO_TCP,    TCP_NODELAY },
 985         { java_net_SocketOptions_SO_OOBINLINE,          SOL_SOCKET,     SO_OOBINLINE },
 986         { java_net_SocketOptions_SO_LINGER,             SOL_SOCKET,     SO_LINGER },
 987         { java_net_SocketOptions_SO_SNDBUF,             SOL_SOCKET,     SO_SNDBUF },
 988         { java_net_SocketOptions_SO_RCVBUF,             SOL_SOCKET,     SO_RCVBUF },
 989         { java_net_SocketOptions_SO_KEEPALIVE,          SOL_SOCKET,     SO_KEEPALIVE },
 990 #if defined(_AIX)
 991         { java_net_SocketOptions_SO_REUSEADDR,          SOL_SOCKET,     SO_REUSEPORT },
 992 #else
 993         { java_net_SocketOptions_SO_REUSEADDR,          SOL_SOCKET,     SO_REUSEADDR },
 994 #endif
 995         { java_net_SocketOptions_SO_BROADCAST,          SOL_SOCKET,     SO_BROADCAST },
 996         { java_net_SocketOptions_IP_TOS,                IPPROTO_IP,     IP_TOS },
 997         { java_net_SocketOptions_IP_MULTICAST_IF,       IPPROTO_IP,     IP_MULTICAST_IF },
 998         { java_net_SocketOptions_IP_MULTICAST_IF2,      IPPROTO_IP,     IP_MULTICAST_IF },
 999         { java_net_SocketOptions_IP_MULTICAST_LOOP,     IPPROTO_IP,     IP_MULTICAST_LOOP },
1000     };
1001 
1002     int i;
1003 
1004     /*
1005      * Different multicast options if IPv6 is enabled
1006      */
1007 #ifdef AF_INET6
1008     if (ipv6_available()) {
1009         switch (cmd) {
1010             case java_net_SocketOptions_IP_MULTICAST_IF:
1011             case java_net_SocketOptions_IP_MULTICAST_IF2:
1012                 *level = IPPROTO_IPV6;
1013                 *optname = IPV6_MULTICAST_IF;
1014                 return 0;


1369                     if (tcp_max_buf == -1) {
1370                         return -1;
1371                     }
1372                 }
1373                 init_tcp_max_buf = 1;
1374             } else if (!init_udp_max_buf && sotype == SOCK_DGRAM) {
1375                 udp_max_buf = getParam("/dev/udp", "udp_max_buf");
1376                 if (udp_max_buf == -1) {
1377                     udp_max_buf = findMaxBuf(fd, opt, SOCK_DGRAM);
1378                     if (udp_max_buf == -1) {
1379                         return -1;
1380                     }
1381                 }
1382                 init_udp_max_buf = 1;
1383             }
1384 
1385             maxbuf = (sotype == SOCK_STREAM) ? tcp_max_buf : udp_max_buf;
1386             bufsize = (int *)arg;
1387             if (*bufsize > maxbuf) {
1388                 *bufsize = maxbuf;
1389             }
1390         }
1391     }
1392 #endif
1393 
1394 #ifdef _AIX
1395     if (level == SOL_SOCKET) {
1396         if (opt == SO_SNDBUF || opt == SO_RCVBUF) {
1397             /*
1398              * Just try to set the requested size. If it fails we will leave the
1399              * socket option as is. Setting the buffer size means only a hint in
1400              * the jse2/java software layer, see javadoc. In the previous
1401              * solution the buffer has always been truncated to a length of
1402              * 0x100000 Byte, even if the technical limit has not been reached.
1403              * This kind of absolute truncation was unexpected in the jck tests.
1404              */
1405             int ret = setsockopt(fd, level, opt, arg, len);
1406             if ((ret == 0) || (ret == -1 && errno == ENOBUFS)) {
1407                 // Accept failure because of insufficient buffer memory resources.
1408                 return 0;
1409             } else {
1410                 // Deliver all other kinds of errors.
1411                 return ret;
1412             }
1413         }
1414     }
1415 #endif
1416 
1417     /*
1418      * On Linux the receive buffer is used for both socket
1419      * structures and the the packet payload. The implication
1420      * is that if SO_RCVBUF is too small then small packets
1421      * must be discard.
1422      */
1423 #ifdef __linux__
1424     if (level == SOL_SOCKET && opt == SO_RCVBUF) {
1425         int *bufsize = (int *)arg;
1426         if (*bufsize < 1024) {
1427             *bufsize = 1024;
1428         }
1429     }
1430 #endif
1431