comparison src/channel.c @ 8491:daebcbd87bd3 v7.4.1536

commit https://github.com/vim/vim/commit/de27989157f35172b25f9e01e0c147ed8f6ae3ce Author: Bram Moolenaar <Bram@vim.org> Date: Fri Mar 11 22:19:44 2016 +0100 patch 7.4.1536 Problem: Cannot re-use a channel for another job. Solution: Add the "channel" option to job_start().
author Christian Brabandt <cb@256bit.org>
date Fri, 11 Mar 2016 22:30:04 +0100
parents 8924d7adbc22
children caed4b2d305f
comparison
equal deleted inserted replaced
8490:eceb3c28e179 8491:daebcbd87bd3
457 #endif 457 #endif
458 458
459 static void 459 static void
460 channel_gui_register_one(channel_T *channel, int part) 460 channel_gui_register_one(channel_T *channel, int part)
461 { 461 {
462 if (!CH_HAS_GUI)
463 return;
464
462 # ifdef FEAT_GUI_X11 465 # ifdef FEAT_GUI_X11
463 /* Tell notifier we are interested in being called 466 /* Tell notifier we are interested in being called
464 * when there is input on the editor connection socket. */ 467 * when there is input on the editor connection socket. */
465 if (channel->ch_part[part].ch_inputHandler == (XtInputId)NULL) 468 if (channel->ch_part[part].ch_inputHandler == (XtInputId)NULL)
466 channel->ch_part[part].ch_inputHandler = XtAppAddInput( 469 channel->ch_part[part].ch_inputHandler = XtAppAddInput(
497 # endif 500 # endif
498 # endif 501 # endif
499 # endif 502 # endif
500 } 503 }
501 504
502 void 505 static void
503 channel_gui_register(channel_T *channel) 506 channel_gui_register(channel_T *channel)
504 { 507 {
505 if (!CH_HAS_GUI)
506 return;
507
508 if (channel->CH_SOCK_FD != INVALID_FD) 508 if (channel->CH_SOCK_FD != INVALID_FD)
509 channel_gui_register_one(channel, PART_SOCK); 509 channel_gui_register_one(channel, PART_SOCK);
510 # ifdef CHANNEL_PIPES 510 # ifdef CHANNEL_PIPES
511 if (channel->CH_OUT_FD != INVALID_FD) 511 if (channel->CH_OUT_FD != INVALID_FD)
512 channel_gui_register_one(channel, PART_OUT); 512 channel_gui_register_one(channel, PART_OUT);
527 for (channel = first_channel; channel != NULL; channel = channel->ch_next) 527 for (channel = first_channel; channel != NULL; channel = channel->ch_next)
528 channel_gui_register(channel); 528 channel_gui_register(channel);
529 } 529 }
530 530
531 static void 531 static void
532 channel_gui_unregister_one(channel_T *channel, int part)
533 {
534 # ifdef FEAT_GUI_X11
535 if (channel->ch_part[part].ch_inputHandler != (XtInputId)NULL)
536 {
537 XtRemoveInput(channel->ch_part[part].ch_inputHandler);
538 channel->ch_part[part].ch_inputHandler = (XtInputId)NULL;
539 }
540 # else
541 # ifdef FEAT_GUI_GTK
542 if (channel->ch_part[part].ch_inputHandler != 0)
543 {
544 # if GTK_CHECK_VERSION(3,0,0)
545 g_source_remove(channel->ch_part[part].ch_inputHandler);
546 # else
547 gdk_input_remove(channel->ch_part[part].ch_inputHandler);
548 # endif
549 channel->ch_part[part].ch_inputHandler = 0;
550 }
551 # endif
552 # endif
553 }
554
555 static void
532 channel_gui_unregister(channel_T *channel) 556 channel_gui_unregister(channel_T *channel)
533 { 557 {
534 int part; 558 int part;
535 559
536 #ifdef CHANNEL_PIPES 560 #ifdef CHANNEL_PIPES
537 for (part = PART_SOCK; part < PART_IN; ++part) 561 for (part = PART_SOCK; part < PART_IN; ++part)
538 #else 562 #else
539 part = PART_SOCK; 563 part = PART_SOCK;
540 #endif 564 #endif
541 { 565 {
542 # ifdef FEAT_GUI_X11 566 channel_gui_unregister_one(channel, part);
543 if (channel->ch_part[part].ch_inputHandler != (XtInputId)NULL)
544 {
545 XtRemoveInput(channel->ch_part[part].ch_inputHandler);
546 channel->ch_part[part].ch_inputHandler = (XtInputId)NULL;
547 }
548 # else
549 # ifdef FEAT_GUI_GTK
550 if (channel->ch_part[part].ch_inputHandler != 0)
551 {
552 # if GTK_CHECK_VERSION(3,0,0)
553 g_source_remove(channel->ch_part[part].ch_inputHandler);
554 # else
555 gdk_input_remove(channel->ch_part[part].ch_inputHandler);
556 # endif
557 channel->ch_part[part].ch_inputHandler = 0;
558 }
559 # endif
560 # endif
561 } 567 }
562 } 568 }
563 569
564 #endif 570 #endif
565 571
828 834
829 channel->CH_SOCK_FD = (sock_T)sd; 835 channel->CH_SOCK_FD = (sock_T)sd;
830 channel->ch_nb_close_cb = nb_close_cb; 836 channel->ch_nb_close_cb = nb_close_cb;
831 837
832 #ifdef FEAT_GUI 838 #ifdef FEAT_GUI
833 channel_gui_register(channel); 839 channel_gui_register_one(channel, PART_SOCK);
834 #endif 840 #endif
835 841
836 return channel; 842 return channel;
837 } 843 }
838 844
839 #if defined(CHANNEL_PIPES) || defined(PROTO) 845 #if defined(CHANNEL_PIPES) || defined(PROTO)
846 static void
847 may_close_part(sock_T *fd)
848 {
849 if (*fd != INVALID_FD)
850 {
851 fd_close(*fd);
852 *fd = INVALID_FD;
853 }
854 }
855
840 void 856 void
841 channel_set_pipes(channel_T *channel, sock_T in, sock_T out, sock_T err) 857 channel_set_pipes(channel_T *channel, sock_T in, sock_T out, sock_T err)
842 { 858 {
843 channel->CH_IN_FD = in; 859 if (in != INVALID_FD)
844 channel->CH_OUT_FD = out; 860 {
845 channel->CH_ERR_FD = err; 861 may_close_part(&channel->CH_IN_FD);
862 channel->CH_IN_FD = in;
863 }
864 if (out != INVALID_FD)
865 {
866 # if defined(FEAT_GUI)
867 channel_gui_unregister_one(channel, PART_OUT);
868 # endif
869 may_close_part(&channel->CH_OUT_FD);
870 channel->CH_OUT_FD = out;
871 # if defined(FEAT_GUI)
872 channel_gui_register_one(channel, PART_OUT);
873 # endif
874 }
875 if (err != INVALID_FD)
876 {
877 # if defined(FEAT_GUI)
878 channel_gui_unregister_one(channel, PART_ERR);
879 # endif
880 may_close_part(&channel->CH_ERR_FD);
881 channel->CH_ERR_FD = err;
882 # if defined(FEAT_GUI)
883 channel_gui_register_one(channel, PART_ERR);
884 # endif
885 }
846 } 886 }
847 #endif 887 #endif
848 888
849 /* 889 /*
850 * Sets the job the channel is associated with and associated options. 890 * Sets the job the channel is associated with and associated options.
1910 { 1950 {
1911 sock_close(channel->CH_SOCK_FD); 1951 sock_close(channel->CH_SOCK_FD);
1912 channel->CH_SOCK_FD = INVALID_FD; 1952 channel->CH_SOCK_FD = INVALID_FD;
1913 } 1953 }
1914 #if defined(CHANNEL_PIPES) 1954 #if defined(CHANNEL_PIPES)
1915 if (channel->CH_IN_FD != INVALID_FD) 1955 may_close_part(&channel->CH_IN_FD);
1916 { 1956 may_close_part(&channel->CH_OUT_FD);
1917 fd_close(channel->CH_IN_FD); 1957 may_close_part(&channel->CH_ERR_FD);
1918 channel->CH_IN_FD = INVALID_FD;
1919 }
1920 if (channel->CH_OUT_FD != INVALID_FD)
1921 {
1922 fd_close(channel->CH_OUT_FD);
1923 channel->CH_OUT_FD = INVALID_FD;
1924 }
1925 if (channel->CH_ERR_FD != INVALID_FD)
1926 {
1927 fd_close(channel->CH_ERR_FD);
1928 channel->CH_ERR_FD = INVALID_FD;
1929 }
1930 #endif 1958 #endif
1931 1959
1932 if (invoke_close_cb && channel->ch_close_cb != NULL) 1960 if (invoke_close_cb && channel->ch_close_cb != NULL)
1933 { 1961 {
1934 typval_T argv[1]; 1962 typval_T argv[1];