~samwhited/xmpp

b3285f765e521841d14e3380f6e37998c32a17b8 — Sam Whited 4 years ago 5b35c42
Error if we read from a closed input stream
1 files changed, 8 insertions(+), 0 deletions(-)

M conn.go
M conn.go => conn.go +8 -0
@@ 33,6 33,7 @@ type Conn struct {
	flock    sync.Mutex

	in struct {
		sync.Mutex
		stream
		d *xml.Decoder
	}


@@ 73,6 74,13 @@ func (c *Conn) Config() *Config {

// Read reads data from the connection.
func (c *Conn) Read(b []byte) (n int, err error) {
	c.in.Lock()
	defer c.in.Unlock()

	if c.state&InputStreamClosed == InputStreamClosed {
		return 0, errors.New("XML input stream is closed")
	}

	return c.rwc.Read(b)
}