]> git.r.bdr.sh - rbdr/mobius/commitdiff
Minor improvements to sendTransaction
authorJeff Halter <redacted>
Mon, 21 Nov 2022 17:10:24 +0000 (09:10 -0800)
committerJeff Halter <redacted>
Mon, 21 Nov 2022 17:10:24 +0000 (09:10 -0800)
1. Remove use of defer for the unlock because it make hold the mutex longer than necessary
2. Remove shadowed err var on L166

hotline/server.go

index e28ff9a597dc93ef7f8a6d06d0430290150dd14d..1aa9b1a35e074aae26dd90e4dc3f280049c79972 100644 (file)
@@ -152,8 +152,8 @@ func (s *Server) sendTransaction(t Transaction) error {
        }
 
        s.mux.Lock()
-       defer s.mux.Unlock()
        client := s.Clients[uint16(clientID)]
+       s.mux.Unlock()
        if client == nil {
                return fmt.Errorf("invalid client id %v", *t.clientID)
        }
@@ -163,7 +163,8 @@ func (s *Server) sendTransaction(t Transaction) error {
                return err
        }
 
-       if _, err := client.Connection.Write(b); err != nil {
+       _, err = client.Connection.Write(b)
+       if err != nil {
                return err
        }