Esempio n. 1
0
 public HttpConnection(TestContext ctx, HttpServer server, Stream stream, ISslStream sslStream = null)
     : base(stream)
 {
     Context   = ctx;
     Server    = server;
     SslStream = sslStream;
 }
Esempio n. 2
0
        void StartServer(TestContext ctx, CancellationToken cancellationToken)
        {
            var endpoint = GetEndPoint();

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.Bind(endpoint);
            socket.Listen(1);

            ctx.LogMessage("Listening at {0}.", endpoint);

            tcs = new TaskCompletionSource <ISslStream> ();

            socket.BeginAccept(async ar => {
                try {
                    accepted = socket.EndAccept(ar);
                    cancellationToken.ThrowIfCancellationRequested();
                    ctx.LogMessage("Accepted connection from {0}.", accepted.RemoteEndPoint);
                    var stream = CreateStream(accepted);
                    sslStream  = await Start(ctx, stream, cancellationToken);
                    tcs.SetResult(sslStream);
                } catch (Exception ex) {
                    tcs.SetException(ex);
                }
            }, null);
        }
Esempio n. 3
0
 protected override void Stop()
 {
     try {
         if (sslStream != null)
         {
             sslStream.Close();
             sslStream = null;
         }
     } catch {
         ;
     }
     if (accepted != null)
     {
         try {
             accepted.Shutdown(SocketShutdown.Both);
         } catch {
             ;
         }
         try {
             accepted.Dispose();
         } catch {
             ;
         }
         accepted = null;
     }
     if (socket != null)
     {
         try {
             socket.Shutdown(SocketShutdown.Both);
         } catch {
             ;
         }
         try {
             socket.Dispose();
         } catch {
             ;
         }
         socket = null;
     }
 }
Esempio n. 4
0
        void StartClient(TestContext ctx, CancellationToken cancellationToken)
        {
            var endpoint = GetEndPoint();

            socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            ctx.LogMessage("Connecting to {0}.", endpoint);

            tcs = new TaskCompletionSource <ISslStream> ();

            socket.BeginConnect(endpoint, async ar => {
                try {
                    socket.EndConnect(ar);
                    cancellationToken.ThrowIfCancellationRequested();
                    var stream = CreateStream(socket);
                    sslStream  = await Start(ctx, stream, cancellationToken);
                    tcs.SetResult(sslStream);
                } catch (Exception ex) {
                    tcs.SetException(ex);
                }
            }, null);
        }