コード例 #1
0
        public override IAsyncResult BeginRead(byte[] buffer, int offset,
                                               int count, AsyncCallback callback, object state)
        {
            ReadDelegate read = this.Read;

            return(read.BeginInvoke(buffer, offset, count, callback, state));
        }
コード例 #2
0
        public void ShouldReadFileMultithreadedCorrectly()
        {
            ReadDelegate action = () =>
            {
                using (var image = new MagickImage())
                {
                    image.Read(Files.Coders.CartoonNetworkStudiosLogoAI);

                    Assert.AreEqual(765, image.Width);
                    Assert.AreEqual(361, image.Height);
                    Assert.AreEqual(MagickFormat.Ai, image.Format);
                }
            };

            var results = new IAsyncResult[3];

            for (int i = 0; i < results.Length; ++i)
            {
                results[i] = action.BeginInvoke(null, null);
            }

            for (int i = 0; i < results.Length; ++i)
            {
                action.EndInvoke(results[i]);
            }
        }
コード例 #3
0
        public override IAsyncResult BeginRead(byte [] buffer, int offset, int count,
                                               AsyncCallback cback, object state)
        {
            if (!CanRead)
            {
                throw new NotSupportedException("This stream does not support reading");
            }

            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (count < 0)
            {
                throw new ArgumentOutOfRangeException("count", "Must be >= 0");
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "Must be >= 0");
            }

            ReadDelegate d = new ReadDelegate(this.Read);

            return(d.BeginInvoke(buffer, offset, count, cback, state));
        }
コード例 #4
0
ファイル: HidDevice.cs プロジェクト: wdatkinson/KFDtool
        public void Read(ReadCallback callback)
        {
            ReadDelegate  readDelegate = Read;
            HidAsyncState @object      = new HidAsyncState(readDelegate, callback);

            readDelegate.BeginInvoke(EndRead, @object);
        }
コード例 #5
0
ファイル: FtpDataStream.cs プロジェクト: pmq20/mono_forked
        public override IAsyncResult BeginRead(byte [] buffer, int offset, int size, AsyncCallback cb, object state)
        {
            CheckDisposed();

            if (!isRead)
            {
                throw new NotSupportedException();
            }
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }
            if (offset < 0 || offset > buffer.Length)
            {
                throw new ArgumentOutOfRangeException("offset");
            }
            if (size < 0 || size > buffer.Length - offset)
            {
                throw new ArgumentOutOfRangeException("offset+size");
            }

            ReadDelegate del = ReadInternal;

            return(del.BeginInvoke(buffer, offset, size, cb, state));
        }
コード例 #6
0
        public void Read(ReadCallback callback)
        {
            var readDelegate = new ReadDelegate(Read);
            var asyncState   = new HidAsyncState(readDelegate, callback);

            readDelegate.BeginInvoke(EndRead, asyncState);
        }
コード例 #7
0
        public void FastRead(ReadCallback callback, int timeout)
        {
            var readDelegate = new ReadDelegate(FastRead);
            var asyncState   = new HidAsyncState(readDelegate, callback);

            readDelegate.BeginInvoke(timeout, EndRead, asyncState);
        }
コード例 #8
0
        override public void Read(ReadCallback callback, int timeout)
        {
            if (!IsConnected)
            {
                return;
            }


            if (IsReadInProgress)
            {
                //UnityEngine.Debug.Log("Clone paket");
                __lastHIDReport.Status = HIDReport.ReadStatus.Buffered;

                callback.BeginInvoke(__lastHIDReport, EndReadCallback, callback);
                // callback.Invoke(__lastHIDReport);

                return;
            }

            IsReadInProgress = true;

            //TODO make this fields or use pool
            var readDelegate = new ReadDelegate(Read);
            var asyncState   = new HidAsyncState(readDelegate, callback);

            readDelegate.BeginInvoke(timeout, EndRead, asyncState);
        }
コード例 #9
0
 public void ReadAsyncContinuously()
 {//開始するとデリゲートで非同期読み待ち→読んでmessageLabel更新→また読み待ちが起動
     if (IsAvailable)
     {
         ConnectStateLabel = "読み待ち開始";
         readDelegate.BeginInvoke(null, null);
     }
 }
コード例 #10
0
ファイル: SimpleFileStream.cs プロジェクト: Baptista/PC
	//
	// Starts an asynchronous read operation.
	//

    public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count,
										  AsyncCallback userCallback, object userState) {
										  
		// Blocks if an asynchronous read is taking place.
        asyncActiveEvent.WaitOne();
        readDelegate = new ReadDelegate(Read);
        return readDelegate.BeginInvoke(buffer, offset, count, userCallback, userState);
    }
コード例 #11
0
        /// <summary>
        /// Begin asynchronous reading of data
        /// </summary>
        /// <param name="callback">The function to be called when data is done being read</param>
        public void ReadAsync(ReadCallback callback)
        {
            ReadDelegate del = new ReadDelegate(Read);

            del.BeginInvoke(AsyncReadEnd, new object[2] {
                del, callback
            });
        }
コード例 #12
0
        public override IAsyncResult BeginRead(byte [] array, int offset, int numBytes,
                                               AsyncCallback userCallback, object stateObject)
        {
            if (safeHandle.IsClosed)
            {
                throw new ObjectDisposedException("Stream has been closed");
            }

            if (!CanRead)
            {
                throw new NotSupportedException("This stream does not support reading");
            }

            if (array == null)
            {
                throw new ArgumentNullException("array");
            }

            if (numBytes < 0)
            {
                throw new ArgumentOutOfRangeException("numBytes", "Must be >= 0");
            }

            if (offset < 0)
            {
                throw new ArgumentOutOfRangeException("offset", "Must be >= 0");
            }

            // reordered to avoid possible integer overflow
            if (numBytes > array.Length - offset)
            {
                throw new ArgumentException("Buffer too small. numBytes/offset wrong.");
            }

            if (!async)
            {
                return(base.BeginRead(array, offset, numBytes, userCallback, stateObject));
            }

            ReadDelegate r = new ReadDelegate(ReadInternal);

            return(r.BeginInvoke(array, offset, numBytes, userCallback, stateObject));
        }
コード例 #13
0
    static void FeedDone(IAsyncResult ares)
    {
        AsyncResult a   = (AsyncResult)ares;
        ReadResult  res = null;

        try {
            res = ((ReadDelegate)a.AsyncDelegate).EndInvoke(ares);
        } catch {
            res = new ReadResult(UpdateStatus.Error);
        }

        if (disable_load)
        {
            return;
        }
        Blogger blogger = (Blogger)ares.AsyncState;

        blogger.Feed = res.Feed;
        blogger.UpdateFeed();
        if (res.Status == UpdateStatus.CachedButError)
        {
            blogger.Error = true;
        }
        Settings.Log("DONE {0}", blogger.RssUrl);
        lock (all) {
            loaded++;
            counters [(int)res.Status]++;
            if (loaded >= all.Length)
            {
                wait_handle.Set();
            }
            if (next >= all.Length)
            {
                return;
            }
            Blogger      b = all [next++];
            ReadDelegate d = new ReadDelegate(FeedCache.Read);
            d.BeginInvoke(b.Name, b.RssUrl, feed_done, b);
        }
    }
コード例 #14
0
        public void Test_Multithreading()
        {
            ReadDelegate action = delegate()
            {
                using (MagickImage image = new MagickImage())
                {
                    image.Read(Files.Coders.CartoonNetworkStudiosLogoAI);
                }
            };

            IAsyncResult[] results = new IAsyncResult[3];

            for (int i = 0; i < results.Length; ++i)
            {
                results[i] = action.BeginInvoke(null, null);
            }

            for (int i = 0; i < results.Length; ++i)
            {
                action.EndInvoke(results[i]);
            }
        }
コード例 #15
0
        override public HIDReport ReadBuffered()
        {
            if (!IsConnected)
            {
                return(null);
            }

            if (IsReadInProgress)
            {
                __lastHIDReport.Status = HIDReport.ReadStatus.Buffered;
                return(__lastHIDReport);
            }

            IsReadInProgress = true;

            //TODO make this fields or use pool
            var readDelegate = new ReadDelegate(Read);

            readDelegate.BeginInvoke(0, EndReadBuffered, readDelegate);

            return(__lastHIDReport);
        }
コード例 #16
0
        public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, Object state)
        {
            if (!CanRead)
            {
                __Error.ReadNotSupported();
            }

            // Increment the count to account for this async operation
            BCLDebug.Assert(_asyncActiveCount >= 1, "ref counting mismatch, possible race in the code");
            Interlocked.Increment(ref _asyncActiveCount);

            ReadDelegate d = new ReadDelegate(Read);

            // To avoid a race with a stream's position pointer & generating race
            // conditions with internal buffer indexes in our own streams that
            // don't natively support async IO operations when there are multiple
            // async requests outstanding, we will block the application's main
            // thread if it does a second IO request until the first one completes.
            if (_asyncActiveEvent == null)
            {
                lock (this) {
                    if (_asyncActiveEvent == null)
                    {
                        _asyncActiveEvent = new AutoResetEvent(true);
                    }
                }
            }
            bool r = _asyncActiveEvent.WaitOne();

            BCLDebug.Assert(r, "AutoResetEvent didn't get a signal when we called WaitOne!");

            BCLDebug.Assert(_readDelegate == null && _writeDelegate == null, "Expected no other readers or writers!");

            // Set delegate before we call BeginInvoke, to avoid a race
            _readDelegate = d;
            IAsyncResult asyncResult = d.BeginInvoke(buffer, offset, count, callback, state);

            return(asyncResult);
        }
コード例 #17
0
 public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     if (!this.CanRead)
     {
         __Error.ReadNotSupported();
     }
     Interlocked.Increment(ref this._asyncActiveCount);
     ReadDelegate delegate2 = new ReadDelegate(this.Read);
     if (this._asyncActiveEvent == null)
     {
         lock (this)
         {
             if (this._asyncActiveEvent == null)
             {
                 this._asyncActiveEvent = new AutoResetEvent(true);
             }
         }
     }
     this._asyncActiveEvent.WaitOne();
     this._readDelegate = delegate2;
     return delegate2.BeginInvoke(buffer, offset, count, callback, state);
 }
コード例 #18
0
        public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
        {
            if (!this.CanRead)
            {
                __Error.ReadNotSupported();
            }
            Interlocked.Increment(ref this._asyncActiveCount);
            ReadDelegate delegate2 = new ReadDelegate(this.Read);

            if (this._asyncActiveEvent == null)
            {
                lock (this)
                {
                    if (this._asyncActiveEvent == null)
                    {
                        this._asyncActiveEvent = new AutoResetEvent(true);
                    }
                }
            }
            this._asyncActiveEvent.WaitOne();
            this._readDelegate = delegate2;
            return(delegate2.BeginInvoke(buffer, offset, count, callback, state));
        }
コード例 #19
0
        public void ShouldReadFileMultithreadedCorrectly()
        {
            ReadDelegate action = () =>
            {
                using (IMagickImage image = new MagickImage())
                {
                    image.Read(Files.Coders.CartoonNetworkStudiosLogoAI);
                    Test_Image(image);
                }
            };

            IAsyncResult[] results = new IAsyncResult[3];

            for (int i = 0; i < results.Length; ++i)
            {
                results[i] = action.BeginInvoke(null, null);
            }

            for (int i = 0; i < results.Length; ++i)
            {
                action.EndInvoke(results[i]);
            }
        }
コード例 #20
0
 public void FastRead(ReadCallback callback, int timeout)
 {
     var readDelegate = new ReadDelegate(FastRead);
     var asyncState = new HidAsyncState(readDelegate, callback);
     readDelegate.BeginInvoke(timeout, EndRead, asyncState);
 }
コード例 #21
0
            public IAsyncResult BeginRead(byte [] buffer, int offset, int count, AsyncCallback cb, object state)
            {
                ReadDelegate del = new ReadDelegate(Read);

                return(del.BeginInvoke(buffer, offset, count, cb, state));
            }
コード例 #22
0
ファイル: monologue-worker.cs プロジェクト: geek/monologue
    static void RunOnce()
    {
        if (bloggers == null || File.GetLastWriteTime (bloggersFile) > lastReadOfBloggersFile) {
            lastReadOfBloggersFile = File.GetLastWriteTime (bloggersFile);
            bloggers = BloggerCollection.LoadFromFile (bloggersFile);
        }

        disable_load = false;
        all = (Blogger []) bloggers.Bloggers.ToArray (typeof (Blogger));
        lock (all) {
            next = 10;
            for (int i = 0; i < 10 && i < all.Length; i++) {
                Blogger b = all [i];
                ReadDelegate d = new ReadDelegate (FeedCache.Read);
                d.BeginInvoke (b.Name, b.RssUrl, feed_done, b);
            }
        }

        wait_handle.WaitOne (300000, false);
        disable_load = true;

        for (int i = 0; i < (int) UpdateStatus.MAX; i++) {
            Console.WriteLine ("{0}: {1}", (UpdateStatus) i, counters [i]);
        }

        int error = counters [(int) UpdateStatus.Error];
        int downloaded = counters [(int) UpdateStatus.Downloaded];
        int updated = counters [(int) UpdateStatus.Updated];
        if (error == 0 && downloaded == 0 && updated == 0)
            return;

        outFeed = new RssFeed ();
        RssChannel ch = new RssChannel ();
        ch.Title = "Monologue";
        ch.Generator = "Monologue worker: b-diddy powered";
        ch.Description = "The voices of Mono";
        ch.Link = new Uri ("http://www.go-mono.com/monologue/");

        ArrayList stories = new ArrayList ();

        DateTime minPubDate = DateTime.Now.AddDays (-14);
        foreach (Blogger b in bloggers.BloggersByUrl) {
            if (b.Channel == null) continue;
            foreach (RssItem i in b.Channel.Items) {
                if (i.PubDate == DateTime.MinValue) {
                    b.DateError = true;
                } else if (i.PubDate >= minPubDate) {
                    i.Title = b.Name + ": " + i.Title;
                    i.PubDate = i.PubDate.ToUniversalTime ();
                    stories.Add (i);
                }
            }
        }

        stories.Sort (new ReverseRssItemComparer ());

        foreach (RssItem itm in stories)
            ch.Items.Add (itm);

        if (ch.Items.Count == 0) {
            Settings.Log ("No feeds to store.");
            return;
        }
        outFeed.Channels.Add (ch);
        outFeed.Write (rssOutFile);

        Render ();
    }
コード例 #23
0
ファイル: monologue-worker.cs プロジェクト: geek/monologue
    static void FeedDone(IAsyncResult ares)
    {
        AsyncResult a = (AsyncResult) ares;
        ReadResult res = null;
        try {
            res = ((ReadDelegate) a.AsyncDelegate).EndInvoke (ares);
        } catch {
            res = new ReadResult (UpdateStatus.Error);
        }

        if (disable_load)
            return;
        Blogger blogger = (Blogger) ares.AsyncState;
        blogger.Feed = res.Feed;
        blogger.UpdateFeed ();
        if (res.Status == UpdateStatus.CachedButError)
            blogger.Error = true;
        Settings.Log ("DONE {0}", blogger.RssUrl);
        lock (all) {
            loaded++;
            counters [(int) res.Status]++;
            if (loaded >= all.Length)
                wait_handle.Set ();
            if (next >= all.Length)
                return;
            Blogger b = all [next++];
            ReadDelegate d = new ReadDelegate (FeedCache.Read);
            d.BeginInvoke (b.Name, b.RssUrl, feed_done, b);
        }
    }
コード例 #24
0
		override public void Read(ReadCallback callback,int timeout)
		{
            if (!IsConnected) return;


			if (IsReadInProgress)
			{
				//UnityEngine.Debug.Log("Clone paket");
				__lastHIDReport.Status = HIDReport.ReadStatus.Buffered;

				callback.BeginInvoke(__lastHIDReport, EndReadCallback, callback);
				// callback.Invoke(__lastHIDReport);
               
				return;
			}
			
			IsReadInProgress = true;
			
			//TODO make this fields or use pool
			var readDelegate = new ReadDelegate(Read);
			var asyncState = new HidAsyncState(readDelegate, callback);
			readDelegate.BeginInvoke(timeout,EndRead, asyncState);
		}
コード例 #25
0
 public override IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, object state)
 {
     ReadDelegate r = new ReadDelegate(Read);
     return r.BeginInvoke(buffer, offset, count, callback, state);
 }
コード例 #26
0
			public IAsyncResult BeginRead (byte [] buffer, int offset, int count, AsyncCallback cb, object state)
			{
				ReadDelegate del = new ReadDelegate (Read);
				return del.BeginInvoke (buffer, offset, count, cb, state);
			}
コード例 #27
0
        override public HIDReport ReadBuffered()
        {
            if (!IsConnected) return null;

            if (IsReadInProgress)
            {
                __lastHIDReport.Status = HIDReport.ReadStatus.Buffered;
                return __lastHIDReport;
            }

            IsReadInProgress = true;

            //TODO make this fields or use pool
            var readDelegate = new ReadDelegate(Read);

            readDelegate.BeginInvoke(0, EndReadBuffered, readDelegate);

            return __lastHIDReport;

        }
コード例 #28
0
    static void RunOnce()
    {
        if (bloggers == null || File.GetLastWriteTime(bloggersFile) > lastReadOfBloggersFile)
        {
            lastReadOfBloggersFile = File.GetLastWriteTime(bloggersFile);
            bloggers = BloggerCollection.LoadFromFile(bloggersFile);
        }

        disable_load = false;
        all          = (Blogger [])bloggers.Bloggers.ToArray(typeof(Blogger));
        lock (all) {
            next = 10;
            for (int i = 0; i < 10 && i < all.Length; i++)
            {
                Blogger      b = all [i];
                ReadDelegate d = new ReadDelegate(FeedCache.Read);
                d.BeginInvoke(b.Name, b.RssUrl, feed_done, b);
            }
        }

        wait_handle.WaitOne(300000, false);
        disable_load = true;

        for (int i = 0; i < (int)UpdateStatus.MAX; i++)
        {
            Console.WriteLine("{0}: {1}", (UpdateStatus)i, counters [i]);
        }

        int error      = counters [(int)UpdateStatus.Error];
        int downloaded = counters [(int)UpdateStatus.Downloaded];
        int updated    = counters [(int)UpdateStatus.Updated];

        if (error == 0 && downloaded == 0 && updated == 0)
        {
            return;
        }

        outFeed = new RssFeed();
        RssChannel ch = new RssChannel();

        ch.Title       = "Monologue";
        ch.Generator   = "Monologue worker: b-diddy powered";
        ch.Description = "The voices of Mono";
        ch.Link        = new Uri("http://www.go-mono.com/monologue/");

        ArrayList stories = new ArrayList();

        DateTime minPubDate = DateTime.Now.AddDays(-14);

        foreach (Blogger b in bloggers.BloggersByUrl)
        {
            if (b.Channel == null)
            {
                continue;
            }
            foreach (RssItem i in b.Channel.Items)
            {
                if (i.PubDate == DateTime.MinValue)
                {
                    b.DateError = true;
                }
                else if (i.PubDate >= minPubDate)
                {
                    i.Title   = b.Name + ": " + i.Title;
                    i.PubDate = i.PubDate.ToUniversalTime();
                    stories.Add(i);
                }
            }
        }

        stories.Sort(new ReverseRssItemComparer());

        foreach (RssItem itm in stories)
        {
            ch.Items.Add(itm);
        }

        if (ch.Items.Count == 0)
        {
            Settings.Log("No feeds to store.");
            return;
        }
        outFeed.Channels.Add(ch);
        outFeed.Write(rssOutFile);

        Render();
    }
コード例 #29
0
		public override IAsyncResult BeginRead(
			byte[]			buffer,
			int				offset,
			int				count,
			AsyncCallback	callback,
			object			state)
		{
			this.checkDisposed ();
			
			if (buffer == null)
			{
				throw new ArgumentNullException("buffer is a null reference.");
			}
			if (offset < 0)
			{
				throw new ArgumentOutOfRangeException("offset is less than 0.");
			}
			if (offset > buffer.Length)
			{
				throw new ArgumentOutOfRangeException("offset is greater than the length of buffer.");
			}
			if (count < 0)
			{
				throw new ArgumentOutOfRangeException("count is less than 0.");
			}
			if (count > (buffer.Length - offset))
			{
				throw new ArgumentOutOfRangeException("count is less than the length of buffer minus the value of the offset parameter.");
			}

			if (this.context.HandshakeState == HandshakeState.None)
			{
				// Note: Async code may have problem if they can't ensure that
				// the Negotiate phase isn't done during a read operation.
				// System.Net.HttpWebRequest protects itself from that problem
				lock (this.negotiate)
				{
					if (this.context.HandshakeState == HandshakeState.None)
					{
						this.NegotiateHandshake();
					}
				}
			}

			IAsyncResult asyncResult = null;

			lock (this.read)
			{
				try
				{
					// If actual buffer is full readed reset it
					if (this.inputBuffer.Position == this.inputBuffer.Length &&
						this.inputBuffer.Length > 0)
					{
						this.resetBuffer();
					}

					if (!this.context.ConnectionEnd)
					{
						if ((this.inputBuffer.Length == this.inputBuffer.Position) && (count > 0))
						{
							// bigger than max record length for SSL/TLS
							byte[] recbuf = new byte[16384]; 

							// this will read data from the network until we have (at least) one
							// record to send back to the caller
							this.innerStream.BeginRead (recbuf, 0, recbuf.Length, 
								new AsyncCallback (NetworkReadCallback), recbuf);

							if (!recordEvent.WaitOne (300000, false)) // 5 minutes
							{
								// FAILSAFE
								DebugHelper.WriteLine ("TIMEOUT length {0}, position {1}, count {2} - {3}\n{4}", 
									this.inputBuffer.Length, this.inputBuffer.Position, count, GetHashCode (),
									Environment.StackTrace);
								throw new TlsException (AlertDescription.InternalError);
							}
						}
					}

					// return the record(s) to the caller
					rd = new ReadDelegate (this.inputBuffer.Read);
					asyncResult = rd.BeginInvoke (buffer, offset, count, callback, state);
				}
				catch (TlsException ex)
				{
					this.protocol.SendAlert(ex.Alert);
					this.Close();

					throw new IOException("The authentication or decryption has failed.");
				}
				catch (Exception)
				{
					throw new IOException("IO exception during read.");
				}

			}

			return asyncResult;
		}
コード例 #30
0
ファイル: HidDevice.cs プロジェクト: GotenXiao/blink1
 public void Read(ReadCallback callback)
 {
     var readDelegate = new ReadDelegate(Read);
     var asyncState = new HidAsyncState(readDelegate, callback);
     readDelegate.BeginInvoke(EndRead, asyncState);
 }
コード例 #31
0
        public virtual IAsyncResult BeginRead(byte[] buffer, int offset, int count, AsyncCallback callback, Object state)
        {
            if (!CanRead) __Error.ReadNotSupported();

            // Increment the count to account for this async operation
            BCLDebug.Assert(_asyncActiveCount >= 1, "ref counting mismatch, possible race in the code");
            Interlocked.Increment(ref _asyncActiveCount);
            
            ReadDelegate d = new ReadDelegate(Read);

            // To avoid a race with a stream's position pointer & generating race 
            // conditions with internal buffer indexes in our own streams that 
            // don't natively support async IO operations when there are multiple 
            // async requests outstanding, we will block the application's main
            // thread if it does a second IO request until the first one completes.
            if (_asyncActiveEvent == null) {
                lock(this) {
                    if (_asyncActiveEvent == null)
                        _asyncActiveEvent = new AutoResetEvent(true);
                }
            }
            bool r = _asyncActiveEvent.WaitOne();
            BCLDebug.Assert(r, "AutoResetEvent didn't get a signal when we called WaitOne!");

            BCLDebug.Assert(_readDelegate == null && _writeDelegate == null, "Expected no other readers or writers!");

            // Set delegate before we call BeginInvoke, to avoid a race
            _readDelegate = d;
            IAsyncResult asyncResult = d.BeginInvoke(buffer, offset, count, callback, state);

            return asyncResult;
        }
コード例 #32
0
        /// <summary>
        /// Starts an async reading.
        /// </summary>
        /// <param name="offset"></param>
        /// <param name="len"></param>
        /// <param name="cb"></param>
        /// <param name="state"></param>
        /// <returns></returns>
        public IAsyncResult BeginRead(int offset, int len, AsyncCallback cb, object state)
        {
            ReadDelegate d = Read;

            return(d.BeginInvoke(offset, len, cb, state));
        }
コード例 #33
0
ファイル: FileStream.cs プロジェクト: stabbylambda/mono
		public override IAsyncResult BeginRead (byte [] array, int offset, int numBytes,
							AsyncCallback userCallback, object stateObject)
		{
			if (handle == MonoIO.InvalidHandle)
				throw new ObjectDisposedException ("Stream has been closed");

			if (!CanRead)
				throw new NotSupportedException ("This stream does not support reading");

			if (array == null)
				throw new ArgumentNullException ("array");

			if (numBytes < 0)
				throw new ArgumentOutOfRangeException ("numBytes", "Must be >= 0");

			if (offset < 0)
				throw new ArgumentOutOfRangeException ("offset", "Must be >= 0");

			// reordered to avoid possible integer overflow
			if (numBytes > array.Length - offset)
				throw new ArgumentException ("Buffer too small. numBytes/offset wrong.");

			if (!async)
				return base.BeginRead (array, offset, numBytes, userCallback, stateObject);

			ReadDelegate r = new ReadDelegate (ReadInternal);
			return r.BeginInvoke (array, offset, numBytes, userCallback, stateObject);
		}
コード例 #34
0
ファイル: MonoSyncFileStream.cs プロジェクト: nlhepler/mono
		public override IAsyncResult BeginRead (byte [] buffer, int offset, int count,
							AsyncCallback cback, object state)
		{
			if (!CanRead)
				throw new NotSupportedException ("This stream does not support reading");

			if (buffer == null)
				throw new ArgumentNullException ("buffer");

			if (count < 0)
				throw new ArgumentOutOfRangeException ("count", "Must be >= 0");

			if (offset < 0)
				throw new ArgumentOutOfRangeException ("offset", "Must be >= 0");

			ReadDelegate d = new ReadDelegate (this.Read);
			return d.BeginInvoke (buffer, offset, count, cback, state);
		}