diff --git a/tui/funcs.go b/tui/funcs.go index 0d4a12f..8d0c01b 100644 --- a/tui/funcs.go +++ b/tui/funcs.go @@ -81,6 +81,7 @@ func FE_ConnectTLS(t *TUI, data dataT) error { } t.stateChannel <- "TLS Connected" t.isConnected = true + go t.launchReadingMessagesFromConnection() return nil } diff --git a/tui/input.go b/tui/input.go deleted file mode 100644 index 89aa0ee..0000000 --- a/tui/input.go +++ /dev/null @@ -1 +0,0 @@ -package tui diff --git a/tui/reading.go b/tui/reading.go new file mode 100644 index 0000000..b13c667 --- /dev/null +++ b/tui/reading.go @@ -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] + } +}