コード例 #1
0
        public IAsyncResult BeginConnect(IPEndPoint remoteEP,
                                         AsyncCallback callback,
                                         Object state)
        {
            if (_physical == null)
            {
                AutomaticBind();
            }

            RUDPConnectIAsyncResult asyncResult = new RUDPConnectIAsyncResult(this, callback, state);

            Interlocked.Exchange <RUDPConnectIAsyncResult>(ref _asyncResultConnect, asyncResult);

            _remoteEndPoint = remoteEP;
            RUDPSocketError result = _physical.BeginConnect(this, DefaultConnectionTimeOut);

            if (result != RUDPSocketError.Success)
            {
                Interlocked.Exchange <RUDPConnectIAsyncResult>(ref _asyncResultConnect, null);
                _remoteEndPoint = null;
                throw new RUDPSocketException(result);
            }

            return(asyncResult);
        }
コード例 #2
0
        internal void OnEndConnect(RUDPSocketError error)
        {
            RUDPConnectIAsyncResult result = null;

            Interlocked.Exchange <RUDPConnectIAsyncResult>(ref result, _asyncResultConnect);
            if (result == null)
            {
                return;
            }

            Interlocked.Exchange <RUDPConnectIAsyncResult>(ref _asyncResultConnect, null);

            result.Connected = (error == RUDPSocketError.Success);
            result.SetAsCompleted(error, false);
        }
コード例 #3
0
ファイル: RUDPSocket.cs プロジェクト: iraychen/ourmsg
		public IAsyncResult BeginConnect(IPEndPoint remoteEP,
											AsyncCallback callback,
											Object state)
		{
			if (_physical == null)
				AutomaticBind();

			RUDPConnectIAsyncResult asyncResult = new RUDPConnectIAsyncResult(this, callback, state);
			Interlocked.Exchange<RUDPConnectIAsyncResult>(ref _asyncResultConnect, asyncResult);

			_remoteEndPoint = remoteEP;
			RUDPSocketError result = _physical.BeginConnect(this, DefaultConnectionTimeOut);
			if (result != RUDPSocketError.Success)
			{
				Interlocked.Exchange<RUDPConnectIAsyncResult>(ref _asyncResultConnect, null);
				_remoteEndPoint = null;
				throw new RUDPSocketException(result);
			}

			return asyncResult;
		}