Mercurial > vim
comparison src/channel.c @ 8049:15253130abd8 v7.4.1319
commit https://github.com/vim/vim/commit/16eb4f88000cfdba68df6c421fe44e7e029ba53e
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Feb 14 23:02:34 2016 +0100
patch 7.4.1319
Problem: Tests fail on MS-Windows and on Unix with GUI.
Solution: Fix unregistering.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 14 Feb 2016 23:15:04 +0100 |
parents | 7c74cafac0a1 |
children | 6db4b1c863ec |
comparison
equal
deleted
inserted
replaced
8048:e50896a2b629 | 8049:15253130abd8 |
---|---|
337 # ifdef FEAT_GUI_GTK | 337 # ifdef FEAT_GUI_GTK |
338 /* Tell gdk we are interested in being called when there | 338 /* Tell gdk we are interested in being called when there |
339 * is input on the editor connection socket. */ | 339 * is input on the editor connection socket. */ |
340 if (channel->ch_pfd[which].ch_inputHandler == 0) | 340 if (channel->ch_pfd[which].ch_inputHandler == 0) |
341 channel->ch_pfd[which].ch_inputHandler = gdk_input_add( | 341 channel->ch_pfd[which].ch_inputHandler = gdk_input_add( |
342 (gint)channel->ch_pfd[which].ch_fd, (GdkInputCondition) | 342 (gint)channel->ch_pfd[which].ch_fd, |
343 ((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION), | 343 (GdkInputCondition) |
344 ((int)GDK_INPUT_READ + (int)GDK_INPUT_EXCEPTION), | |
344 messageFromNetbeans, | 345 messageFromNetbeans, |
345 (gpointer)(long)channel->ch_id); | 346 (gpointer)(long)channel->ch_id); |
346 # else | 347 # else |
347 # ifdef FEAT_GUI_W32 | 348 # ifdef FEAT_GUI_W32 |
348 /* Tell Windows we are interested in receiving message when there | 349 /* Tell Windows we are interested in receiving message when there |
360 channel_gui_register(channel_T *channel) | 361 channel_gui_register(channel_T *channel) |
361 { | 362 { |
362 if (!CH_HAS_GUI) | 363 if (!CH_HAS_GUI) |
363 return; | 364 return; |
364 | 365 |
365 if (channel->ch_pfd[CHAN_SOCK].ch_fd >= 0) | 366 if (channel->CH_SOCK >= 0) |
366 channel_gui_register_one(channel, CHAN_SOCK); | 367 channel_gui_register_one(channel, CHAN_SOCK); |
367 # ifdef CHANNEL_PIPES | 368 # ifdef CHANNEL_PIPES |
368 if (channel->ch_pfd[CHAN_OUT].ch_fd >= 0) | 369 if (channel->CH_OUT >= 0) |
369 channel_gui_register_one(channel, CHAN_OUT); | 370 channel_gui_register_one(channel, CHAN_OUT); |
370 if (channel->ch_pfd[CHAN_ERR].ch_fd >= 0) | 371 if (channel->CH_ERR >= 0) |
371 channel_gui_register_one(channel, CHAN_ERR); | 372 channel_gui_register_one(channel, CHAN_ERR); |
372 # endif | 373 # endif |
373 } | 374 } |
374 | 375 |
375 /* | 376 /* |
384 for (channel = first_channel; channel != NULL; channel = channel->ch_next) | 385 for (channel = first_channel; channel != NULL; channel = channel->ch_next) |
385 channel_gui_register(channel); | 386 channel_gui_register(channel); |
386 } | 387 } |
387 | 388 |
388 static void | 389 static void |
389 channel_gui_unregister_one(channel_T *channel, int which) | 390 channel_gui_unregister(channel_T *channel) |
390 { | 391 { |
392 int which; | |
393 | |
394 #ifdef CHANNEL_PIPES | |
395 for (which = CHAN_SOCK; which < CHAN_IN; ++which) | |
396 #else | |
397 which = CHAN_SOCK; | |
398 #endif | |
399 { | |
391 # ifdef FEAT_GUI_X11 | 400 # ifdef FEAT_GUI_X11 |
392 if (channel->ch_pfd[which].ch_inputHandler != (XtInputId)NULL) | 401 if (channel->ch_pfd[which].ch_inputHandler != (XtInputId)NULL) |
393 { | 402 { |
394 XtRemoveInput(channel->ch_pfd[which].ch_inputHandler); | 403 XtRemoveInput(channel->ch_pfd[which].ch_inputHandler); |
395 channel->ch_pfd[which].ch_inputHandler = (XtInputId)NULL; | 404 channel->ch_pfd[which].ch_inputHandler = (XtInputId)NULL; |
396 } | 405 } |
397 # else | 406 # else |
398 # ifdef FEAT_GUI_GTK | 407 # ifdef FEAT_GUI_GTK |
399 if (channel->ch_pfd[which].ch_inputHandler != 0) | 408 if (channel->ch_pfd[which].ch_inputHandler != 0) |
400 { | 409 { |
401 gdk_input_remove(channel->ch_pfd[which].ch_inputHandler); | 410 gdk_input_remove(channel->ch_pfd[which].ch_inputHandler); |
402 channel->ch_pfd[which].ch_inputHandler = 0; | 411 channel->ch_pfd[which].ch_inputHandler = 0; |
403 } | 412 } |
404 # else | 413 # else |
405 # ifdef FEAT_GUI_W32 | 414 # ifdef FEAT_GUI_W32 |
406 if (channel->ch_pfd[which].ch_inputHandler == 0) | 415 if (channel->ch_pfd[which].ch_inputHandler == 0) |
407 { | 416 { |
408 WSAAsyncSelect(channel->ch_pfd[which].ch_fd, s_hwnd, 0, 0); | 417 WSAAsyncSelect(channel->ch_pfd[which].ch_fd, s_hwnd, 0, 0); |
409 channel->ch_pfd[which].ch_inputHandler = -1; | 418 channel->ch_pfd[which].ch_inputHandler = -1; |
410 } | 419 } |
411 # endif | 420 # endif |
412 # endif | 421 # endif |
413 # endif | 422 # endif |
414 } | 423 } |
415 | |
416 static void | |
417 channel_gui_unregister(channel_T *channel) | |
418 { | |
419 if (channel->ch_pfd[CHAN_SOCK].ch_fd >= 0) | |
420 channel_gui_unregister_one(channel, CHAN_SOCK); | |
421 # ifdef CHANNEL_PIPES | |
422 if (channel->ch_pfd[CHAN_OUT].ch_fd >= 0) | |
423 channel_gui_unregister_one(channel, CHAN_OUT); | |
424 if (channel->ch_pfd[CHAN_ERR].ch_fd >= 0) | |
425 channel_gui_unregister_one(channel, CHAN_ERR); | |
426 # endif | |
427 } | 424 } |
428 | 425 |
429 #endif | 426 #endif |
430 | 427 |
431 /* | 428 /* |
1190 void | 1187 void |
1191 channel_close(channel_T *channel) | 1188 channel_close(channel_T *channel) |
1192 { | 1189 { |
1193 ch_log(channel, "Closing channel"); | 1190 ch_log(channel, "Closing channel"); |
1194 | 1191 |
1192 #ifdef FEAT_GUI | |
1193 channel_gui_unregister(channel); | |
1194 #endif | |
1195 | |
1195 if (channel->CH_SOCK >= 0) | 1196 if (channel->CH_SOCK >= 0) |
1196 { | 1197 { |
1197 sock_close(channel->CH_SOCK); | 1198 sock_close(channel->CH_SOCK); |
1198 channel->CH_SOCK = -1; | 1199 channel->CH_SOCK = -1; |
1199 channel->ch_close_cb = NULL; | |
1200 #ifdef FEAT_GUI | |
1201 channel_gui_unregister(channel); | |
1202 #endif | |
1203 vim_free(channel->ch_callback); | |
1204 channel->ch_callback = NULL; | |
1205 } | 1200 } |
1206 #if defined(CHANNEL_PIPES) | 1201 #if defined(CHANNEL_PIPES) |
1207 if (channel->CH_IN >= 0) | 1202 if (channel->CH_IN >= 0) |
1208 { | 1203 { |
1209 close(channel->CH_IN); | 1204 close(channel->CH_IN); |
1218 { | 1213 { |
1219 close(channel->CH_ERR); | 1214 close(channel->CH_ERR); |
1220 channel->CH_ERR = -1; | 1215 channel->CH_ERR = -1; |
1221 } | 1216 } |
1222 #endif | 1217 #endif |
1218 | |
1219 channel->ch_close_cb = NULL; | |
1220 vim_free(channel->ch_callback); | |
1221 channel->ch_callback = NULL; | |
1223 channel_clear(channel); | 1222 channel_clear(channel); |
1224 } | 1223 } |
1225 | 1224 |
1226 /* | 1225 /* |
1227 * Store "buf[len]" on channel "channel". | 1226 * Store "buf[len]" on channel "channel". |
1381 return next_id++; | 1380 return next_id++; |
1382 } | 1381 } |
1383 | 1382 |
1384 /* | 1383 /* |
1385 * Get the file descriptor to read from, either the socket or stdout. | 1384 * Get the file descriptor to read from, either the socket or stdout. |
1386 * TODO: never gets stderr. | 1385 * TODO: should have a way to read stderr. |
1387 */ | 1386 */ |
1388 static int | 1387 static int |
1389 get_read_fd(channel_T *channel) | 1388 get_read_fd(channel_T *channel) |
1390 { | 1389 { |
1391 if (channel->CH_SOCK >= 0) | 1390 if (channel->CH_SOCK >= 0) |
1398 return -1; | 1397 return -1; |
1399 } | 1398 } |
1400 | 1399 |
1401 /* | 1400 /* |
1402 * Read from channel "channel" for as long as there is something to read. | 1401 * Read from channel "channel" for as long as there is something to read. |
1403 * "which" is CHAN_SOCK, CHAN_OUT or CHAN_ERR. When -1 guess. | 1402 * "which" is CHAN_SOCK, CHAN_OUT or CHAN_ERR. When -1 use CHAN_SOCK or |
1403 * CHAN_OUT, the one that is open. | |
1404 * The data is put in the read queue. | 1404 * The data is put in the read queue. |
1405 */ | 1405 */ |
1406 void | 1406 void |
1407 channel_read(channel_T *channel, int which, char *func) | 1407 channel_read(channel_T *channel, int which, char *func) |
1408 { | 1408 { |
1473 * -> channel_read() | 1473 * -> channel_read() |
1474 */ | 1474 */ |
1475 ch_errors(channel, "%s(): Cannot read\n", func); | 1475 ch_errors(channel, "%s(): Cannot read\n", func); |
1476 channel_save(channel, (char_u *)DETACH_MSG, (int)STRLEN(DETACH_MSG)); | 1476 channel_save(channel, (char_u *)DETACH_MSG, (int)STRLEN(DETACH_MSG)); |
1477 | 1477 |
1478 if (use_socket) | 1478 /* TODO: When reading from stdout is not possible, should we try to |
1479 { | 1479 * keep stdin and stderr open? Probably not, assume the other side |
1480 channel_close(channel); | 1480 * has died. */ |
1481 if (channel->ch_close_cb != NULL) | 1481 channel_close(channel); |
1482 (*channel->ch_close_cb)(); | 1482 if (channel->ch_close_cb != NULL) |
1483 } | 1483 (*channel->ch_close_cb)(); |
1484 #if defined(CHANNEL_PIPES) | |
1485 else | |
1486 { | |
1487 close(fd); | |
1488 channel->CH_OUT = -1; | |
1489 } | |
1490 #endif | |
1491 | 1484 |
1492 if (len < 0) | 1485 if (len < 0) |
1493 { | 1486 { |
1494 ch_error(channel, "channel_read(): cannot read from channel\n"); | 1487 ch_error(channel, "channel_read(): cannot read from channel\n"); |
1495 PERROR(_("E896: read from channel")); | 1488 PERROR(_("E896: read from channel")); |
1585 int i; | 1578 int i; |
1586 | 1579 |
1587 if (fd >= 0) | 1580 if (fd >= 0) |
1588 for (channel = first_channel; channel != NULL; | 1581 for (channel = first_channel; channel != NULL; |
1589 channel = channel->ch_next) | 1582 channel = channel->ch_next) |
1583 { | |
1590 # ifdef CHANNEL_PIPES | 1584 # ifdef CHANNEL_PIPES |
1591 for (i = CHAN_SOCK; i < CHAN_IN; ++i) | 1585 for (i = CHAN_SOCK; i < CHAN_IN; ++i) |
1592 # else | 1586 # else |
1593 i = CHAN_SOCK; | 1587 i = CHAN_SOCK; |
1594 # endif | 1588 # endif |
1595 if (channel->ch_pfd[i].ch_fd == fd) | 1589 if (channel->ch_pfd[i].ch_fd == fd) |
1596 { | 1590 { |
1597 *whichp = i; | 1591 *whichp = i; |
1598 return channel | 1592 return channel; |
1599 } | 1593 } |
1594 } | |
1600 return NULL; | 1595 return NULL; |
1601 } | 1596 } |
1602 # endif | 1597 # endif |
1603 | 1598 |
1604 /* | 1599 /* |
1636 | 1631 |
1637 if (log_fd != NULL) | 1632 if (log_fd != NULL) |
1638 { | 1633 { |
1639 ch_log_lead("SEND ", channel); | 1634 ch_log_lead("SEND ", channel); |
1640 fprintf(log_fd, "'"); | 1635 fprintf(log_fd, "'"); |
1641 ignored = fwrite(buf, len, 1, log_fd); | 1636 ignored = (int)fwrite(buf, len, 1, log_fd); |
1642 fprintf(log_fd, "'\n"); | 1637 fprintf(log_fd, "'\n"); |
1643 fflush(log_fd); | 1638 fflush(log_fd); |
1644 } | 1639 } |
1645 | 1640 |
1646 if (use_socket) | 1641 if (use_socket) |
1675 channel_T *channel; | 1670 channel_T *channel; |
1676 struct pollfd *fds = fds_in; | 1671 struct pollfd *fds = fds_in; |
1677 int which; | 1672 int which; |
1678 | 1673 |
1679 for (channel = first_channel; channel != NULL; channel = channel->ch_next) | 1674 for (channel = first_channel; channel != NULL; channel = channel->ch_next) |
1675 { | |
1680 # ifdef CHANNEL_PIPES | 1676 # ifdef CHANNEL_PIPES |
1681 for (which = CHAN_SOCK; which < CHAN_IN; ++which) | 1677 for (which = CHAN_SOCK; which < CHAN_IN; ++which) |
1682 # else | 1678 # else |
1683 which = CHAN_SOCK; | 1679 which = CHAN_SOCK; |
1684 # endif | 1680 # endif |
1681 { | |
1685 if (channel->ch_pfd[which].ch_fd >= 0) | 1682 if (channel->ch_pfd[which].ch_fd >= 0) |
1686 { | 1683 { |
1687 channel->ch_pfd[which].ch_poll_idx = nfd; | 1684 channel->ch_pfd[which].ch_poll_idx = nfd; |
1688 fds[nfd].fd = channel->ch_pfd[which].ch_fd; | 1685 fds[nfd].fd = channel->ch_pfd[which].ch_fd; |
1689 fds[nfd].events = POLLIN; | 1686 fds[nfd].events = POLLIN; |
1690 nfd++; | 1687 nfd++; |
1691 } | 1688 } |
1692 else | 1689 else |
1693 channel->ch_pfd[which].ch_poll_idx = -1; | 1690 channel->ch_pfd[which].ch_poll_idx = -1; |
1691 } | |
1692 } | |
1694 | 1693 |
1695 return nfd; | 1694 return nfd; |
1696 } | 1695 } |
1697 | 1696 |
1698 /* | 1697 /* |
1705 channel_T *channel; | 1704 channel_T *channel; |
1706 struct pollfd *fds = fds_in; | 1705 struct pollfd *fds = fds_in; |
1707 int which; | 1706 int which; |
1708 | 1707 |
1709 for (channel = first_channel; channel != NULL; channel = channel->ch_next) | 1708 for (channel = first_channel; channel != NULL; channel = channel->ch_next) |
1709 { | |
1710 # ifdef CHANNEL_PIPES | 1710 # ifdef CHANNEL_PIPES |
1711 for (which = CHAN_SOCK; which < CHAN_IN; ++which) | 1711 for (which = CHAN_SOCK; which < CH_IN; ++which) |
1712 # else | 1712 # else |
1713 which = CHAN_SOCK; | 1713 which = CHAN_SOCK; |
1714 # endif | 1714 # endif |
1715 { | 1715 { |
1716 int idx = channel->ch_pfd[which].ch_poll_idx; | 1716 int idx = channel->ch_pfd[which].ch_poll_idx; |
1719 { | 1719 { |
1720 channel_read(channel, which, "channel_poll_check"); | 1720 channel_read(channel, which, "channel_poll_check"); |
1721 --ret; | 1721 --ret; |
1722 } | 1722 } |
1723 } | 1723 } |
1724 } | |
1724 | 1725 |
1725 return ret; | 1726 return ret; |
1726 } | 1727 } |
1727 # endif /* UNIX && !HAVE_SELECT */ | 1728 # endif /* UNIX && !HAVE_SELECT */ |
1728 | 1729 |
1737 channel_T *channel; | 1738 channel_T *channel; |
1738 fd_set *rfds = rfds_in; | 1739 fd_set *rfds = rfds_in; |
1739 int which; | 1740 int which; |
1740 | 1741 |
1741 for (channel = first_channel; channel != NULL; channel = channel->ch_next) | 1742 for (channel = first_channel; channel != NULL; channel = channel->ch_next) |
1743 { | |
1742 # ifdef CHANNEL_PIPES | 1744 # ifdef CHANNEL_PIPES |
1743 for (which = CHAN_SOCK; which < CHAN_IN; ++which) | 1745 for (which = CHAN_SOCK; which < CHAN_IN; ++which) |
1744 # else | 1746 # else |
1745 which = CHAN_SOCK; | 1747 which = CHAN_SOCK; |
1746 # endif | 1748 # endif |
1752 FD_SET(fd, rfds); | 1754 FD_SET(fd, rfds); |
1753 if (maxfd < fd) | 1755 if (maxfd < fd) |
1754 maxfd = fd; | 1756 maxfd = fd; |
1755 } | 1757 } |
1756 } | 1758 } |
1759 } | |
1757 | 1760 |
1758 return maxfd; | 1761 return maxfd; |
1759 } | 1762 } |
1760 | 1763 |
1761 /* | 1764 /* |
1768 channel_T *channel; | 1771 channel_T *channel; |
1769 fd_set *rfds = rfds_in; | 1772 fd_set *rfds = rfds_in; |
1770 int which; | 1773 int which; |
1771 | 1774 |
1772 for (channel = first_channel; channel != NULL; channel = channel->ch_next) | 1775 for (channel = first_channel; channel != NULL; channel = channel->ch_next) |
1776 { | |
1773 # ifdef CHANNEL_PIPES | 1777 # ifdef CHANNEL_PIPES |
1774 for (which = CHAN_SOCK; which < CHAN_IN; ++which) | 1778 for (which = CHAN_SOCK; which < CHAN_IN; ++which) |
1775 # else | 1779 # else |
1776 which = CHAN_SOCK; | 1780 which = CHAN_SOCK; |
1777 # endif | 1781 # endif |
1782 { | 1786 { |
1783 channel_read(channel, which, "channel_select_check"); | 1787 channel_read(channel, which, "channel_select_check"); |
1784 --ret; | 1788 --ret; |
1785 } | 1789 } |
1786 } | 1790 } |
1791 } | |
1787 | 1792 |
1788 return ret; | 1793 return ret; |
1789 } | 1794 } |
1790 # endif /* !FEAT_GUI_W32 && HAVE_SELECT */ | 1795 # endif /* !FEAT_GUI_W32 && HAVE_SELECT */ |
1791 | 1796 |