~samwhited/xmpp

5b35c42716a1fb686c4052197df07b61a0e1f718 — Sam Whited 4 years ago c16b6ef
Error if we write to a closed output stream
1 files changed, 8 insertions(+), 0 deletions(-)

M conn.go
M conn.go => conn.go +8 -0
@@ 37,6 37,7 @@ type Conn struct {
		d *xml.Decoder
	}
	out struct {
		sync.Mutex
		stream
		e *xml.Encoder
	}


@@ 77,6 78,13 @@ func (c *Conn) Read(b []byte) (n int, err error) {

// Write writes data to the connection.
func (c *Conn) Write(b []byte) (n int, err error) {
	c.out.Lock()
	defer c.out.Unlock()

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

	return c.rwc.Write(b)
}