Author: spouliot
Date: 2005-04-09 12:32:24 -0400 (Sat, 09 Apr 2005)
New Revision: 42736
Added:
trunk/mcs/class/Mono.Security/Test/tools/tlstest/tlsasync.cs
Modified:
trunk/mcs/class/Mono.Security/Test/tools/tlstest/ChangeLog
trunk/mcs/class/Mono.Security/Test/tools/tlstest/Makefile
trunk/mcs/class/Mono.Security/Test/tools/tlstest/tlsmulti.cs
Log:
2005-04-09 Sebastien Pouliot <[EMAIL PROTECTED]>
* tlsasync.cs: New. Async HttpWebRequest and streams using HTTP or
HTTPS GET. Display the web page if only one URL is supplied.
* Makefile: Build tlsasync tool.
Modified: trunk/mcs/class/Mono.Security/Test/tools/tlstest/ChangeLog
===================================================================
--- trunk/mcs/class/Mono.Security/Test/tools/tlstest/ChangeLog 2005-04-09
16:21:31 UTC (rev 42735)
+++ trunk/mcs/class/Mono.Security/Test/tools/tlstest/ChangeLog 2005-04-09
16:32:24 UTC (rev 42736)
@@ -1,3 +1,9 @@
+2005-04-09 Sebastien Pouliot <[EMAIL PROTECTED]>
+
+ * tlsasync.cs: New. Async HttpWebRequest and streams using HTTP or
+ HTTPS GET. Display the web page if only one URL is supplied.
+ * Makefile: Build tlsasync tool.
+
2005-04-08 Sebastien Pouliot <[EMAIL PROTECTED]>
* tlsmulti.cs: Display the web page if only one URL is supplied. Show
Modified: trunk/mcs/class/Mono.Security/Test/tools/tlstest/Makefile
===================================================================
--- trunk/mcs/class/Mono.Security/Test/tools/tlstest/Makefile 2005-04-09
16:21:31 UTC (rev 42735)
+++ trunk/mcs/class/Mono.Security/Test/tools/tlstest/Makefile 2005-04-09
16:32:24 UTC (rev 42736)
@@ -15,16 +15,19 @@
clean-local:
rm -f *.exe *.pdb
-sources = tlstest.cs tlsmulti.cs
+sources = tlstest.cs tlsmulti.cs tlsasync.cs
DISTFILES = $(sources)
dist-local: dist-default
-all: tlstest.exe tlsmulti.exe
+all: tlstest.exe tlsmulti.exe tlsasync.exe
tlstest.exe: tlstest.cs
$(CSCOMPILE) /target:exe /out:$@ $^
tlsmulti.exe: tlsmulti.cs
$(CSCOMPILE) /target:exe /out:$@ $^
+
+tlsasync.exe: tlsasync.cs
+ $(CSCOMPILE) /target:exe /out:$@ $^
Added: trunk/mcs/class/Mono.Security/Test/tools/tlstest/tlsasync.cs
===================================================================
--- trunk/mcs/class/Mono.Security/Test/tools/tlstest/tlsasync.cs
2005-04-09 16:21:31 UTC (rev 42735)
+++ trunk/mcs/class/Mono.Security/Test/tools/tlstest/tlsasync.cs
2005-04-09 16:32:24 UTC (rev 42736)
@@ -0,0 +1,150 @@
+//
+// tlsasync.cs: Multi-sessions TLS/SSL Test Program with async streams
+// based on tlstest.cs and tlsmulti.cs
+//
+// Author:
+// Sebastien Pouliot <[EMAIL PROTECTED]>
+//
+// Copyright (C) 2004-2005 Novell (http://www.novell.com)
+//
+
+using System;
+using System.Collections;
+using System.Globalization;
+using System.IO;
+using System.Net;
+using System.Net.Sockets;
+using System.Reflection;
+using System.Security.Cryptography.X509Certificates;
+using System.Text;
+using System.Threading;
+
+using Mono.Security.Protocol.Tls;
+
+public class State {
+
+ static ArrayList handleList = new ArrayList ();
+
+ private int id;
+ private HttpWebRequest request;
+ private ManualResetEvent handle;
+ private Stream stream;
+ private byte[] buffer;
+ private MemoryStream memory;
+
+ public State (int id, HttpWebRequest req)
+ {
+ this.id = id;
+ request = req;
+ handle = new ManualResetEvent (false);
+ handleList.Add (handle);
+ }
+
+ public int Id {
+ get { return id; }
+ }
+
+ public HttpWebRequest Request {
+ get { return request; }
+ }
+
+ public Stream Stream {
+ get { return stream; }
+ set { stream = value; }
+ }
+
+ public byte[] Buffer {
+ get {
+ if (buffer == null)
+ buffer = new byte [256]; // really small on
purpose
+ return buffer;
+ }
+ }
+
+ public Stream Memory {
+ get {
+ if (memory == null)
+ memory = new MemoryStream ();
+ return memory;
+ }
+ }
+
+ public void Complete ()
+ {
+ handle.Set ();
+ }
+
+ static public void WaitAll ()
+ {
+ if (handleList.Count > 0) {
+ WaitHandle[] handles = (WaitHandle[])
handleList.ToArray (typeof (WaitHandle));
+ WaitHandle.WaitAll (handles);
+ handleList.Clear ();
+ }
+ }
+}
+
+public class MultiTest {
+
+ static bool alone;
+
+ public static void Main (string[] args)
+ {
+ if (args.Length == 0) {
+ Console.WriteLine ("usage: mono testmulti.exe url1 [url
...]");
+ return;
+ } else if (args.Length > 64) {
+ Console.WriteLine ("WaitHandle has a limit of 64
handles so you cannot process {0} URLs.", args.Length);
+ return;
+ }
+
+ alone = (args.Length == 1);
+ ServicePointManager.CertificatePolicy = new
TestCertificatePolicy ();
+
+ int id = 1;
+ foreach (string url in args) {
+ Console.WriteLine ("GET #{0} at {1}", id, url);
+ HttpWebRequest wreq = (HttpWebRequest)
WebRequest.Create (url);
+ State s = new State (id++, wreq);
+ wreq.BeginGetResponse (new AsyncCallback
(ResponseCallback), s);
+ }
+
+ State.WaitAll ();
+ }
+
+ private static void ResponseCallback (IAsyncResult result)
+ {
+ State state = ((State) result.AsyncState);
+ HttpWebResponse response = (HttpWebResponse)
state.Request.EndGetResponse (result);
+ state.Stream = response.GetResponseStream ();
+ state.Stream.BeginRead (state.Buffer, 0, state.Buffer.Length,
new AsyncCallback (StreamCallBack), state);
+ }
+
+ private static void StreamCallBack (IAsyncResult result)
+ {
+ State state = ((State) result.AsyncState);
+ int length = state.Stream.EndRead (result);
+ if (length > 0) {
+ state.Memory.Write (state.Buffer, 0, length);
+ state.Stream.BeginRead (state.Buffer, 0,
state.Buffer.Length, new AsyncCallback (StreamCallBack), state);
+ } else {
+ state.Stream.Close ();
+ if (alone) {
+ state.Memory.Position = 0;
+ StreamReader sr = new StreamReader
(state.Memory, Encoding.UTF8);
+ Console.WriteLine (sr.ReadToEnd ());
+ }
+ Console.WriteLine ("END #{0}", state.Id);
+ state.Complete ();
+ }
+ }
+
+ public class TestCertificatePolicy : ICertificatePolicy {
+
+ public bool CheckValidationResult (ServicePoint sp,
X509Certificate certificate, WebRequest request, int error)
+ {
+ // whatever the reason we do not stop the SSL connection
+ return true;
+ }
+ }
+}
Modified: trunk/mcs/class/Mono.Security/Test/tools/tlstest/tlsmulti.cs
===================================================================
--- trunk/mcs/class/Mono.Security/Test/tools/tlstest/tlsmulti.cs
2005-04-09 16:21:31 UTC (rev 42735)
+++ trunk/mcs/class/Mono.Security/Test/tools/tlstest/tlsmulti.cs
2005-04-09 16:32:24 UTC (rev 42736)
@@ -1,5 +1,5 @@
//
-// tlsmulti.cs: Multi-sessions TLS/SSL Test Program
+// tlsmulti.cs: Multi-sessions TLS/SSL Test Program with async HttpWebRequest
// based on tlstest.cs
//
// Author:
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches