Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 3
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;
		}