From 8dde2362561ced8d331186106005132f608daca7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen?= Date: Tue, 19 Jul 2016 00:04:27 +0200 Subject: [PATCH] Stability improvement: Processing in separate threat may cause racing condition and timeouts in browser. By putting processing in original threat we get a more sequential processing and more stability. --- SpotifyAPI/Web/SimpleHttpServer.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/SpotifyAPI/Web/SimpleHttpServer.cs b/SpotifyAPI/Web/SimpleHttpServer.cs index ffc297b4..1f417b6c 100644 --- a/SpotifyAPI/Web/SimpleHttpServer.cs +++ b/SpotifyAPI/Web/SimpleHttpServer.cs @@ -4,7 +4,9 @@ using System.Collections.Specialized; using System.IO; using System.Net; using System.Net.Sockets; +using System.Text; using System.Threading; +using System.Threading.Tasks; using System.Web; // offered to the public domain for any use with no restriction @@ -57,10 +59,8 @@ namespace SpotifyAPI.Web return data; } - public void Process(object tcpClient) + public void Process(TcpClient socket) { - TcpClient socket = tcpClient as TcpClient; - // we can't use a StreamReader for input, because it buffers up extra data on us inside it's // "processed" view of the world, and we want the data raw after the headers _inputStream = new BufferedStream(socket.GetStream()); @@ -80,7 +80,7 @@ namespace SpotifyAPI.Web HandlePostRequest(); } } - catch + catch (Exception ex) { WriteFailure(); } @@ -224,9 +224,7 @@ namespace SpotifyAPI.Web while (IsActive) { TcpClient s = _listener.AcceptTcpClient(); - Thread thread = new Thread(processor.Process); - thread.Start(s); - Thread.Sleep(1); + processor.Process(s); } } }