mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 15:02:19 +00:00
Use string pointers for the telnet output to avoid concurrency map read/write
This commit is contained in:
parent
770862cb7d
commit
6d9fe4a028
@ -13,7 +13,7 @@ var (
|
||||
// Cfg contains the different options of the telnet package, see below
|
||||
// TODO Config should not be exported
|
||||
Cfg *Options
|
||||
currentMessage map[string]string
|
||||
currentMessage map[string]*string
|
||||
)
|
||||
|
||||
// Options holds telnet package configuration
|
||||
@ -33,7 +33,7 @@ func Serve(config *Options) {
|
||||
return
|
||||
}
|
||||
|
||||
currentMessage = make(map[string]string)
|
||||
currentMessage = make(map[string]*string)
|
||||
|
||||
listener, err := net.Listen("tcp", Cfg.ListenAddress)
|
||||
if err != nil {
|
||||
@ -92,7 +92,7 @@ func Serve(config *Options) {
|
||||
}
|
||||
|
||||
for {
|
||||
n, err := s.Write([]byte(currentMessage[streamID]))
|
||||
n, err := s.Write([]byte(*currentMessage[streamID]))
|
||||
if err != nil {
|
||||
log.Printf("Error while sending TCP data: %s", err)
|
||||
_ = s.Close()
|
||||
@ -123,6 +123,7 @@ func StartASCIIArtStream(streamID string, reader io.ReadCloser) {
|
||||
return
|
||||
}
|
||||
|
||||
currentMessage[streamID] = new(string)
|
||||
buff := make([]byte, Cfg.Width*Cfg.Height)
|
||||
header := "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"
|
||||
for {
|
||||
@ -138,6 +139,6 @@ func StartASCIIArtStream(streamID string, reader io.ReadCloser) {
|
||||
}
|
||||
imageStr += "\n"
|
||||
}
|
||||
currentMessage[streamID] = header + imageStr
|
||||
*(currentMessage[streamID]) = header + imageStr
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user