int StartOperation(ref AsyncProtocolRequest nestedRequest, ref BufferOffsetSize2 internalBuffer, AsyncOperation operation, AsyncProtocolRequest asyncRequest, string name) { if (Interlocked.CompareExchange(ref nestedRequest, asyncRequest, null) != null) { throw new InvalidOperationException("Invalid nested call."); } bool failed = false; try { internalBuffer.Reset(); asyncRequest.StartOperation(operation); return(asyncRequest.UserResult); } catch (Exception e) { failed = true; if (e is IOException) { throw; } throw new IOException(name + " failed", e); } finally { if (asyncRequest.UserAsyncResult == null || failed) { internalBuffer.Reset(); nestedRequest = null; } } }
async Task <int> StartOperation(OperationType type, AsyncProtocolRequest asyncRequest, CancellationToken cancellationToken) { CheckThrow(true, type != OperationType.Read); Debug("StartOperationAsync: {0} {1}", asyncRequest, type); if (type == OperationType.Read) { if (Interlocked.CompareExchange(ref asyncReadRequest, asyncRequest, null) != null) { throw new InvalidOperationException("Invalid nested call."); } } else { if (Interlocked.CompareExchange(ref asyncWriteRequest, asyncRequest, null) != null) { throw new InvalidOperationException("Invalid nested call."); } } AsyncProtocolResult result; try { lock (ioLock) { if (type == OperationType.Read) { readBuffer.Reset(); } else { writeBuffer.Reset(); } } result = await asyncRequest.StartOperation(cancellationToken).ConfigureAwait(false); } catch (Exception e) { var info = SetException(GetIOException(e, asyncRequest.Name + " failed")); result = new AsyncProtocolResult(info); } finally { lock (ioLock) { if (type == OperationType.Read) { readBuffer.Reset(); asyncReadRequest = null; } else { writeBuffer.Reset(); asyncWriteRequest = null; } } } if (result.Error != null) { result.Error.Throw(); } return(result.UserResult); }
internal void ProcessAuthentication(LazyAsyncResult lazyResult) { var asyncRequest = new AsyncProtocolRequest(this, lazyResult); if (Interlocked.CompareExchange(ref asyncHandshakeRequest, asyncRequest, null) != null) { throw new InvalidOperationException("Invalid nested call."); } try { if (lastException != null) { throw lastException; } if (xobileTlsContext == null) { throw new InvalidOperationException(); } readBuffer.Reset(); writeBuffer.Reset(); try { asyncRequest.StartOperation(ProcessHandshake); } catch (Exception ex) { throw SetException(ex); } } finally { if (lazyResult == null || lastException != null) { readBuffer.Reset(); writeBuffer.Reset(); asyncHandshakeRequest = null; } } }
int StartOperation (ref AsyncProtocolRequest nestedRequest, ref BufferOffsetSize2 internalBuffer, AsyncOperation operation, AsyncProtocolRequest asyncRequest, string name) { if (Interlocked.CompareExchange (ref nestedRequest, asyncRequest, null) != null) throw new InvalidOperationException ("Invalid nested call."); bool failed = false; try { internalBuffer.Reset (); asyncRequest.StartOperation (operation); return asyncRequest.UserResult; } catch (Exception e) { failed = true; if (e is IOException) throw; throw new IOException (name + " failed", e); } finally { if (asyncRequest.UserAsyncResult == null || failed) { internalBuffer.Reset (); nestedRequest = null; } } }
internal void ProcessAuthentication (LazyAsyncResult lazyResult) { var asyncRequest = new AsyncProtocolRequest (this, lazyResult); if (Interlocked.CompareExchange (ref asyncHandshakeRequest, asyncRequest, null) != null) throw new InvalidOperationException ("Invalid nested call."); try { if (lastException != null) throw lastException; if (xobileTlsContext == null) throw new InvalidOperationException (); readBuffer.Reset (); writeBuffer.Reset (); try { asyncRequest.StartOperation (ProcessHandshake); } catch (Exception ex) { ExceptionDispatchInfo.Capture (SetException (ex)).Throw (); } } finally { if (lazyResult == null || lastException != null) { readBuffer.Reset (); writeBuffer.Reset (); asyncHandshakeRequest = null; } } }