@@ -314,8 +314,11 @@ add_channel(void)
314314}
315315
316316/*
317+ * Called when the refcount of a channel is zero.
317318 * Return TRUE if "channel" has a callback and the associated job wasn't
318319 * killed.
320+ * If the job was killed the channel is not expected to work anymore.
321+ * If there is no callback then nobody can get readahead.
319322 */
320323 static int
321324channel_still_useful (channel_T * channel )
@@ -334,12 +337,17 @@ channel_still_useful(channel_T *channel)
334337 * Close a channel and free all its resources if there is no further action
335338 * possible, there is no callback to be invoked or the associated job was
336339 * killed.
340+ * Return TRUE if the channel was freed.
337341 */
338- void
342+ int
339343channel_may_free (channel_T * channel )
340344{
341345 if (!channel_still_useful (channel ))
346+ {
342347 channel_free (channel );
348+ return TRUE;
349+ }
350+ return FALSE;
343351}
344352
345353/*
@@ -350,6 +358,7 @@ channel_free(channel_T *channel)
350358{
351359 channel_close (channel , TRUE);
352360 channel_clear (channel );
361+ ch_log (channel , "Freeing channel" );
353362 if (channel -> ch_next != NULL )
354363 channel -> ch_next -> ch_prev = channel -> ch_prev ;
355364 if (channel -> ch_prev == NULL )
@@ -794,6 +803,10 @@ channel_set_pipes(channel_T *channel, sock_T in, sock_T out, sock_T err)
794803}
795804#endif
796805
806+ /*
807+ * Sets the job the channel is associated with.
808+ * This does not keep a refcount, when the job is freed ch_job is cleared.
809+ */
797810 void
798811channel_set_job (channel_T * channel , job_T * job )
799812{
@@ -951,10 +964,15 @@ invoke_callback(channel_T *channel, char_u *callback, typval_T *argv)
951964 clear_tv (& rettv );
952965
953966 /* If an echo command was used the cursor needs to be put back where
954- * it belongs. */
967+ * it belongs. If highlighting was changed a redraw is needed. */
968+ update_screen (0 );
955969 setcursor ();
956970 cursor_on ();
957971 out_flush ();
972+ #ifdef FEAT_GUI
973+ gui_update_cursor (TRUE, FALSE);
974+ gui_mch_flush ();
975+ #endif
958976}
959977
960978/*
@@ -1440,7 +1458,10 @@ may_invoke_callback(channel_T *channel, int part)
14401458 if (callback == NULL && buffer == NULL )
14411459 {
14421460 while ((msg = channel_get (channel , part )) != NULL )
1461+ {
1462+ ch_logs (channel , "Dropping message '%s'" , (char * )msg );
14431463 vim_free (msg );
1464+ }
14441465 return FALSE;
14451466 }
14461467
@@ -1494,7 +1515,8 @@ may_invoke_callback(channel_T *channel, int part)
14941515 {
14951516 if (item -> cq_seq_nr == seq_nr )
14961517 {
1497- ch_log (channel , "Invoking one-time callback" );
1518+ ch_logs (channel , "Invoking one-time callback '%s'" ,
1519+ (char * )item -> cq_callback );
14981520 /* Remove the item from the list first, if the callback
14991521 * invokes ch_close() the list will be cleared. */
15001522 remove_cb_node (head , item );
@@ -1507,7 +1529,7 @@ may_invoke_callback(channel_T *channel, int part)
15071529 item = item -> cq_next ;
15081530 }
15091531 if (!done )
1510- ch_log (channel , "Dropping message without callback" );
1532+ ch_logn (channel , "Dropping message %d without callback" , seq_nr );
15111533 }
15121534 else if (callback != NULL || buffer != NULL )
15131535 {
@@ -1558,6 +1580,8 @@ may_invoke_callback(channel_T *channel, int part)
15581580 invoke_callback (channel , callback , argv );
15591581 }
15601582 }
1583+ else if (msg != NULL )
1584+ ch_logs (channel , "Dropping message '%s'" , (char * )msg );
15611585 else
15621586 ch_log (channel , "Dropping message" );
15631587
@@ -1656,6 +1680,8 @@ channel_close(channel_T *channel, int invoke_close_cb)
16561680
16571681 /* invoke the close callback; increment the refcount to avoid it
16581682 * being freed halfway */
1683+ ch_logs (channel , "Invoking close callback %s" ,
1684+ (char * )channel -> ch_close_cb );
16591685 argv [0 ].v_type = VAR_CHANNEL ;
16601686 argv [0 ].vval .v_channel = channel ;
16611687 ++ channel -> ch_refcount ;
@@ -1723,6 +1749,7 @@ channel_clear_one(channel_T *channel, int part)
17231749 void
17241750channel_clear (channel_T * channel )
17251751{
1752+ ch_log (channel , "Clearing channel" );
17261753 channel_clear_one (channel , PART_SOCK );
17271754#ifdef CHANNEL_PIPES
17281755 channel_clear_one (channel , PART_OUT );
@@ -1740,6 +1767,7 @@ channel_free_all(void)
17401767{
17411768 channel_T * channel ;
17421769
1770+ ch_log (NULL , "channel_free_all()" );
17431771 for (channel = first_channel ; channel != NULL ; channel = channel -> ch_next )
17441772 channel_clear (channel );
17451773}
@@ -1817,7 +1845,6 @@ channel_wait(channel_T *channel, sock_T fd, int timeout)
18171845 return OK ;
18181846#endif
18191847 }
1820- ch_log (channel , "Nothing to read" );
18211848 return FAIL ;
18221849}
18231850
@@ -1989,11 +2016,11 @@ channel_read_block(channel_T *channel, int part, int timeout)
19892016 */
19902017 int
19912018channel_read_json_block (
1992- channel_T * channel ,
1993- int part ,
1994- int timeout ,
1995- int id ,
1996- typval_T * * rettv )
2019+ channel_T * channel ,
2020+ int part ,
2021+ int timeout ,
2022+ int id ,
2023+ typval_T * * rettv )
19972024{
19982025 int more ;
19992026 sock_T fd ;
0 commit comments