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
}
net.lock.Lock()
net.conn = uc
net.lock.Unlock()
net.user.events <- eventUpstreamConnected{uc}
if err := uc.readMessages(net.user.events); err != nil {
uc.logger.Printf("failed to handle messages: %v", err)
}
uc.Close()
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) {
case eventUpstreamConnected:
uc := e.uc
uc.network.lock.Lock()
uc.network.conn = uc
uc.network.lock.Unlock()
uc.updateAway()
case eventUpstreamDisconnected:
uc := e.uc
uc.network.lock.Lock()
uc.network.conn = nil
uc.network.lock.Unlock()
for _, log := range uc.logs {
log.file.Close()
}
uc.endPendingLISTs(true)
case eventUpstreamMessage:
msg, uc := e.msg, e.uc