mirror of
https://github.com/Sarsoo/Spotify.NET.git
synced 2024-12-24 15:06:26 +00:00
Cleaning up after timeout
Proper Re-Use is now possible
This commit is contained in:
parent
f0290fa037
commit
234a522f8f
@ -44,15 +44,20 @@ namespace SpotifyAPI.Web.Auth
|
|||||||
authenticationWaitFlag.Set();
|
authenticationWaitFlag.Set();
|
||||||
};
|
};
|
||||||
|
|
||||||
authentication.StartHttpServer(m_ListeningPort);
|
try
|
||||||
|
{
|
||||||
|
authentication.StartHttpServer(m_ListeningPort);
|
||||||
|
|
||||||
authentication.DoAuth();
|
authentication.DoAuth();
|
||||||
|
|
||||||
authenticationWaitFlag.WaitOne(m_Timeout);
|
authenticationWaitFlag.WaitOne(m_Timeout);
|
||||||
if (spotifyWebApi == null)
|
if (spotifyWebApi == null)
|
||||||
throw new TimeoutException($"No valid response received for the last {m_Timeout.TotalSeconds} seconds");
|
throw new TimeoutException($"No valid response received for the last {m_Timeout.TotalSeconds} seconds");
|
||||||
|
}
|
||||||
authentication.StopHttpServer();
|
finally
|
||||||
|
{
|
||||||
|
authentication.StopHttpServer();
|
||||||
|
}
|
||||||
|
|
||||||
return Task.FromResult(spotifyWebApi);
|
return Task.FromResult(spotifyWebApi);
|
||||||
}
|
}
|
||||||
|
@ -87,7 +87,6 @@ namespace SpotifyAPI.Web
|
|||||||
OutputStream.Flush();
|
OutputStream.Flush();
|
||||||
_inputStream = null;
|
_inputStream = null;
|
||||||
OutputStream = null;
|
OutputStream = null;
|
||||||
socket.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ParseRequest()
|
public void ParseRequest()
|
||||||
@ -219,26 +218,8 @@ namespace SpotifyAPI.Web
|
|||||||
_listener = new TcpListener(IPAddress.Any, Port);
|
_listener = new TcpListener(IPAddress.Any, Port);
|
||||||
_listener.Start();
|
_listener.Start();
|
||||||
|
|
||||||
using (HttpProcessor processor = new HttpProcessor(this))
|
_listener.BeginAcceptTcpClient(AcceptTcpConnection, _listener);
|
||||||
{
|
|
||||||
while (IsActive)
|
|
||||||
{
|
|
||||||
_listener.BeginAcceptTcpClient(ar =>
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
TcpListener listener = (TcpListener)ar.AsyncState;
|
|
||||||
var tcpCLient = listener.EndAcceptTcpClient(ar);
|
|
||||||
processor.Process(tcpCLient);
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (ObjectDisposedException)
|
|
||||||
{
|
|
||||||
// Ignore
|
|
||||||
}
|
|
||||||
}, _listener);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (SocketException e)
|
catch (SocketException e)
|
||||||
{
|
{
|
||||||
@ -247,6 +228,28 @@ namespace SpotifyAPI.Web
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void AcceptTcpConnection(IAsyncResult ar)
|
||||||
|
{
|
||||||
|
TcpListener listener = (TcpListener)ar.AsyncState;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var tcpCLient = listener.EndAcceptTcpClient(ar);
|
||||||
|
using (HttpProcessor processor = new HttpProcessor(this))
|
||||||
|
{
|
||||||
|
processor.Process(tcpCLient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (ObjectDisposedException)
|
||||||
|
{
|
||||||
|
// Ignore
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IsActive)
|
||||||
|
return;
|
||||||
|
//listener.Start();
|
||||||
|
listener.BeginAcceptTcpClient(AcceptTcpConnection, listener);
|
||||||
|
}
|
||||||
|
|
||||||
public abstract void HandleGetRequest(HttpProcessor p);
|
public abstract void HandleGetRequest(HttpProcessor p);
|
||||||
|
|
||||||
public abstract void HandlePostRequest(HttpProcessor p, StreamReader inputData);
|
public abstract void HandlePostRequest(HttpProcessor p, StreamReader inputData);
|
||||||
|
Loading…
Reference in New Issue
Block a user