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.
This commit is contained in:
Jürgen 2016-07-19 00:04:27 +02:00
parent 14210f3654
commit 8dde236256

View File

@ -4,7 +4,9 @@ using System.Collections.Specialized;
using System.IO; using System.IO;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks;
using System.Web; using System.Web;
// offered to the public domain for any use with no restriction // offered to the public domain for any use with no restriction
@ -57,10 +59,8 @@ namespace SpotifyAPI.Web
return data; 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 // 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 // "processed" view of the world, and we want the data raw after the headers
_inputStream = new BufferedStream(socket.GetStream()); _inputStream = new BufferedStream(socket.GetStream());
@ -80,7 +80,7 @@ namespace SpotifyAPI.Web
HandlePostRequest(); HandlePostRequest();
} }
} }
catch catch (Exception ex)
{ {
WriteFailure(); WriteFailure();
} }
@ -224,9 +224,7 @@ namespace SpotifyAPI.Web
while (IsActive) while (IsActive)
{ {
TcpClient s = _listener.AcceptTcpClient(); TcpClient s = _listener.AcceptTcpClient();
Thread thread = new Thread(processor.Process); processor.Process(s);
thread.Start(s);
Thread.Sleep(1);
} }
} }
} }