@@ -1573,7 +1573,8 @@ channel_free_all(void)
15731573
15741574
15751575/* Sent when the channel is found closed when reading. */
1576- #define DETACH_MSG "\"DETACH\"\n"
1576+ #define DETACH_MSG_RAW "DETACH\n"
1577+ #define DETACH_MSG_JSON "\"DETACH\"\n"
15771578
15781579/* Buffer size for reading incoming messages. */
15791580#define MAXMSGSIZE 4096
@@ -1677,6 +1678,7 @@ channel_read(channel_T *channel, int part, char *func)
16771678 int readlen = 0 ;
16781679 sock_T fd ;
16791680 int use_socket = FALSE;
1681+ char * msg ;
16801682
16811683 fd = channel -> ch_part [part ].ch_fd ;
16821684 if (fd == INVALID_FD )
@@ -1725,9 +1727,9 @@ channel_read(channel_T *channel, int part, char *func)
17251727 }
17261728#endif
17271729
1728- /* Reading a socket disconnection (readlen == 0), or a socket error.
1730+ /* Reading a disconnection (readlen == 0), or an error.
17291731 * TODO: call error callback. */
1730- if (readlen <= 0 && channel -> ch_job == NULL )
1732+ if (readlen <= 0 )
17311733 {
17321734 /* Queue a "DETACH" netbeans message in the command queue in order to
17331735 * terminate the netbeans session later. Do not end the session here
@@ -1740,8 +1742,10 @@ channel_read(channel_T *channel, int part, char *func)
17401742 * -> channel_read()
17411743 */
17421744 ch_errors (channel , "%s(): Cannot read" , func );
1743- channel_save (channel , part ,
1744- (char_u * )DETACH_MSG , (int )STRLEN (DETACH_MSG ));
1745+ msg = channel -> ch_part [part ].ch_mode == MODE_RAW
1746+ || channel -> ch_part [part ].ch_mode == MODE_NL
1747+ ? DETACH_MSG_RAW : DETACH_MSG_JSON ;
1748+ channel_save (channel , part , (char_u * )msg , (int )STRLEN (msg ));
17451749
17461750 /* TODO: When reading from stdout is not possible, should we try to
17471751 * keep stdin and stderr open? Probably not, assume the other side
0 commit comments