@@ -51,10 +51,11 @@ static int ws__callback_established(struct lws * wsi, ti_ws_t * pss)
5151 return -1 ;
5252}
5353
54- static inline void ws__write_done (ti_ws_t * pss )
54+ static inline void ws__done (ti_ws_t * pss , ti_write_t * req , ex_enum status )
5555{
5656 (void ) queue_shift (pss -> queue );
5757 pss -> f = 0 ; /* reset to frame 0 */
58+ req -> cb_ (req , status );
5859}
5960
6061static int ws__callback_server_writable (struct lws * wsi , ti_ws_t * pss )
@@ -99,16 +100,12 @@ static int ws__callback_server_writable(struct lws * wsi, ti_ws_t * pss)
99100 if (m < (int ) len )
100101 {
101102 log_error ("ERROR %d; writing to WebSocket" , m );
102- ws__write_done (pss ); /* reset to frame 0 and shift from queue */
103- req -> cb_ (req , EX_WRITE_UV );
103+ ws__done (pss , req , EX_WRITE_UV );
104104 return -1 ;
105105 }
106106
107107 if (is_end )
108- {
109- ws__write_done (pss ); /* reset to frame 0 and shift from queue */
110- req -> cb_ (req , 0 );
111- }
108+ ws__done (pss , req , 0 );
112109 else
113110 pss -> f ++ ; /* next frame */
114111
@@ -179,6 +176,11 @@ struct per_vhost_data__minimal {
179176 const struct lws_protocols * protocol ;
180177};
181178
179+ static void ws__drop_req (ti_write_t * req )
180+ {
181+ req -> cb_ (req , EX_WRITE_UV );
182+ }
183+
182184/* Callback function for WebSocket server messages */
183185int ws__callback (
184186 struct lws * wsi ,
@@ -202,8 +204,8 @@ int ws__callback(
202204 case LWS_CALLBACK_CLOSED :
203205 if (pss -> stream )
204206 {
207+ queue_destroy (pss -> queue , (queue_destroy_cb ) ws__drop_req );
205208 ti_stream_close (pss -> stream );
206- queue_destroy (pss -> queue , free );
207209 }
208210 break ;
209211 default :
0 commit comments