Exemple #1
0
        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
        }
Exemple #2
0
        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
        }