diff options
Diffstat (limited to 'xmpp/encoder_decoder.go')
-rw-r--r-- | xmpp/encoder_decoder.go | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/xmpp/encoder_decoder.go b/xmpp/encoder_decoder.go index 7a917da..c340b09 100644 --- a/xmpp/encoder_decoder.go +++ b/xmpp/encoder_decoder.go @@ -2,18 +2,18 @@ package xmpp import ( "encoding/xml" - "log" + "errors" "io" + "log" "os" - "errors" ) -type encoderDecoder struct{ - session *session - ct *xml.Encoder // client transport encoder - cl *xml.Encoder // client log encoder - st *xml.Decoder // server transport decoder - sl *xml.Encoder // server log encoder +type encoderDecoder struct { + session *session + ct *xml.Encoder // client transport encoder + cl *xml.Encoder // client log encoder + st *xml.Decoder // server transport decoder + sl *xml.Encoder // server log encoder terminator chan bool } @@ -38,17 +38,29 @@ func newEncoderDecoder(s *session) encoderDecoder { func (ed *encoderDecoder) encodeToken(t xml.Token) error { var err error - defer func() { if err != nil { log.Println(err) } }() + defer func() { + if err != nil { + log.Println(err) + } + }() err = ed.ct.EncodeToken(t) - if err != nil { return err } + if err != nil { + return err + } err = ed.ct.Flush() - if err != nil { return err } + if err != nil { + return err + } err = ed.cl.EncodeToken(t) - if err != nil { return err } + if err != nil { + return err + } err = ed.cl.Flush() - if err != nil { return err } + if err != nil { + return err + } return nil } @@ -62,15 +74,21 @@ func (ed *encoderDecoder) run() { t, err := ed.st.Token() if t != nil && err == nil { err = ed.sl.EncodeToken(t) - if err != nil { log.Println("Could not encode to server stream log") } + if err != nil { + log.Println("Could not encode to server stream log") + } err = ed.sl.Flush() - if err != nil { log.Println("Could not flush server stream log") } + if err != nil { + log.Println("Could not flush server stream log") + } c := xml.CopyToken(t) ed.session.rx <- c } if err != nil { - if errors.Is(err, io.EOF) { return } - log.Println(err) // FIXME terminate session on error + if errors.Is(err, io.EOF) { + return + } + log.Println(err) // FIXME terminate session on error return } } |