@@ -243,6 +243,9 @@ func (c *connection) ReadByte() (b byte, err error) {
243243
244244// Malloc implements Connection.
245245func (c * connection ) Malloc (n int ) (buf []byte , err error ) {
246+ if ! c .IsActive () {
247+ return nil , Exception (ErrConnClosed , "when malloc" )
248+ }
246249 return c .outputBuffer .Malloc (n )
247250}
248251
@@ -273,31 +276,49 @@ func (c *connection) Flush() error {
273276
274277// MallocAck implements Connection.
275278func (c * connection ) MallocAck (n int ) (err error ) {
279+ if ! c .IsActive () {
280+ return Exception (ErrConnClosed , "when malloc ack" )
281+ }
276282 return c .outputBuffer .MallocAck (n )
277283}
278284
279285// Append implements Connection.
280286func (c * connection ) Append (w Writer ) (err error ) {
287+ if ! c .IsActive () {
288+ return Exception (ErrConnClosed , "when append" )
289+ }
281290 return c .outputBuffer .Append (w )
282291}
283292
284293// WriteString implements Connection.
285294func (c * connection ) WriteString (s string ) (n int , err error ) {
295+ if ! c .IsActive () {
296+ return 0 , Exception (ErrConnClosed , "when write string" )
297+ }
286298 return c .outputBuffer .WriteString (s )
287299}
288300
289301// WriteBinary implements Connection.
290302func (c * connection ) WriteBinary (b []byte ) (n int , err error ) {
303+ if ! c .IsActive () {
304+ return 0 , Exception (ErrConnClosed , "when write binary" )
305+ }
291306 return c .outputBuffer .WriteBinary (b )
292307}
293308
294309// WriteDirect implements Connection.
295310func (c * connection ) WriteDirect (p []byte , remainCap int ) (err error ) {
311+ if ! c .IsActive () {
312+ return Exception (ErrConnClosed , "when write direct" )
313+ }
296314 return c .outputBuffer .WriteDirect (p , remainCap )
297315}
298316
299317// WriteByte implements Connection.
300318func (c * connection ) WriteByte (b byte ) (err error ) {
319+ if ! c .IsActive () {
320+ return Exception (ErrConnClosed , "when write byte" )
321+ }
301322 return c .outputBuffer .WriteByte (b )
302323}
303324
0 commit comments