Beispiel #1
0
        public void Connect()
        {
            if (result.EndPoint == null)
            {
                result.Complete(new SocketException((int)SocketError.AddressNotAvailable));
                return;
            }

            SocketAsyncResult mconnect = result.AsyncState as SocketAsyncResult;
            bool is_mconnect           = (mconnect != null && mconnect.Addresses != null);

            try {
                int      error_code;
                EndPoint ep = result.EndPoint;
                error_code = (int)result.socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Error);
                if (error_code == 0)
                {
                    if (is_mconnect)
                    {
                        result = mconnect;
                    }
                    result.socket.seed_endpoint       = ep;
                    result.socket.is_connected        = true;
                    result.socket.is_bound            = true;
                    result.socket.connect_in_progress = false;
                    result.error = 0;
                    result.Complete();
                    if (is_mconnect)
                    {
                        result.DoMConnectCallback();
                    }
                    return;
                }

                if (!is_mconnect)
                {
                    result.socket.connect_in_progress = false;
                    result.Complete(new SocketException(error_code));
                    return;
                }

                if (mconnect.CurrentAddress >= mconnect.Addresses.Length)
                {
                    mconnect.Complete(new SocketException(error_code));
                    if (is_mconnect)
                    {
                        mconnect.DoMConnectCallback();
                    }
                    return;
                }
                mconnect.socket.BeginMConnect(mconnect);
            } catch (Exception e) {
                result.socket.connect_in_progress = false;
                if (is_mconnect)
                {
                    result = mconnect;
                }
                result.Complete(e);
                if (is_mconnect)
                {
                    result.DoMConnectCallback();
                }
                return;
            }
        }
Beispiel #2
0
        public void Accept()
        {
            Socket acc_socket = null;

            try {
                if (args != null && args.AcceptSocket != null)
                {
                    result.socket.Accept(args.AcceptSocket);
                    acc_socket = args.AcceptSocket;
                }
                else
                {
                    acc_socket = result.socket.Accept();
                    if (args != null)
                    {
                        args.AcceptSocket = acc_socket;
                    }
                }
            } catch (Exception e) {
                result.Complete(e);
                return;
            }

            result.Complete(acc_socket);
        }