minor cleanup in websocket code
Open
Nobody has claimed this yet.
- Dominant language
- Ada
- Stars
- 162
- Forks
- 45
- PR merge metrics
- No merged PRs in 30d
Description
While reviewing code for PR 209, I noticed the following function aws-net-websocket-registry.adb:
procedure Watch (WebSocket : Object_Class) is
begin
if Is_Registered (WebSocket.Id)
and then not Watched.Contains (WebSocket.Id)
then
Watched.Insert (WebSocket.Id);
Count := Count + 1;
Signal_Socket;
end if;
exception
when others =>
Unregister (WebSocket);
raise;
end Watch;
It is slightly un-optimal since it needs to do two lookups when the socket is not watched yet. Perhaps something like the following would be more efficient:
procedure Watch (WebSocket : Object_Class) is
Inserted : Boolean;
Pos : WebSocket_Set.Cursor;
begin
if Is_Registered (WebSocket.Id) then
Watched.Insert (WebSocket.Id, Pos, Inserted);
if Inserted then
Count := Count + 1;
Signal_Socket;
end if;
end if;
exception
when others =>
-- ??? Not clear why we would unregister the socket here ?
-- also, it is possible that it is still in Watched at this point, and given the first test in this procedure this
-- might be unexpected behavior.
Unregister (WebSocket);
raise;
end Watch;
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading aws-net-websocket-registry.adb and the Watch procedure's surrounding exception handling. Compare the proposed single-lookup insertion with the current behavior, especially whether Unregister should remain and how Watched is left on failure. Done means the lookup is not duplicated and the exception behavior is consistent.
Written by the indexing model from the issue text.
Assessment
- Domain
- backend, networking
- Issue type
- Refactor
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100