Example #1
0
        public static int accept0(object _this, FileDescriptor ssfd, FileDescriptor newfd, object isaa)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                System.Net.Sockets.Socket netSocket = ssfd.getSocket();
                if (netSocket.Blocking || netSocket.Poll(0, System.Net.Sockets.SelectMode.SelectRead))
                {
                    System.Net.Sockets.Socket accsock = netSocket.Accept();
                    newfd.setSocket(accsock);
                    System.Net.IPEndPoint ep = (System.Net.IPEndPoint)accsock.RemoteEndPoint;
                    ((global::java.net.InetSocketAddress[])isaa)[0] = new global::java.net.InetSocketAddress(global::java.net.SocketUtil.getInetAddressFromIPEndPoint(ep), ep.Port);
                    return(1);
                }
                else
                {
                    return(global::sun.nio.ch.IOStatus.UNAVAILABLE);
                }
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
            }
            catch (System.ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
#endif
        }
Example #2
0
        public static FileDescriptor socket0(bool preferIPv6, bool stream, bool reuse)
        {
#if FIRST_PASS
            return(null);
#else
            try
            {
                System.Net.Sockets.AddressFamily addressFamily = preferIPv6
                                        ? System.Net.Sockets.AddressFamily.InterNetworkV6
                                        : System.Net.Sockets.AddressFamily.InterNetwork;
                System.Net.Sockets.SocketType socketType = stream
                                        ? System.Net.Sockets.SocketType.Stream
                                        : System.Net.Sockets.SocketType.Dgram;
                System.Net.Sockets.ProtocolType protocolType = stream
                                        ? System.Net.Sockets.ProtocolType.Tcp
                                        : System.Net.Sockets.ProtocolType.Udp;
                System.Net.Sockets.Socket socket = new System.Net.Sockets.Socket(addressFamily, socketType, protocolType);
                if (preferIPv6)
                {
                    // enable IPv4 over IPv6 sockets (note that we don't have to check for >= Vista here, because nio sockets only support IPv6 on >= Vista)
                    const System.Net.Sockets.SocketOptionName IPV6_V6ONLY = (System.Net.Sockets.SocketOptionName) 27;
                    socket.SetSocketOption(System.Net.Sockets.SocketOptionLevel.IPv6, IPV6_V6ONLY, 0);
                }
                if (!stream)
                {
                    setConnectionReset(socket, false);
                }
                FileDescriptor fd = new FileDescriptor();
                fd.setSocket(socket);
                return(fd);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
            }
#endif
        }