void TransparentStreamWriteRequestMessageReceived(TransparentStreamMessageBase transparentStreamMessageBase) { TransparentStreamWriteRequestMessage request = (TransparentStreamWriteRequestMessage)transparentStreamMessageBase; Exception exception = null; try { baseStream.BeginWrite(request.Buffer, 0, request.Buffer.Length, (ar) => { try { baseStream.EndWrite(ar); } catch (Exception ex) { objectBusSession.SendMessage(new TransparentStreamWriteResponseMessage(streamID, request.ID, ex)); } }, request.Buffer); } catch (Exception ex) { exception = ex; objectBusSession.SendMessage(new TransparentStreamWriteResponseMessage(streamID, request.ID, exception)); } }
public override IAsyncResult BeginWrite (byte[] buffer, int offset, int count, AsyncCallback callback, object state) { byte[] nbuf = new byte[count]; System.Buffer.BlockCopy (buffer, offset, nbuf, 0, count); TransparentStreamWriteRequestMessage request = new TransparentStreamWriteRequestMessage (Guid.NewGuid (), streamID, nbuf); TransparentStreamAsyncResult result = new TransparentStreamAsyncResult (null); if (!pendingWriteRequests.TryAdd (request.ID, result)) { throw new Exception ("request failed before sending."); } objectBusSession.SendMessage (request); return result; }