Mercurial > vim
comparison src/channel.c @ 8259:99a70c3b902f v7.4.1422
commit https://github.com/vim/vim/commit/46c85439c966d7ed39fb3d711d4d6c61ac964647
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Feb 26 11:17:46 2016 +0100
patch 7.4.1422
Problem: Error when reading fails uses wrong errno. Keeping channel open
after job stops results in test failing.
Solution: Move the error up. Add ch_job_killed.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Fri, 26 Feb 2016 11:30:05 +0100 |
parents | c4ffdda8cdfd |
children | a412b466bedc |
comparison
equal
deleted
inserted
replaced
8258:c753d5773e64 | 8259:99a70c3b902f |
---|---|
305 channel->ch_refcount = 1; | 305 channel->ch_refcount = 1; |
306 return channel; | 306 return channel; |
307 } | 307 } |
308 | 308 |
309 /* | 309 /* |
310 * Return TRUE if "channel" has a callback. | 310 * Return TRUE if "channel" has a callback and the associated job wasn't |
311 * killed. | |
311 */ | 312 */ |
312 static int | 313 static int |
313 channel_has_callback(channel_T *channel) | 314 channel_still_useful(channel_T *channel) |
314 { | 315 { |
316 if (channel->ch_job_killed && channel->ch_job == NULL) | |
317 return FALSE; | |
315 return channel->ch_callback != NULL | 318 return channel->ch_callback != NULL |
316 #ifdef CHANNEL_PIPES | 319 #ifdef CHANNEL_PIPES |
317 || channel->ch_part[PART_OUT].ch_callback != NULL | 320 || channel->ch_part[PART_OUT].ch_callback != NULL |
318 || channel->ch_part[PART_ERR].ch_callback != NULL | 321 || channel->ch_part[PART_ERR].ch_callback != NULL |
319 #endif | 322 #endif |
320 || channel->ch_close_cb != NULL; | 323 || channel->ch_close_cb != NULL; |
321 } | 324 } |
322 | 325 |
323 /* | 326 /* |
324 * Close a channel and free all its resources if there is no further action | 327 * Close a channel and free all its resources if there is no further action |
325 * possible, there is no callback to be invoked. | 328 * possible, there is no callback to be invoked or the associated job was |
329 * killed. | |
326 */ | 330 */ |
327 void | 331 void |
328 channel_may_free(channel_T *channel) | 332 channel_may_free(channel_T *channel) |
329 { | 333 { |
330 if (!channel_has_callback(channel)) | 334 if (!channel_still_useful(channel)) |
331 channel_free(channel); | 335 channel_free(channel); |
332 } | 336 } |
333 | 337 |
334 /* | 338 /* |
335 * Close a channel and free all its resources. | 339 * Close a channel and free all its resources. |
1772 * -> ui_breakcheck | 1776 * -> ui_breakcheck |
1773 * -> gui event loop or select loop | 1777 * -> gui event loop or select loop |
1774 * -> channel_read() | 1778 * -> channel_read() |
1775 */ | 1779 */ |
1776 ch_errors(channel, "%s(): Cannot read", func); | 1780 ch_errors(channel, "%s(): Cannot read", func); |
1781 if (len < 0) | |
1782 { | |
1783 ch_error(channel, "channel_read(): cannot read from channel"); | |
1784 PERROR(_("E896: read from channel")); | |
1785 } | |
1786 | |
1777 msg = channel->ch_part[part].ch_mode == MODE_RAW | 1787 msg = channel->ch_part[part].ch_mode == MODE_RAW |
1778 || channel->ch_part[part].ch_mode == MODE_NL | 1788 || channel->ch_part[part].ch_mode == MODE_NL |
1779 ? DETACH_MSG_RAW : DETACH_MSG_JSON; | 1789 ? DETACH_MSG_RAW : DETACH_MSG_JSON; |
1780 channel_save(channel, part, (char_u *)msg, (int)STRLEN(msg)); | 1790 channel_save(channel, part, (char_u *)msg, (int)STRLEN(msg)); |
1781 | 1791 |
1783 * keep stdin and stderr open? Probably not, assume the other side | 1793 * keep stdin and stderr open? Probably not, assume the other side |
1784 * has died. */ | 1794 * has died. */ |
1785 channel_close(channel, TRUE); | 1795 channel_close(channel, TRUE); |
1786 if (channel->ch_nb_close_cb != NULL) | 1796 if (channel->ch_nb_close_cb != NULL) |
1787 (*channel->ch_nb_close_cb)(); | 1797 (*channel->ch_nb_close_cb)(); |
1788 | |
1789 if (len < 0) | |
1790 { | |
1791 ch_error(channel, "channel_read(): cannot read from channel"); | |
1792 PERROR(_("E896: read from channel")); | |
1793 } | |
1794 } | 1798 } |
1795 | 1799 |
1796 #if defined(CH_HAS_GUI) && defined(FEAT_GUI_GTK) | 1800 #if defined(CH_HAS_GUI) && defined(FEAT_GUI_GTK) |
1797 /* signal the main loop that there is something to read */ | 1801 /* signal the main loop that there is something to read */ |
1798 if (CH_HAS_GUI && gtk_main_level() > 0) | 1802 if (CH_HAS_GUI && gtk_main_level() > 0) |
2172 int r; | 2176 int r; |
2173 int part = PART_SOCK; | 2177 int part = PART_SOCK; |
2174 | 2178 |
2175 while (channel != NULL) | 2179 while (channel != NULL) |
2176 { | 2180 { |
2177 if (channel->ch_refcount == 0 && !channel_has_callback(channel)) | 2181 if (channel->ch_refcount == 0 && !channel_still_useful(channel)) |
2178 { | 2182 { |
2179 /* channel is no longer useful, free it */ | 2183 /* channel is no longer useful, free it */ |
2180 channel_free(channel); | 2184 channel_free(channel); |
2181 channel = first_channel; | 2185 channel = first_channel; |
2182 part = PART_SOCK; | 2186 part = PART_SOCK; |