public void WriteForPost(byte[] headDomain, byte[] body, Action <OwinSocket, int, Exception, object> callback, object otherState) { CheckClosed(); WriteState writeState = new WriteState { Callback = callback, OtherState = otherState }; WriteStateForPost writeStateForPost = new WriteStateForPost { WriteObject = writeState, Buffers = new List <byte[]> { headDomain, body } }; if (Thread.CurrentThread.ManagedThreadId != _clientHandle.Loop.LoopRunThreadId) { _postAsync(new Action <object>(WriteForPost), writeStateForPost); return; } WriteForPost(writeStateForPost); }
private void WriteForPost(object state) { WriteStateForPost writeStateForPost = (WriteStateForPost)state; WriteHandle writeHandle = new WriteHandle(); writeHandle.Init(_clientHandle.Loop); List <byte[]> buffers = writeStateForPost.Buffers; try { if (buffers.Count == 1) { writeHandle.Write(_clientHandle, buffers[0], new Action <int, Exception, object>(WriteCallback), writeStateForPost.WriteObject); } else if (buffers.Count == 2) { writeHandle.Write(_clientHandle, buffers[0], buffers[1], new Action <int, Exception, object>(WriteCallback), writeStateForPost.WriteObject); } } catch (Exception ex) { WriteCallback(-1, ex, writeStateForPost.WriteObject); } }