Skip to content

Commit 8dde236

Browse files
committed
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.
1 parent 14210f3 commit 8dde236

1 file changed

Lines changed: 5 additions & 7 deletions

File tree

‎SpotifyAPI/Web/SimpleHttpServer.cs‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
using System.IO;
55
using System.Net;
66
using System.Net.Sockets;
7+
using System.Text;
78
using System.Threading;
9+
using System.Threading.Tasks;
810
using System.Web;
911

1012
// offered to the public domain for any use with no restriction
@@ -57,10 +59,8 @@ private string StreamReadLine(Stream inputStream)
5759
return data;
5860
}
5961

60-
public void Process(object tcpClient)
62+
public void Process(TcpClient socket)
6163
{
62-
TcpClient socket = tcpClient as TcpClient;
63-
6464
// we can't use a StreamReader for input, because it buffers up extra data on us inside it's
6565
// "processed" view of the world, and we want the data raw after the headers
6666
_inputStream = new BufferedStream(socket.GetStream());
@@ -80,7 +80,7 @@ public void Process(object tcpClient)
8080
HandlePostRequest();
8181
}
8282
}
83-
catch
83+
catch (Exception ex)
8484
{
8585
WriteFailure();
8686
}
@@ -224,9 +224,7 @@ public void Listen()
224224
while (IsActive)
225225
{
226226
TcpClient s = _listener.AcceptTcpClient();
227-
Thread thread = new Thread(processor.Process);
228-
thread.Start(s);
229-
Thread.Sleep(1);
227+
processor.Process(s);
230228
}
231229
}
232230
}

0 commit comments

Comments
 (0)