@@ -102,13 +102,12 @@ func (rs *RedHub) OnClose(c gnet.Conn, err error) (action gnet.Action) {
102102
103103// OnTraffic fires when a socket receives data from the remote
104104func (rs * RedHub ) OnTraffic (c gnet.Conn ) (action gnet.Action ) {
105- var out []byte
106105 rs .connSync .RLock ()
107106 cb , ok := rs .redHubBufMap [c ]
108107 rs .connSync .RUnlock ()
109108
110109 if ! ok {
111- c . AsyncWrite (resp .AppendError (nil , "ERR Client is closed" ), nil )
110+ _ , _ = c . Write (resp .AppendError (nil , "ERR Client is closed" ))
112111 return gnet .None
113112 }
114113
@@ -120,28 +119,32 @@ func (rs *RedHub) OnTraffic(c gnet.Conn) (action gnet.Action) {
120119 cb .buf .Write (buf )
121120 cmds , lastbyte , err := resp .ReadCommands (cb .buf .Bytes ())
122121 if err != nil {
123- c . AsyncWrite (resp .AppendError (nil , "ERR " + err .Error ()), nil )
122+ _ , _ = c . Write (resp .AppendError (nil , "ERR " + err .Error ()))
124123 return gnet .None
125124 }
126125
127126 cb .command = append (cb .command , cmds ... )
128127 cb .buf .Reset ()
129128
130129 if len (lastbyte ) == 0 {
130+ var out []byte
131131 for len (cb .command ) > 0 {
132132 cmd := cb .command [0 ]
133133 cb .command = cb .command [1 :]
134134
135135 var status Action
136- result , status := rs .handler (cmd , out )
137- if len (result ) > 0 {
138- c .AsyncWrite (result , nil )
139- }
136+ out , status = rs .handler (cmd , out )
140137
141138 if status == Close {
139+ if len (out ) > 0 {
140+ _ , _ = c .Write (out )
141+ }
142142 return gnet .Close
143143 }
144144 }
145+ if len (out ) > 0 {
146+ _ , _ = c .Write (out )
147+ }
145148 } else {
146149 cb .buf .Write (lastbyte )
147150 }
0 commit comments