[System]: Add new internal X509Certificate2Impl.IntermediateCertificates.
[mono-project.git] / mono / tests / async_read.cs
blob4bb59149a60cb6a6cd6321d486add83ac6c105cc
1 using System;
2 using System.IO;
3 using System.Threading;
5 class Test {
7 static int sum = 0;
8 static int count = 0;
10 static void async_callback (IAsyncResult ar)
12 byte [] buf = (byte [])ar.AsyncState;
13 Interlocked.Add (ref sum, buf [0]);
14 Interlocked.Increment (ref count);
17 static int Main () {
18 byte [] buf = new byte [1];
19 AsyncCallback ac = new AsyncCallback (async_callback);
20 IAsyncResult ar;
21 int sum0 = 0;
22 int count0 = 0;
24 FileStream s = new FileStream ("async_read.exe", FileMode.Open, FileAccess.Read);
26 s.Position = 0;
27 while (s.Read (buf, 0, 1) == 1) {
28 sum0 += buf [0];
29 count0 ++;
32 s.Position = 0;
34 do {
35 buf = new byte [1];
36 ar = s.BeginRead (buf, 0, 1, ac, buf);
37 } while (s.EndRead (ar) == 1);
39 Thread.Sleep (100);
41 s.Close ();
43 count0 ++; // async_callback is invoked for the "finished reading" case too
44 Console.WriteLine ("CSUM: " + sum + " " + sum0);
45 Console.WriteLine ("Count: " + count + " " + count0);
46 if (sum != sum0 || count != count0)
47 return 1;
49 return 0;