コード例 #1
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int connect0(bool preferIPv6, FileDescriptor fd, InetAddress remote, int remotePort)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                System.Net.IPEndPoint ep = new System.Net.IPEndPoint(global::java.net.SocketUtil.getAddressFromInetAddress(remote, preferIPv6), remotePort);
                bool datagram            = fd.getSocket().SocketType == System.Net.Sockets.SocketType.Dgram;
                if (datagram || fd.isSocketBlocking())
                {
                    fd.getSocket().Connect(ep);
                    if (datagram)
                    {
                        setConnectionReset(fd.getSocket(), true);
                    }
                    return(1);
                }
                else
                {
                    fd.setAsyncResult(fd.getSocket().BeginConnect(ep, null, null));
                    return(global::sun.nio.ch.IOStatus.UNAVAILABLE);
                }
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw new global::java.net.ConnectException(x.Message);
            }
            catch (System.ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
#endif
        }
コード例 #2
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int checkConnect(FileDescriptor fd, bool block, bool ready)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                IAsyncResult asyncConnect = fd.getAsyncResult();
                if (block || ready || asyncConnect.IsCompleted)
                {
                    fd.setAsyncResult(null);
                    fd.getSocket().EndConnect(asyncConnect);
                    // work around for blocking issue
                    fd.getSocket().Blocking = fd.isSocketBlocking();
                    return(1);
                }
                else
                {
                    return(global::sun.nio.ch.IOStatus.UNAVAILABLE);
                }
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw new global::java.net.ConnectException(x.Message);
            }
            catch (System.ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
#endif
        }
コード例 #3
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int blockOrUnblock4(bool block, FileDescriptor fd, int group, int interf, int source)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                // ip_mreq_source
                byte[] optionValue = new byte[12];
                PutInt(optionValue, 0, group);
                PutInt(optionValue, 4, source);
                PutInt(optionValue, 8, interf);
                fd.getSocket().SetSocketOption(System.Net.Sockets.SocketOptionLevel.IP,
                                               block ? System.Net.Sockets.SocketOptionName.BlockSource : System.Net.Sockets.SocketOptionName.UnblockSource,
                                               optionValue);
                return(0);
            }
            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
        }
コード例 #4
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int blockOrUnblock6(bool block, FileDescriptor fd, byte[] group, int index, byte[] source)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                const System.Net.Sockets.SocketOptionName MCAST_BLOCK_SOURCE   = (System.Net.Sockets.SocketOptionName) 43;
                const System.Net.Sockets.SocketOptionName MCAST_UNBLOCK_SOURCE = (System.Net.Sockets.SocketOptionName) 44;
                // group_source_req
                byte[] optionValue = new byte[264];
                optionValue[0] = (byte)index;
                optionValue[1] = (byte)(index >> 8);
                optionValue[2] = (byte)(index >> 16);
                optionValue[3] = (byte)(index >> 24);
                PutSockAddrIn6(optionValue, 8, group);
                PutSockAddrIn6(optionValue, 136, source);
                fd.getSocket().SetSocketOption(System.Net.Sockets.SocketOptionLevel.IPv6, block ? MCAST_BLOCK_SOURCE : MCAST_UNBLOCK_SOURCE, optionValue);
                return(0);
            }
            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
        }
コード例 #5
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        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
        }
コード例 #6
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static long write(object nd, FileDescriptor fd, ByteBuffer[] bufs, int offset, int length)
        {
#if FIRST_PASS
            return(0);
#else
            ByteBuffer[] altBufs             = null;
            List <ArraySegment <byte> > list = new List <ArraySegment <byte> >(length);
            for (int i = 0; i < length; i++)
            {
                ByteBuffer bb = bufs[i + offset];
                if (!bb.hasArray())
                {
                    if (altBufs == null)
                    {
                        altBufs = new ByteBuffer[bufs.Length];
                    }
                    ByteBuffer abb = ByteBuffer.allocate(bb.remaining());
                    int        pos = bb.position();
                    abb.put(bb);
                    bb.position(pos);
                    abb.flip();
                    bb = altBufs[i + offset] = abb;
                }
                list.Add(new ArraySegment <byte>(bb.array(), bb.arrayOffset() + bb.position(), bb.remaining()));
            }
            int count;
            try
            {
                count = fd.getSocket().Send(list);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                if (x.ErrorCode == global::java.net.SocketUtil.WSAEWOULDBLOCK)
                {
                    count = 0;
                }
                else
                {
                    throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
                }
            }
            catch (ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
            int total = count;
            for (int i = 0; total > 0 && i < length; i++)
            {
                ByteBuffer bb       = bufs[i + offset];
                int        consumed = Math.Min(total, bb.remaining());
                bb.position(bb.position() + consumed);
                total -= consumed;
            }
            return(count);
#endif
        }
コード例 #7
0
ファイル: sun.nio.ch.cs プロジェクト: moayyaed/ikvm
        public static void bind0(FileDescriptor fd, bool preferIPv6, bool useExclBind, InetAddress addr, int port)
        {
#if !FIRST_PASS
            try
            {
                if (useExclBind)
                {
                    global::java.net.net_util_md.setExclusiveBind(fd.getSocket());
                }
                fd.getSocket().Bind(new System.Net.IPEndPoint(global::java.net.SocketUtil.getAddressFromInetAddress(addr, preferIPv6), port));
            }
            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
        }
コード例 #8
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int joinOrDrop6(bool join, FileDescriptor fd, byte[] group, int index, byte[] source)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                if (source == null)
                {
                    fd.getSocket().SetSocketOption(System.Net.Sockets.SocketOptionLevel.IPv6,
                                                   join ? System.Net.Sockets.SocketOptionName.AddMembership : System.Net.Sockets.SocketOptionName.DropMembership,
                                                   new System.Net.Sockets.IPv6MulticastOption(new System.Net.IPAddress(group), index));
                }
                else
                {
                    const System.Net.Sockets.SocketOptionName MCAST_JOIN_SOURCE_GROUP  = (System.Net.Sockets.SocketOptionName) 45;
                    const System.Net.Sockets.SocketOptionName MCAST_LEAVE_SOURCE_GROUP = (System.Net.Sockets.SocketOptionName) 46;
                    // group_source_req
                    byte[] optionValue = new byte[264];
                    optionValue[0] = (byte)index;
                    optionValue[1] = (byte)(index >> 8);
                    optionValue[2] = (byte)(index >> 16);
                    optionValue[3] = (byte)(index >> 24);
                    PutSockAddrIn6(optionValue, 8, group);
                    PutSockAddrIn6(optionValue, 136, source);
                    fd.getSocket().SetSocketOption(System.Net.Sockets.SocketOptionLevel.IPv6, join ? MCAST_JOIN_SOURCE_GROUP : MCAST_LEAVE_SOURCE_GROUP, optionValue);
                }
                return(0);
            }
            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
        }
コード例 #9
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int joinOrDrop4(bool join, FileDescriptor fd, int group, int interf, int source)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                if (source == 0)
                {
                    fd.getSocket().SetSocketOption(System.Net.Sockets.SocketOptionLevel.IP,
                                                   join ? System.Net.Sockets.SocketOptionName.AddMembership : System.Net.Sockets.SocketOptionName.DropMembership,
                                                   new System.Net.Sockets.MulticastOption(new System.Net.IPAddress(System.Net.IPAddress.HostToNetworkOrder(group) & 0xFFFFFFFFL), new System.Net.IPAddress(System.Net.IPAddress.HostToNetworkOrder(interf) & 0xFFFFFFFFL)));
                }
                else
                {
                    // ip_mreq_source
                    byte[] optionValue = new byte[12];
                    PutInt(optionValue, 0, group);
                    PutInt(optionValue, 4, source);
                    PutInt(optionValue, 8, interf);
                    fd.getSocket().SetSocketOption(System.Net.Sockets.SocketOptionLevel.IP,
                                                   join ? System.Net.Sockets.SocketOptionName.AddSourceMembership : System.Net.Sockets.SocketOptionName.DropSourceMembership,
                                                   optionValue);
                }
                return(0);
            }
            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
        }
コード例 #10
0
ファイル: sun.nio.ch.cs プロジェクト: moayyaed/ikvm
        public static void setIntOption0(FileDescriptor fd, bool mayNeedConversion, int level, int opt, int arg, bool isIPv6)
        {
#if !FIRST_PASS
            if (level == global::[email protected]_IPV6 && opt == global::[email protected]_TCLASS)
            {
                return;
            }
            System.Net.Sockets.SocketOptionLevel sol = (System.Net.Sockets.SocketOptionLevel)level;
            System.Net.Sockets.SocketOptionName  son = (System.Net.Sockets.SocketOptionName)opt;
            if (mayNeedConversion)
            {
                const int IPTOS_TOS_MASK  = 0x1e;
                const int IPTOS_PREC_MASK = 0xe0;
                if (sol == System.Net.Sockets.SocketOptionLevel.IP &&
                    son == System.Net.Sockets.SocketOptionName.TypeOfService)
                {
                    arg &= (IPTOS_TOS_MASK | IPTOS_PREC_MASK);
                }
            }
            try
            {
                fd.getSocket().SetSocketOption(sol, son, arg);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                if (mayNeedConversion)
                {
                    if (x.ErrorCode == global::java.net.SocketUtil.WSAENOPROTOOPT &&
                        sol == System.Net.Sockets.SocketOptionLevel.IP &&
                        (son == System.Net.Sockets.SocketOptionName.TypeOfService || son == System.Net.Sockets.SocketOptionName.MulticastLoopback))
                    {
                        return;
                    }
                    if (x.ErrorCode == global::java.net.SocketUtil.WSAEINVAL &&
                        sol == System.Net.Sockets.SocketOptionLevel.IP &&
                        son == System.Net.Sockets.SocketOptionName.TypeOfService)
                    {
                        return;
                    }
                }
                throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
            }
            catch (System.ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
#endif
        }
コード例 #11
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static void setInterface6(FileDescriptor fd, int index)
        {
#if !FIRST_PASS
            try
            {
                fd.getSocket().SetSocketOption(System.Net.Sockets.SocketOptionLevel.IPv6, System.Net.Sockets.SocketOptionName.MulticastInterface, index);
            }
            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
        }
コード例 #12
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static void listen(FileDescriptor fd, int backlog)
        {
#if !FIRST_PASS
            try
            {
                fd.getSocket().Listen(backlog);
            }
            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
        }
コード例 #13
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int getInterface6(FileDescriptor fd)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                return((int)fd.getSocket().GetSocketOption(System.Net.Sockets.SocketOptionLevel.IPv6, System.Net.Sockets.SocketOptionName.MulticastInterface));
            }
            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
        }
コード例 #14
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static void shutdown(FileDescriptor fd, int how)
        {
#if !FIRST_PASS
            try
            {
                fd.getSocket().Shutdown(how == global::sun.nio.ch.Net.SHUT_RD
                                        ? System.Net.Sockets.SocketShutdown.Receive
                                        : System.Net.Sockets.SocketShutdown.Send);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
            }
            catch (ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
#endif
        }
コード例 #15
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static InetAddress remoteInetAddress(FileDescriptor fd)
        {
#if FIRST_PASS
            return(null);
#else
            try
            {
                System.Net.IPEndPoint ep = (System.Net.IPEndPoint)fd.getSocket().RemoteEndPoint;
                return(global::java.net.SocketUtil.getInetAddressFromIPEndPoint(ep));
            }
            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
        }
コード例 #16
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int remotePort(FileDescriptor fd)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                System.Net.IPEndPoint ep = (System.Net.IPEndPoint)fd.getSocket().RemoteEndPoint;
                return(ep.Port);
            }
            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
        }
コード例 #17
0
ファイル: sun.nio.ch.cs プロジェクト: cDoru/ikvm-fork
        public static int sendOutOfBandData(FileDescriptor fd, byte data)
        {
#if FIRST_PASS
            return(0);
#else
            try
            {
                fd.getSocket().Send(new byte[] { data }, 1, System.Net.Sockets.SocketFlags.OutOfBand);
                return(1);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw new global::java.net.ConnectException(x.Message);
            }
            catch (System.ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
#endif
        }
コード例 #18
0
ファイル: sun.nio.ch.cs プロジェクト: moayyaed/ikvm
        public static int getIntOption0(FileDescriptor fd, bool mayNeedConversion, int level, int opt)
        {
#if FIRST_PASS
            return(0);
#else
            if (level == global::[email protected]_IPV6 && opt == global::[email protected]_TCLASS)
            {
                return(0);
            }
            System.Net.Sockets.SocketOptionLevel sol = (System.Net.Sockets.SocketOptionLevel)level;
            System.Net.Sockets.SocketOptionName  son = (System.Net.Sockets.SocketOptionName)opt;
            try
            {
                object obj = fd.getSocket().GetSocketOption(sol, son);
                System.Net.Sockets.LingerOption linger = obj as System.Net.Sockets.LingerOption;
                if (linger != null)
                {
                    return(linger.Enabled ? linger.LingerTime : -1);
                }
                return((int)obj);
            }
            catch (System.Net.Sockets.SocketException x)
            {
                if (mayNeedConversion)
                {
                    if (x.ErrorCode == global::java.net.SocketUtil.WSAENOPROTOOPT &&
                        sol == System.Net.Sockets.SocketOptionLevel.IP &&
                        son == System.Net.Sockets.SocketOptionName.TypeOfService)
                    {
                        return(0);
                    }
                }
                throw global::java.net.SocketUtil.convertSocketExceptionToIOException(x);
            }
            catch (System.ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
#endif
        }
コード例 #19
0
ファイル: sun.nio.ch.cs プロジェクト: moayyaed/ikvm
        public static int poll(FileDescriptor fd, int events, long timeout)
        {
#if FIRST_PASS
            return(0);
#else
            System.Net.Sockets.SelectMode selectMode;
            switch (events)
            {
            case global::sun.nio.ch.Net.POLLCONN:
            case global::sun.nio.ch.Net.POLLOUT:
                selectMode = System.Net.Sockets.SelectMode.SelectWrite;
                break;

            case global::sun.nio.ch.Net.POLLIN:
                selectMode = System.Net.Sockets.SelectMode.SelectRead;
                break;

            default:
                throw new NotSupportedException();
            }
            int microSeconds = timeout >= Int32.MaxValue / 1000 ? Int32.MaxValue : (int)(timeout * 1000);
            try
            {
                if (fd.getSocket().Poll(microSeconds, selectMode))
                {
                    return(events);
                }
            }
            catch (System.Net.Sockets.SocketException x)
            {
                throw new global::java.net.SocketException(x.Message);
            }
            catch (System.ObjectDisposedException)
            {
                throw new global::java.net.SocketException("Socket is closed");
            }
            return(0);
#endif
        }