public void TestDefaultTimeout() { bool okclient = false; bool okserver = false; bool pipeready = false; var pipename = "test.pipe." + RndCrypto.NextBytes(10).ToHex(); var tc = new Thread(() => { while (!pipeready) { Thread.Sleep(50); } Thread.Sleep(50); using (var pipe = new NamedPipeClientStream(".", pipename, PipeDirection.InOut, PipeOptions.Asynchronous)) using (var binary = new BinaryStream(pipe)) { pipe.Connect(); Thread.Sleep(100); binary.WriteString("TEST"); Thread.Sleep(500); binary.WriteString("TEST"); Thread.Sleep(100); binary.ReadString(); Thread.Sleep(500); binary.ReadString(); Thread.Sleep(100); okclient = true; } }); tc.Start(); var ts = new Thread(() => { using (var pipe = new NamedPipeServerStream(pipename, PipeDirection.InOut, 1, PipeTransmissionMode.Byte, PipeOptions.Asynchronous)) using (var timeout = new TimeoutableStream(pipe)) using (var binary = new BinaryStream(timeout)) { pipeready = true; pipe.WaitForConnection(); binary.ReadString(); binary.ReadString(); binary.WriteString("TEST"); binary.WriteString("TEST"); Thread.Sleep(100); okserver = true; } }); ts.Start(); tc.Join(); ts.Join(); Assert.IsTrue(okclient); Assert.IsTrue(okserver); }
/// <summary> /// Initialises this session instance from the specified request. Only call this if you are not using <see /// cref="EnableAutomatic{TSession}(HttpRequest, Func{TSession, HttpResponse})"/>, <see /// cref="EnableAutomatic{TSession}(HttpRequest, Func{TSession, HttpResponse}, Func{TSession})"/> or <see /// cref="EnableManual"/>, as that already calls it.</summary> /// <param name="req"> /// Request containing the cookie information from which to initialise the session.</param> protected void InitialiseFromRequest(HttpRequest req) { // Try to read in an existing session if (req.Headers != null && req.Headers.Cookie != null && req.Headers.Cookie.ContainsKey(CookieName)) { SessionID = req.Headers.Cookie[CookieName].Value; _hadSession = ReadSession(); _hadCookie = true; } // Create a new session if no existing session found if (!_hadSession) { SessionID = RndCrypto.NextBytes(21).Base64UrlEncode(); NewSession(); CookieModified = true; } else { CookieModified = false; } }
/// <summary>Returns a random string of 32 characters useful as a session ID.</summary> public static string CreateNewSessionId() { return(RndCrypto.GenerateString(32)); }