commit 8af4a8d1db4aca36417d33e2020d069db02330c1
parent 96603232a44572accc7e421b3233083d8b845a35
Author: Vetle Haflan <vetle@haflan.dev>
Date: Fri, 29 Jan 2021 00:00:31 +0100
Make Room.listen() thread safe too
Fixes error:
read tcp 127.0.0.1:8080->127.0.0.1:55450: use of closed network connection
Diffstat:
1 file changed, 2 insertions(+), 0 deletions(-)
diff --git a/lipre.go b/lipre.go
@@ -68,6 +68,7 @@ func (room *Room) Close(presenter bool) {
func (room *Room) listen() {
for {
+ room.mu.Lock()
var file File
err := room.presenter.ReadJSON(&file)
if err != nil {
@@ -86,6 +87,7 @@ func (room *Room) listen() {
}
viewerConn.WriteJSON(&file)
}
+ room.mu.Unlock()
}
}