Esempio n. 1
0
        public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            EnsureStarted();

            var asyncResult = new AsyncResult<int>(callback, state);
            var retval = new int[1];
            var async = _spool.Pull(new ArraySegment<byte>(buffer, offset, count), retval, () => asyncResult.SetAsCompleted(retval[0], false));
            if (async == false)
                asyncResult.SetAsCompleted(retval[0], true);
            return asyncResult;
        }
Esempio n. 2
0
        public override IAsyncResult BeginWrite(byte[] buffer, int offset, int count, AsyncCallback callback,
            object state)
        {
            EnsureNotCompleted();

            asyncResult = new AsyncResult(callback, state);

            if (!next(new ArraySegment<byte>(buffer, offset, count), () => asyncResult.SetAsCompleted(null, false)))
                asyncResult.SetAsCompleted(null, true);

            return asyncResult;
        }