Set network.conn in user goroutine

One step closed to removing that lock.
This commit is contained in:
Simon Ser 2020-04-01 12:21:31 +02:00
parent 434e722f92
commit f2a0775208
No known key found for this signature in database
GPG Key ID: 0FDE7BE0E88F5E48

19
user.go
View File

@ -77,20 +77,12 @@ func (net *network) run() {
continue continue
} }
net.lock.Lock()
net.conn = uc
net.lock.Unlock()
net.user.events <- eventUpstreamConnected{uc} net.user.events <- eventUpstreamConnected{uc}
if err := uc.readMessages(net.user.events); err != nil { if err := uc.readMessages(net.user.events); err != nil {
uc.logger.Printf("failed to handle messages: %v", err) uc.logger.Printf("failed to handle messages: %v", err)
} }
uc.Close() uc.Close()
net.user.events <- eventUpstreamDisconnected{uc} net.user.events <- eventUpstreamDisconnected{uc}
net.lock.Lock()
net.conn = nil
net.lock.Unlock()
} }
} }
@ -176,12 +168,23 @@ func (u *user) run() {
switch e := e.(type) { switch e := e.(type) {
case eventUpstreamConnected: case eventUpstreamConnected:
uc := e.uc uc := e.uc
uc.network.lock.Lock()
uc.network.conn = uc
uc.network.lock.Unlock()
uc.updateAway() uc.updateAway()
case eventUpstreamDisconnected: case eventUpstreamDisconnected:
uc := e.uc uc := e.uc
uc.network.lock.Lock()
uc.network.conn = nil
uc.network.lock.Unlock()
for _, log := range uc.logs { for _, log := range uc.logs {
log.file.Close() log.file.Close()
} }
uc.endPendingLISTs(true) uc.endPendingLISTs(true)
case eventUpstreamMessage: case eventUpstreamMessage:
msg, uc := e.msg, e.uc msg, uc := e.msg, e.uc