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); }
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); }
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; }