Esempio n. 1
0
        public void Write(Cargo<ArraySegment<byte>> cargo)
        {
            if (!cargo.Delayable) {
                _write(cargo.Result.Array, cargo.Result.Offset, cargo.Result.Count);
                return;
            }

            var result = _beginWrite(cargo.Result.Array, cargo.Result.Offset, cargo.Result.Count, asyncResult => {
                if (asyncResult.CompletedSynchronously)
                    return;
                _endWrite(asyncResult);
                cargo.Resume();
            }, null);

            if (result.CompletedSynchronously)
                _endWrite(result);
            else
                cargo.Delay();
        }
Esempio n. 2
0
        static void Write(Cargo<ArraySegment<byte>> cargo, Stream stream)
        {
            if (!cargo.Delayable) {
                stream.Write(cargo.Result.Array, cargo.Result.Offset, cargo.Result.Count);
                return;
            }

            var result = stream.BeginWrite(cargo.Result.Array, cargo.Result.Offset, cargo.Result.Count, asyncResult => {
                if (asyncResult.CompletedSynchronously)
                    return;
                stream.EndWrite(asyncResult);
                cargo.Resume();
            }, null);

            if (result.CompletedSynchronously)
                stream.EndWrite(result);
            else
                cargo.Delay();
        }