jdk/src/solaris/native/sun/nio/ch/Net.c
author simonis
Tue, 26 Nov 2013 16:40:31 +0100
changeset 22597 7515a991bb37
parent 18535 71b74ae0ab8a
child 22604 9b394795e216
permissions -rw-r--r--
8024854: PPC64: Basic changes and files to build the class library on AIX Reviewed-by: alanb, prr, sla, chegar, michaelm, mullan, art Contributed-by: luchsh@linux.vnet.ibm.com, spoole@linux.vnet.ibm.com, thomas.stuefe@sap.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
     2
 * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4814
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#include <sys/types.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#include <sys/socket.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#include <string.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
#include <netinet/in.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
#include <netinet/tcp.h>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
#include "jni.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
#include "jni_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
#include "jvm.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
#include "jlong.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
#include "sun_nio_ch_Net.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
#include "net_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
#include "net_util_md.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
#include "nio_util.h"
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
#include "nio.h"
14025
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
    41
#include "sun_nio_ch_PollArrayWrapper.h"
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    43
#ifdef _AIX
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    44
#include <sys/utsname.h>
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    45
#endif
18535
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    46
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    47
/**
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    48
 * IP_MULTICAST_ALL supported since 2.6.31 but may not be available at
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    49
 * build time.
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    50
 */
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    51
#ifdef __linux__
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    52
  #ifndef IP_MULTICAST_ALL
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    53
  #define IP_MULTICAST_ALL    49
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    54
  #endif
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    55
#endif
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
    56
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    57
#if defined(_ALLBSD_SOURCE) || defined(_AIX)
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    58
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    59
#ifndef IP_BLOCK_SOURCE
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    60
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    61
#if defined(_AIX)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    62
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    63
#define IP_BLOCK_SOURCE                 58   /* Block data from a given source to a given group */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    64
#define IP_UNBLOCK_SOURCE               59   /* Unblock data from a given source to a given group */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    65
#define IP_ADD_SOURCE_MEMBERSHIP        60   /* Join a source-specific group */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    66
#define IP_DROP_SOURCE_MEMBERSHIP       61   /* Leave a source-specific group */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    67
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    68
#else
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    69
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    70
#define IP_ADD_SOURCE_MEMBERSHIP        70   /* join a source-specific group */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    71
#define IP_DROP_SOURCE_MEMBERSHIP       71   /* drop a single source */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    72
#define IP_BLOCK_SOURCE                 72   /* block a source */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    73
#define IP_UNBLOCK_SOURCE               73   /* unblock a source */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    74
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    75
#endif /* _AIX */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    76
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    77
#endif  /* IP_BLOCK_SOURCE */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    78
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    79
#ifndef MCAST_BLOCK_SOURCE
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    80
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    81
#if defined(_AIX)
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    82
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    83
#define MCAST_BLOCK_SOURCE              64
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    84
#define MCAST_UNBLOCK_SOURCE            65
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    85
#define MCAST_JOIN_SOURCE_GROUP         66
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    86
#define MCAST_LEAVE_SOURCE_GROUP        67
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    87
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    88
#else
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    89
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    90
#define MCAST_JOIN_SOURCE_GROUP         82   /* join a source-specific group */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    91
#define MCAST_LEAVE_SOURCE_GROUP        83   /* leave a single source */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    92
#define MCAST_BLOCK_SOURCE              84   /* block a source */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    93
#define MCAST_UNBLOCK_SOURCE            85   /* unblock a source */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    94
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    95
#endif /* _AIX */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
    96
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    97
#endif /* MCAST_BLOCK_SOURCE */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    98
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
    99
#ifndef IPV6_ADD_MEMBERSHIP
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   100
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   101
#define IPV6_ADD_MEMBERSHIP     IPV6_JOIN_GROUP
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   102
#define IPV6_DROP_MEMBERSHIP    IPV6_LEAVE_GROUP
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   103
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   104
#endif /* IPV6_ADD_MEMBERSHIP */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   105
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   106
struct my_ip_mreq_source {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   107
        struct in_addr  imr_multiaddr;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   108
        struct in_addr  imr_interface;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   109
        struct in_addr  imr_sourceaddr;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   110
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   111
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   112
struct my_group_source_req {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   113
        uint32_t                gsr_interface;  /* interface index */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   114
        struct sockaddr_storage gsr_group;      /* group address */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   115
        struct sockaddr_storage gsr_source;     /* source address */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   116
};
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   117
13363
065e0e3545a3 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents: 12047
diff changeset
   118
#else   /* _ALLBSD_SOURCE */
065e0e3545a3 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents: 12047
diff changeset
   119
065e0e3545a3 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents: 12047
diff changeset
   120
#define my_ip_mreq_source         ip_mreq_source
065e0e3545a3 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents: 12047
diff changeset
   121
#define my_group_source_req       group_source_req
065e0e3545a3 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents: 12047
diff changeset
   122
065e0e3545a3 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents: 12047
diff changeset
   123
#endif
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   124
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   125
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   126
#define COPY_INET6_ADDRESS(env, source, target) \
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   127
    (*env)->GetByteArrayRegion(env, source, 0, 16, target)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   128
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   129
/*
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   130
 * Copy IPv6 group, interface index, and IPv6 source address
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   131
 * into group_source_req structure.
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   132
 */
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   133
#ifdef AF_INET6
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   134
static void initGroupSourceReq(JNIEnv* env, jbyteArray group, jint index,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   135
                               jbyteArray source, struct my_group_source_req* req)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   136
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   137
    struct sockaddr_in6* sin6;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   138
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   139
    req->gsr_interface = (uint32_t)index;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   140
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   141
    sin6 = (struct sockaddr_in6*)&(req->gsr_group);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   142
    sin6->sin6_family = AF_INET6;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   143
    COPY_INET6_ADDRESS(env, group, (jbyte*)&(sin6->sin6_addr));
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   144
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   145
    sin6 = (struct sockaddr_in6*)&(req->gsr_source);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   146
    sin6->sin6_family = AF_INET6;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   147
    COPY_INET6_ADDRESS(env, source, (jbyte*)&(sin6->sin6_addr));
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   148
}
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   149
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   151
#ifdef _AIX
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   152
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   153
/*
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   154
 * Checks whether or not "socket extensions for multicast source filters" is supported.
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   155
 * Returns JNI_TRUE if it is supported, JNI_FALSE otherwise
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   156
 */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   157
static jboolean isSourceFilterSupported(){
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   158
    static jboolean alreadyChecked = JNI_FALSE;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   159
    static jboolean result = JNI_TRUE;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   160
    if (alreadyChecked != JNI_TRUE){
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   161
        struct utsname uts;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   162
        memset(&uts, 0, sizeof(uts));
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   163
        strcpy(uts.sysname, "?");
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   164
        const int utsRes = uname(&uts);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   165
        int major = -1;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   166
        int minor = -1;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   167
        major = atoi(uts.version);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   168
        minor = atoi(uts.release);
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   169
        if (strcmp(uts.sysname, "AIX") == 0) {
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   170
            if (major < 6 || (major == 6 && minor < 1)) {// unsupported on aix < 6.1
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   171
                result = JNI_FALSE;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   172
            }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   173
        }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   174
        alreadyChecked = JNI_TRUE;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   175
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   176
    return result;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   177
}
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   178
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   179
#endif  /* _AIX */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   180
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
JNIEXPORT void JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
Java_sun_nio_ch_Net_initIDs(JNIEnv *env, jclass clazz)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
    /* Here because Windows native code does need to init IDs */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   187
JNIEXPORT jboolean JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   188
Java_sun_nio_ch_Net_isIPv6Available0(JNIEnv* env, jclass cl)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   189
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   190
    return (ipv6_available()) ? JNI_TRUE : JNI_FALSE;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   191
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   192
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   193
JNIEXPORT jint JNICALL
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   194
Java_sun_nio_ch_Net_isExclusiveBindAvailable(JNIEnv *env, jclass clazz) {
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   195
    return -1;
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   196
}
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   197
8788
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   198
JNIEXPORT jboolean JNICALL
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   199
Java_sun_nio_ch_Net_canIPv6SocketJoinIPv4Group0(JNIEnv* env, jclass cl)
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   200
{
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   201
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   202
    /* for now IPv6 sockets cannot join IPv4 multicast groups */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   203
    return JNI_FALSE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   204
#else
8788
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   205
    return JNI_TRUE;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   206
#endif
8788
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   207
}
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   208
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   209
JNIEXPORT jboolean JNICALL
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   210
Java_sun_nio_ch_Net_canJoin6WithIPv4Group0(JNIEnv* env, jclass cl)
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   211
{
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   212
#ifdef __solaris__
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   213
    return JNI_TRUE;
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   214
#else
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   215
    return JNI_FALSE;
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   216
#endif
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   217
}
b98f18278dc4 7026376: (dc) DatagramChannel created without specifying protocol family fails to join IPv4 group
alanb
parents: 7668
diff changeset
   218
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
JNIEXPORT int JNICALL
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   220
Java_sun_nio_ch_Net_socket0(JNIEnv *env, jclass cl, jboolean preferIPv6,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   221
                            jboolean stream, jboolean reuse)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    int fd;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   224
    int type = (stream ? SOCK_STREAM : SOCK_DGRAM);
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   225
#ifdef AF_INET6
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   226
    int domain = (ipv6_available() && preferIPv6) ? AF_INET6 : AF_INET;
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   227
#else
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   228
    int domain = AF_INET;
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   229
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   231
    fd = socket(domain, type, 0);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    if (fd < 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        return handleSocketError(env, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    }
6299
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   235
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   236
#ifdef AF_INET6
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   237
    /* Disable IPV6_V6ONLY to ensure dual-socket support */
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   238
    if (domain == AF_INET6) {
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   239
        int arg = 0;
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   240
        if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, (char*)&arg,
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   241
                       sizeof(int)) < 0) {
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   242
            JNU_ThrowByNameWithLastError(env,
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   243
                                         JNU_JAVANETPKG "SocketException",
18535
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   244
                                         "Unable to set IPV6_V6ONLY");
6299
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   245
            close(fd);
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   246
            return -1;
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   247
        }
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   248
    }
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   249
#endif
a44d48dbcd50 6882910: Unexplained lack of IP4 network ability when transparent IP6 to IP4 is disabled.
chegar
parents: 5506
diff changeset
   250
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    if (reuse) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
        int arg = 1;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   253
        if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, (char*)&arg,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   254
                       sizeof(arg)) < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            JNU_ThrowByNameWithLastError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
                                         JNU_JAVANETPKG "SocketException",
18535
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   257
                                         "Unable to set SO_REUSEADDR");
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   258
            close(fd);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   259
            return -1;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
18535
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   262
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   263
#if defined(__linux__)
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   264
    if (type == SOCK_DGRAM) {
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   265
        int arg = 0;
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   266
        int level = (domain == AF_INET6) ? IPPROTO_IPV6 : IPPROTO_IP;
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   267
        if ((setsockopt(fd, level, IP_MULTICAST_ALL, (char*)&arg, sizeof(arg)) < 0) &&
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   268
            (errno != ENOPROTOOPT)) {
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   269
            JNU_ThrowByNameWithLastError(env,
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   270
                                         JNU_JAVANETPKG "SocketException",
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   271
                                         "Unable to set IP_MULTICAST_ALL");
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   272
            close(fd);
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   273
            return -1;
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   274
        }
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   275
    }
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   276
#endif
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   277
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   278
#if defined(__linux__) && defined(AF_INET6)
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   279
    /* By default, Linux uses the route default */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   280
    if (domain == AF_INET6 && type == SOCK_DGRAM) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   281
        int arg = 1;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   282
        if (setsockopt(fd, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &arg,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   283
                       sizeof(arg)) < 0) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   284
            JNU_ThrowByNameWithLastError(env,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   285
                                         JNU_JAVANETPKG "SocketException",
18535
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   286
                                         "Unable to set IPV6_MULTICAST_HOPS");
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   287
            close(fd);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   288
            return -1;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   289
        }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   290
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   291
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
    return fd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
JNIEXPORT void JNICALL
18192
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   296
Java_sun_nio_ch_Net_bind0(JNIEnv *env, jclass clazz, jobject fdo, jboolean preferIPv6,
fa6bd0992104 7170730: Improve Windows network stack support.
khazra
parents: 14342
diff changeset
   297
                          jboolean useExclBind, jobject iao, int port)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
    SOCKADDR sa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    int sa_len = SOCKADDR_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    int rv = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   303
    if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *)&sa, &sa_len, preferIPv6) != 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
      return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
    rv = NET_Bind(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    if (rv != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        handleSocketError(env, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   313
JNIEXPORT void JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   314
Java_sun_nio_ch_Net_listen(JNIEnv *env, jclass cl, jobject fdo, jint backlog)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   315
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   316
    if (listen(fdval(env, fdo), backlog) < 0)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   317
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   318
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   319
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
JNIEXPORT jint JNICALL
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   321
Java_sun_nio_ch_Net_connect0(JNIEnv *env, jclass clazz, jboolean preferIPv6,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   322
                             jobject fdo, jobject iao, jint port)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
    SOCKADDR sa;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    int sa_len = SOCKADDR_LEN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
    int rv;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   328
    if (NET_InetAddressToSockaddr(env, iao, port, (struct sockaddr *) &sa,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   329
                                  &sa_len, preferIPv6) != 0)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   330
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
      return IOS_THROWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
    rv = connect(fdval(env, fdo), (struct sockaddr *)&sa, sa_len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
    if (rv != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
        if (errno == EINPROGRESS) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
            return IOS_UNAVAILABLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
        } else if (errno == EINTR) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
            return IOS_INTERRUPTED;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        return handleSocketError(env, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    return 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
JNIEXPORT jint JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
Java_sun_nio_ch_Net_localPort(JNIEnv *env, jclass clazz, jobject fdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
    SOCKADDR sa;
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
   350
    socklen_t sa_len = SOCKADDR_LEN;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
    if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   352
#ifdef _ALLBSD_SOURCE
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   353
        /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   354
         * XXXBSD:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   355
         * ECONNRESET is specific to the BSDs. We can not return an error,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   356
         * as the calling Java code with raise a java.lang.Error given the expectation
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   357
         * that getsockname() will never fail. According to the Single UNIX Specification,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   358
         * it shouldn't fail. As such, we just fill in generic Linux-compatible values.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   359
         */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   360
        if (errno == ECONNRESET) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   361
            struct sockaddr_in *sin;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   362
            sin = (struct sockaddr_in *) &sa;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   363
            bzero(sin, sizeof(*sin));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   364
            sin->sin_len  = sizeof(struct sockaddr_in);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   365
            sin->sin_family = AF_INET;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   366
            sin->sin_port = htonl(0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   367
            sin->sin_addr.s_addr = INADDR_ANY;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   368
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   369
            handleSocketError(env, errno);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   370
            return -1;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   371
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   372
#else /* _ALLBSD_SOURCE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
        handleSocketError(env, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
        return -1;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   375
#endif /* _ALLBSD_SOURCE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    return NET_GetPortFromSockaddr((struct sockaddr *)&sa);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
JNIEXPORT jobject JNICALL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
Java_sun_nio_ch_Net_localInetAddress(JNIEnv *env, jclass clazz, jobject fdo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
    SOCKADDR sa;
895
67f1dc69ad10 6726309: Compiler warnings in nio code
alanb
parents: 2
diff changeset
   384
    socklen_t sa_len = SOCKADDR_LEN;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
    int port;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    if (getsockname(fdval(env, fdo), (struct sockaddr *)&sa, &sa_len) < 0) {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   387
#ifdef _ALLBSD_SOURCE
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   388
        /*
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   389
         * XXXBSD:
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   390
         * ECONNRESET is specific to the BSDs. We can not return an error,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   391
         * as the calling Java code with raise a java.lang.Error with the expectation
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   392
         * that getsockname() will never fail. According to the Single UNIX Specification,
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   393
         * it shouldn't fail. As such, we just fill in generic Linux-compatible values.
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   394
         */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   395
        if (errno == ECONNRESET) {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   396
            struct sockaddr_in *sin;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   397
            sin = (struct sockaddr_in *) &sa;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   398
            bzero(sin, sizeof(*sin));
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   399
            sin->sin_len  = sizeof(struct sockaddr_in);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   400
            sin->sin_family = AF_INET;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   401
            sin->sin_port = htonl(0);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   402
            sin->sin_addr.s_addr = INADDR_ANY;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   403
        } else {
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   404
            handleSocketError(env, errno);
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   405
            return NULL;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   406
        }
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   407
#else /* _ALLBSD_SOURCE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
        handleSocketError(env, errno);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
        return NULL;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   410
#endif /* _ALLBSD_SOURCE */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
    return NET_SockaddrToInetAddress(env, (struct sockaddr *)&sa, &port);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   415
JNIEXPORT jint JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   416
Java_sun_nio_ch_Net_getIntOption0(JNIEnv *env, jclass clazz, jobject fdo,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   417
                                  jboolean mayNeedConversion, jint level, jint opt)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
{
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   419
    int result;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   420
    struct linger linger;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   421
    u_char carg;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   422
    void *arg;
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6299
diff changeset
   423
    socklen_t arglen;
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6299
diff changeset
   424
    int n;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   426
    /* Option value is an int except for a few specific cases */
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   427
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   428
    arg = (void *)&result;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   429
    arglen = sizeof(result);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   431
    if (level == IPPROTO_IP &&
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   432
        (opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   433
        arg = (void*)&carg;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   434
        arglen = sizeof(carg);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   437
    if (level == SOL_SOCKET && opt == SO_LINGER) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   438
        arg = (void *)&linger;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   439
        arglen = sizeof(linger);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   442
    if (mayNeedConversion) {
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6299
diff changeset
   443
        n = NET_GetSockOpt(fdval(env, fdo), level, opt, arg, (int*)&arglen);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   444
    } else {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   445
        n = getsockopt(fdval(env, fdo), level, opt, arg, &arglen);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
    }
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   447
    if (n < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
        JNU_ThrowByNameWithLastError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
                                     JNU_JAVANETPKG "SocketException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
                                     "sun.nio.ch.Net.getIntOption");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        return -1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   454
    if (level == IPPROTO_IP &&
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   455
        (opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP))
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   456
    {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   457
        return (jint)carg;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   458
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   459
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   460
    if (level == SOL_SOCKET && opt == SO_LINGER)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   461
        return linger.l_onoff ? (jint)linger.l_linger : (jint)-1;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   462
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   463
    return (jint)result;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
JNIEXPORT void JNICALL
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   467
Java_sun_nio_ch_Net_setIntOption0(JNIEnv *env, jclass clazz, jobject fdo,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   468
                                  jboolean mayNeedConversion, jint level, jint opt, jint arg)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    int result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
    struct linger linger;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   472
    u_char carg;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    void *parg;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   474
    socklen_t arglen;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   475
    int n;
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   476
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   477
    /* Option value is an int except for a few specific cases */
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   479
    parg = (void*)&arg;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   480
    arglen = sizeof(arg);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   481
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   482
    if (level == IPPROTO_IP &&
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   483
        (opt == IP_MULTICAST_TTL || opt == IP_MULTICAST_LOOP)) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   484
        parg = (void*)&carg;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   485
        arglen = sizeof(carg);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   486
        carg = (u_char)arg;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   489
    if (level == SOL_SOCKET && opt == SO_LINGER) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
        parg = (void *)&linger;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        arglen = sizeof(linger);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
        if (arg >= 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
            linger.l_onoff = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
            linger.l_linger = arg;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
            linger.l_onoff = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            linger.l_linger = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   501
    if (mayNeedConversion) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   502
        n = NET_SetSockOpt(fdval(env, fdo), level, opt, parg, arglen);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   503
    } else {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   504
        n = setsockopt(fdval(env, fdo), level, opt, parg, arglen);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   505
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   506
    if (n < 0) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
        JNU_ThrowByNameWithLastError(env,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                                     JNU_JAVANETPKG "SocketException",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                                     "sun.nio.ch.Net.setIntOption");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   513
JNIEXPORT jint JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   514
Java_sun_nio_ch_Net_joinOrDrop4(JNIEnv *env, jobject this, jboolean join, jobject fdo,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   515
                                jint group, jint interf, jint source)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   516
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   517
    struct ip_mreq mreq;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   518
    struct my_ip_mreq_source mreq_source;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   519
    int opt, n, optlen;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   520
    void* optval;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   522
    if (source == 0) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   523
        mreq.imr_multiaddr.s_addr = htonl(group);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   524
        mreq.imr_interface.s_addr = htonl(interf);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   525
        opt = (join) ? IP_ADD_MEMBERSHIP : IP_DROP_MEMBERSHIP;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   526
        optval = (void*)&mreq;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   527
        optlen = sizeof(mreq);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   528
    } else {
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   529
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   530
        /* no IPv4 include-mode filtering for now */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   531
        return IOS_UNAVAILABLE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   532
#else
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   533
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   534
#ifdef _AIX
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   535
        /* check AIX for support of source filtering */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   536
        if (isSourceFilterSupported() != JNI_TRUE){
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   537
            return IOS_UNAVAILABLE;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   538
        }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   539
#endif
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   540
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   541
        mreq_source.imr_multiaddr.s_addr = htonl(group);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   542
        mreq_source.imr_sourceaddr.s_addr = htonl(source);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   543
        mreq_source.imr_interface.s_addr = htonl(interf);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   544
        opt = (join) ? IP_ADD_SOURCE_MEMBERSHIP : IP_DROP_SOURCE_MEMBERSHIP;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   545
        optval = (void*)&mreq_source;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   546
        optlen = sizeof(mreq_source);
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   547
#endif
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   548
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   549
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   550
    n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt, optval, optlen);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   551
    if (n < 0) {
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   552
        if (join && (errno == ENOPROTOOPT || errno == EOPNOTSUPP))
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   553
            return IOS_UNAVAILABLE;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   554
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   555
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   556
    return 0;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   557
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   558
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   559
JNIEXPORT jint JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   560
Java_sun_nio_ch_Net_blockOrUnblock4(JNIEnv *env, jobject this, jboolean block, jobject fdo,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   561
                                    jint group, jint interf, jint source)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   562
{
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   563
#ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   564
    /* no IPv4 exclude-mode filtering for now */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   565
    return IOS_UNAVAILABLE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   566
#else
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   567
    struct my_ip_mreq_source mreq_source;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   568
    int n;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   569
    int opt = (block) ? IP_BLOCK_SOURCE : IP_UNBLOCK_SOURCE;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   570
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   571
#ifdef _AIX
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   572
    /* check AIX for support of source filtering */
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   573
    if (isSourceFilterSupported() != JNI_TRUE){
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   574
        return IOS_UNAVAILABLE;
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   575
    }
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   576
#endif
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   577
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   578
    mreq_source.imr_multiaddr.s_addr = htonl(group);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   579
    mreq_source.imr_sourceaddr.s_addr = htonl(source);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   580
    mreq_source.imr_interface.s_addr = htonl(interf);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   581
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   582
    n = setsockopt(fdval(env,fdo), IPPROTO_IP, opt,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   583
                   (void*)&mreq_source, sizeof(mreq_source));
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   584
    if (n < 0) {
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   585
        if (block && (errno == ENOPROTOOPT || errno == EOPNOTSUPP))
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   586
            return IOS_UNAVAILABLE;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   587
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   588
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   589
    return 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   590
#endif
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   591
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   592
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   593
JNIEXPORT jint JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   594
Java_sun_nio_ch_Net_joinOrDrop6(JNIEnv *env, jobject this, jboolean join, jobject fdo,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   595
                                jbyteArray group, jint index, jbyteArray source)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   596
{
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   597
#ifdef AF_INET6
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   598
    struct ipv6_mreq mreq6;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   599
    struct my_group_source_req req;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   600
    int opt, n, optlen;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   601
    void* optval;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   602
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   603
    if (source == NULL) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   604
        COPY_INET6_ADDRESS(env, group, (jbyte*)&(mreq6.ipv6mr_multiaddr));
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   605
        mreq6.ipv6mr_interface = (int)index;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   606
        opt = (join) ? IPV6_ADD_MEMBERSHIP : IPV6_DROP_MEMBERSHIP;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   607
        optval = (void*)&mreq6;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   608
        optlen = sizeof(mreq6);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   609
    } else {
13363
065e0e3545a3 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents: 12047
diff changeset
   610
#ifdef MACOSX
065e0e3545a3 6633549: (dc) Include-mode filtering of IPv6 sources does not block datagrams on Linux
alanb
parents: 12047
diff changeset
   611
        /* no IPv6 include-mode filtering for now */
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   612
        return IOS_UNAVAILABLE;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   613
#else
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   614
        initGroupSourceReq(env, group, index, source, &req);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   615
        opt = (join) ? MCAST_JOIN_SOURCE_GROUP : MCAST_LEAVE_SOURCE_GROUP;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   616
        optval = (void*)&req;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   617
        optlen = sizeof(req);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   618
#endif
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   619
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   620
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   621
    n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt, optval, optlen);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   622
    if (n < 0) {
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   623
        if (join && (errno == ENOPROTOOPT || errno == EOPNOTSUPP))
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   624
            return IOS_UNAVAILABLE;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   625
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   626
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   627
    return 0;
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   628
#else
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   629
    JNU_ThrowInternalError(env, "Should not get here");
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   630
    return IOS_THROWN;
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   631
#endif  /* AF_INET6 */
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   632
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   633
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   634
JNIEXPORT jint JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   635
Java_sun_nio_ch_Net_blockOrUnblock6(JNIEnv *env, jobject this, jboolean block, jobject fdo,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   636
                                    jbyteArray group, jint index, jbyteArray source)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   637
{
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   638
#ifdef AF_INET6
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   639
  #ifdef MACOSX
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   640
    /* no IPv6 exclude-mode filtering for now */
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   641
    return IOS_UNAVAILABLE;
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   642
  #else
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   643
    struct my_group_source_req req;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   644
    int n;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   645
    int opt = (block) ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   646
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   647
    initGroupSourceReq(env, group, index, source, &req);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   648
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   649
    n = setsockopt(fdval(env,fdo), IPPROTO_IPV6, opt,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   650
        (void*)&req, sizeof(req));
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   651
    if (n < 0) {
22597
7515a991bb37 8024854: PPC64: Basic changes and files to build the class library on AIX
simonis
parents: 18535
diff changeset
   652
        if (block && (errno == ENOPROTOOPT || errno == EOPNOTSUPP))
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   653
            return IOS_UNAVAILABLE;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   654
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   655
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   656
    return 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   657
  #endif
4814
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   658
#else
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   659
    JNU_ThrowInternalError(env, "Should not get here");
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   660
    return IOS_THROWN;
dbf72872f8d2 6905552: libnet/nio portability issues
chegar
parents: 3486
diff changeset
   661
#endif
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   662
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   663
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   664
JNIEXPORT void JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   665
Java_sun_nio_ch_Net_setInterface4(JNIEnv* env, jobject this, jobject fdo, jint interf)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   666
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   667
    struct in_addr in;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   668
    socklen_t arglen = sizeof(struct in_addr);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   669
    int n;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   670
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   671
    in.s_addr = htonl(interf);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   672
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   673
    n = setsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   674
                   (void*)&(in.s_addr), arglen);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   675
    if (n < 0) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   676
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   677
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   678
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   679
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   680
JNIEXPORT jint JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   681
Java_sun_nio_ch_Net_getInterface4(JNIEnv* env, jobject this, jobject fdo)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   682
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   683
    struct in_addr in;
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6299
diff changeset
   684
    socklen_t arglen = sizeof(struct in_addr);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   685
    int n;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   686
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   687
    n = getsockopt(fdval(env, fdo), IPPROTO_IP, IP_MULTICAST_IF, (void*)&in, &arglen);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   688
    if (n < 0) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   689
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   690
        return -1;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   691
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   692
    return ntohl(in.s_addr);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   693
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   694
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   695
JNIEXPORT void JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   696
Java_sun_nio_ch_Net_setInterface6(JNIEnv* env, jobject this, jobject fdo, jint index)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   697
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   698
    int value = (jint)index;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   699
    socklen_t arglen = sizeof(value);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   700
    int n;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   701
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   702
    n = setsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF,
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   703
                   (void*)&(index), arglen);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   704
    if (n < 0) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   705
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   706
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   707
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   708
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   709
JNIEXPORT jint JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   710
Java_sun_nio_ch_Net_getInterface6(JNIEnv* env, jobject this, jobject fdo)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   711
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   712
    int index;
6850
56966b0a6a0d 6989466: Miscellaneous compiler warnings in java/lang, java/util, java/io, sun/misc native code
alanb
parents: 6299
diff changeset
   713
    socklen_t arglen = sizeof(index);
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   714
    int n;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   715
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   716
    n = getsockopt(fdval(env, fdo), IPPROTO_IPV6, IPV6_MULTICAST_IF, (void*)&index, &arglen);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   717
    if (n < 0) {
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   718
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   719
        return -1;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   720
    }
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   721
    return (jint)index;
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   722
}
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   723
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   724
JNIEXPORT void JNICALL
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   725
Java_sun_nio_ch_Net_shutdown(JNIEnv *env, jclass cl, jobject fdo, jint jhow)
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   726
{
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   727
    int how = (jhow == sun_nio_ch_Net_SHUT_RD) ? SHUT_RD :
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   728
        (jhow == sun_nio_ch_Net_SHUT_WR) ? SHUT_WR : SHUT_RDWR;
3486
0e14ae32369e 4516760: (so) Intermittent SocketException: Transport endpoint is not connected (lnx)
alanb
parents: 1247
diff changeset
   729
    if ((shutdown(fdval(env, fdo), how) < 0) && (errno != ENOTCONN))
1152
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   730
        handleSocketError(env, errno);
29d6145d1097 4640544: New I/O: Complete socket-channel functionality
alanb
parents: 895
diff changeset
   731
}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   732
14025
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   733
JNIEXPORT jint JNICALL
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   734
Java_sun_nio_ch_Net_poll(JNIEnv* env, jclass this, jobject fdo, jint events, jlong timeout)
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   735
{
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   736
    struct pollfd pfd;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   737
    int rv;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   738
    pfd.fd = fdval(env, fdo);
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   739
    pfd.events = events;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   740
    rv = poll(&pfd, 1, timeout);
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   741
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   742
    if (rv >= 0) {
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   743
        return pfd.revents;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   744
    } else if (errno == EINTR) {
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   745
        return IOS_INTERRUPTED;
18535
71b74ae0ab8a 8014377: (dc) DatagramChannel should set IP_MULTICAST_ALL=0 (lnx)
alanb
parents: 18192
diff changeset
   746
    } else {
14025
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   747
        handleSocketError(env, errno);
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   748
        return IOS_THROWN;
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   749
    }
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   750
}
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   751
fbebe005a3ee 7184932: Remove the temporary Selector usage in the NIO socket adapters
robm
parents: 13363
diff changeset
   752
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   753
/* Declared in nio_util.h */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   754
90ce3da70b43 Initial load
duke
parents:
diff changeset
   755
jint
90ce3da70b43 Initial load
duke
parents:
diff changeset
   756
handleSocketError(JNIEnv *env, jint errorValue)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   757
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
   758
    char *xn;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   759
    switch (errorValue) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   760
        case EINPROGRESS:       /* Non-blocking connect */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   761
            return 0;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   762
#ifdef EPROTO
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   763
        case EPROTO:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   764
            xn = JNU_JAVANETPKG "ProtocolException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   765
            break;
12047
320a714614e9 7113349: Initial changeset for Macosx port to jdk
michaelm
parents: 9035
diff changeset
   766
#endif
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   767
        case ECONNREFUSED:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
            xn = JNU_JAVANETPKG "ConnectException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   770
        case ETIMEDOUT:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   771
            xn = JNU_JAVANETPKG "ConnectException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   772
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   773
        case EHOSTUNREACH:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   774
            xn = JNU_JAVANETPKG "NoRouteToHostException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   775
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   776
        case EADDRINUSE:  /* Fall through */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   777
        case EADDRNOTAVAIL:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
            xn = JNU_JAVANETPKG "BindException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
        default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
            xn = JNU_JAVANETPKG "SocketException";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            break;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
    errno = errorValue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
    JNU_ThrowByNameWithLastError(env, xn, "NioSocketError");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
    return IOS_THROWN;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
}