Skip to content

Commit

Permalink
improve map find performance and update MapContainer to MapDescriptor
Browse files Browse the repository at this point in the history
improve map find performance and update MapContainer to MapDescriptor
  • Loading branch information
alec1o committed Jun 27, 2024
1 parent 717433c commit ae199f0
Showing 1 changed file with 14 additions and 28 deletions.
42 changes: 14 additions & 28 deletions src/http/partials/Server/HTTP.ServerTo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ private async Task HandleConnection(HttpListenerContext context)
}

// SEARCH ROUTE
var myPaths = _server.MyMap.m_mapList.FindAll(x =>
var map = _server.MyMap.m_mapList.FindAll(x =>
{
// websocket connection
if (request.IsWebSocket)
Expand Down Expand Up @@ -301,38 +301,22 @@ private async Task HandleConnection(HttpListenerContext context)
}

return false;
});

}).FirstOrDefault();

// HANDLE HTTP REQUEST
if (request.IsWebSocket == false) // IS HTTP CONNECTION
if (map == null)
{
if (myPaths.Count <= 0)
{
response.Send(404, notFoundMessage);
return;
}
response.Send(404, notFoundMessage);
return;
}

myPaths.ForEach(x =>
{
x.HttpCallback?.Invoke(request, response);
#region HANDLE HTTP REQUEST

if (response.IsOpened)
{
response.Send(508, $"Loop Detected {x.Path}");
throw new NotImplementedException($"NULL response detected on [path='{x.Path}']");
}
});
if (!request.IsWebSocket) // IS HTTP CONNECTION
{
map.HttpCallback(request, response);
}
// IS WEBSOCKET CONNECTION
else
else // IS WEBSOCKET CONNECTION
{
if (myPaths.Count <= 0)
{
response.Send(404, notFoundMessage);
return;
}

var ws = await context.AcceptWebSocketAsync(null);

var websocket = new WebSocket(ws.WebSocket, request);
Expand All @@ -350,10 +334,12 @@ private async Task HandleConnection(HttpListenerContext context)
}
});

myPaths.ForEach(x => x.WebsocketCallback?.Invoke(request, websocket));
map.WebsocketCallback?.Invoke(request, websocket);

websocket.InitWebSocketServerSide();
}

#endregion
}
}
}
Expand Down

0 comments on commit ae199f0

Please sign in to comment.