Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

minor cleanup in websocket code #210

Open
briot opened this issue May 5, 2021 · 0 comments
Open

minor cleanup in websocket code #210

briot opened this issue May 5, 2021 · 0 comments

Comments

@briot
Copy link
Contributor

briot commented May 5, 2021

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;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant