~samwhited/xmpp

a7717df100859564fa3120c113b202d248377a96 — Sam Whited 5 years ago 16f780a
compress: Fix feature to use an io.ReadWriter
2 files changed, 10 insertions(+), 10 deletions(-)

M compress/compression.go
M compress/methods.go
M compress/compression.go => compress/compression.go +5 -5
@@ 83,7 83,7 @@ func New(methods ...Method) xmpp.StreamFeature {

			return true, listed.Methods, nil
		},
		Negotiate: func(ctx context.Context, session *xmpp.Session, data interface{}) (mask xmpp.SessionState, rwc io.ReadWriteCloser, err error) {
		Negotiate: func(ctx context.Context, session *xmpp.Session, data interface{}) (mask xmpp.SessionState, rw io.ReadWriter, err error) {
			conn := session.Conn()

			// If we're a server.


@@ 120,8 120,8 @@ func New(methods ...Method) xmpp.StreamFeature {
					return
				}

				rwc, err = selected.Wrapper(conn)
				return mask, rwc, err
				rw, err = selected.Wrapper(conn)
				return mask, rw, err
			}

			var selected Method


@@ 154,8 154,8 @@ func New(methods ...Method) xmpp.StreamFeature {
				if err = d.Skip(); err != nil {
					return mask, nil, err
				}
				rwc, err = selected.Wrapper(conn)
				return mask, rwc, err
				rw, err = selected.Wrapper(conn)
				return mask, rw, err
			}

			// TODO: Use appropriate errors.

M compress/methods.go => compress/methods.go +5 -5
@@ 16,7 16,7 @@ import (
// Editor: https://xmpp.org/registrar/compress.html
type Method struct {
	Name    string
	Wrapper func(io.ReadWriteCloser) (io.ReadWriteCloser, error)
	Wrapper func(io.ReadWriter) (io.ReadWriter, error)
}

type multiCloser []io.Closer


@@ 44,7 44,7 @@ func (mc multiCloser) Close() (err error) {
type zlibDelayedSetup struct {
	wm, rm sync.Mutex

	raw        io.ReadWriteCloser
	raw        io.ReadWriter
	zlibWriter *zlib.Writer
	zlibReader io.ReadCloser
}


@@ 78,7 78,7 @@ func (r *zlibDelayedSetup) Read(p []byte) (n int, err error) {

func (r *zlibDelayedSetup) Close() error {

	mc := multiCloser{r.raw}
	mc := multiCloser{}

	r.rm.Lock()
	defer r.rm.Unlock()


@@ 97,7 97,7 @@ func (r *zlibDelayedSetup) Close() error {

var zlibMethod = Method{
	Name: "zlib",
	Wrapper: func(rwc io.ReadWriteCloser) (io.ReadWriteCloser, error) {
		return &zlibDelayedSetup{raw: rwc, zlibWriter: zlib.NewWriter(rwc)}, nil
	Wrapper: func(rw io.ReadWriter) (io.ReadWriter, error) {
		return &zlibDelayedSetup{raw: rw, zlibWriter: zlib.NewWriter(rw)}, nil
	},
}