@@ -14,7 +14,6 @@ namespace Halibut.Transport
1414 public class SecureWebSocketListener : IDisposable
1515 {
1616 readonly string endPoint ;
17- readonly X509Certificate2 serverCertificate ;
1817 readonly Func < MessageExchangeProtocol , Task > protocolHandler ;
1918 readonly Predicate < string > verifyClientThumbprint ;
2019 readonly Func < string , string , UnauthorizedClientConnectResponse > unauthorizedClientConnect ;
@@ -53,7 +52,6 @@ public SecureWebSocketListener(string endPoint, X509Certificate2 serverCertifica
5352 endPoint += "/" ;
5453
5554 this . endPoint = endPoint ;
56- this . serverCertificate = serverCertificate ;
5755 this . protocolHandler = protocolHandler ;
5856 this . verifyClientThumbprint = verifyClientThumbprint ;
5957 this . unauthorizedClientConnect = unauthorizedClientConnect ;
@@ -75,7 +73,7 @@ public void Start()
7573
7674 log = logFactory . ForPrefix ( endPoint ) ;
7775 log . Write ( EventType . ListenerStarted , "Listener started" ) ;
78- Task . Run ( async ( ) => await Accept ( ) ) ;
76+ Task . Run ( async ( ) => await Accept ( ) . ConfigureAwait ( false ) ) . ConfigureAwait ( false ) ;
7977 }
8078
8179 async Task Accept ( )
@@ -86,12 +84,12 @@ async Task Accept()
8684 {
8785 try
8886 {
89- var context = await listener . GetContextAsync ( ) ;
87+ var context = await listener . GetContextAsync ( ) . ConfigureAwait ( false ) ;
9088
9189 if ( context . Request . IsWebSocketRequest )
9290 {
9391#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
94- HandleClient ( context ) ;
92+ Task . Run ( async ( ) => await HandleClient ( context ) . ConfigureAwait ( false ) ) . ConfigureAwait ( false ) ;
9593#pragma warning restore CS4014
9694 }
9795 else
@@ -115,7 +113,7 @@ async Task HandleClient(HttpListenerContext context)
115113 try
116114 {
117115 log . Write ( EventType . ListenerAcceptedClient , "Accepted Web Socket client: {0}" , context . Request . RemoteEndPoint ) ;
118- await ExecuteRequest ( context ) ;
116+ await ExecuteRequest ( context ) . ConfigureAwait ( false ) ;
119117 }
120118 catch ( ObjectDisposedException )
121119 {
@@ -136,10 +134,10 @@ async Task ExecuteRequest(HttpListenerContext listenerContext)
136134 WebSocketStream webSocketStream = null ;
137135 try
138136 {
139- var webSocketContext = await listenerContext . AcceptWebSocketAsync ( "Octopus" ) ;
137+ var webSocketContext = await listenerContext . AcceptWebSocketAsync ( "Octopus" ) . ConfigureAwait ( false ) ;
140138 webSocketStream = new WebSocketStream ( webSocketContext . WebSocket ) ;
141139
142- var req = await webSocketStream . ReadTextMessage ( ) ; // Initial message
140+ var req = await webSocketStream . ReadTextMessage ( ) . ConfigureAwait ( false ) ; // Initial message
143141 if ( string . IsNullOrEmpty ( req ) )
144142 {
145143 log . Write ( EventType . Diagnostic , "Ignoring empty request" ) ;
@@ -152,10 +150,12 @@ async Task ExecuteRequest(HttpListenerContext listenerContext)
152150 return ;
153151 }
154152
155- if ( await Authorize ( listenerContext , clientName ) )
153+ var authorized = await Authorize ( listenerContext , clientName ) . ConfigureAwait ( false ) ;
154+
155+ if ( authorized )
156156 {
157157 // Delegate the open stream to the protocol handler - we no longer own the stream lifetime
158- await ExchangeMessages ( webSocketStream ) ;
158+ await ExchangeMessages ( webSocketStream ) . ConfigureAwait ( false ) ;
159159
160160 // Mark the stream as delegated once everything has succeeded
161161 keepConnection = true ;
@@ -202,7 +202,7 @@ void SendFriendlyHtmlPage(HttpListenerResponse response)
202202 async Task < bool > Authorize ( HttpListenerContext context , EndPoint clientName )
203203 {
204204 log . Write ( EventType . Diagnostic , "Begin authorization" ) ;
205- var certificate = await context . Request . GetClientCertificateAsync ( ) ;
205+ var certificate = await context . Request . GetClientCertificateAsync ( ) . ConfigureAwait ( false ) ;
206206 if ( certificate == null )
207207 {
208208 log . Write ( EventType . ClientDenied , "A client at {0} connected, and attempted a message exchange, but did not present a client certificate" , clientName ) ;
0 commit comments