Now ctui reads messages from server. Yay!

This commit is contained in:
qowevisa 2024-03-14 00:32:06 +02:00
parent b51ebb0560
commit 0ef750ca97
3 changed files with 27 additions and 1 deletions

View File

@ -81,6 +81,7 @@ func FE_ConnectTLS(t *TUI, data dataT) error {
} }
t.stateChannel <- "TLS Connected" t.stateChannel <- "TLS Connected"
t.isConnected = true t.isConnected = true
go t.launchReadingMessagesFromConnection()
return nil return nil
} }

View File

@ -1 +0,0 @@
package tui

26
tui/reading.go Normal file
View File

@ -0,0 +1,26 @@
package tui
import (
"io"
"git.qowevisa.me/Qowevisa/gotell/errors"
)
// NOTE: should be launched as goroutine
func (t *TUI) launchReadingMessagesFromConnection() {
if t.messageChannel == nil {
t.errors <- errors.WrapErr("t.messageChannel", errors.NOT_INIT)
return
}
buf := make([]byte, CONST_MESSAGE_LEN)
for {
n, err := t.tlsConnection.Read(buf)
if err != nil {
if err != io.EOF {
t.errors <- errors.WrapErr("t.tlsConnection.Read", err)
}
break
}
t.messageChannel <- buf[:n]
}
}