comparison src/channel.c @ 10249:920c73a27dda v8.0.0022

commit https://github.com/vim/vim/commit/ec68a99464055029c01082762517e97245ddae0c Author: Bram Moolenaar <Bram@vim.org> Date: Mon Oct 3 21:37:41 2016 +0200 patch 8.0.0022 Problem: If a channel in NL mode is missing the NL at the end the remaining characters are dropped. Solution: When the channel is closed use the remaining text. (Ozaki Kiichi)
author Christian Brabandt <cb@256bit.org>
date Mon, 03 Oct 2016 21:45:04 +0200
parents 175b1116f96a
children a92c4abb8c1f
comparison
equal deleted inserted replaced
10248:add2fae6e54b 10249:920c73a27dda
2353 { 2353 {
2354 char_u *msg = NULL; 2354 char_u *msg = NULL;
2355 typval_T *listtv = NULL; 2355 typval_T *listtv = NULL;
2356 typval_T argv[CH_JSON_MAX_ARGS]; 2356 typval_T argv[CH_JSON_MAX_ARGS];
2357 int seq_nr = -1; 2357 int seq_nr = -1;
2358 ch_mode_T ch_mode = channel->ch_part[part].ch_mode; 2358 chanpart_T *ch_part = &channel->ch_part[part];
2359 cbq_T *cbhead = &channel->ch_part[part].ch_cb_head; 2359 ch_mode_T ch_mode = ch_part->ch_mode;
2360 cbq_T *cbhead = &ch_part->ch_cb_head;
2360 cbq_T *cbitem; 2361 cbq_T *cbitem;
2361 char_u *callback = NULL; 2362 char_u *callback = NULL;
2362 partial_T *partial = NULL; 2363 partial_T *partial = NULL;
2363 buf_T *buffer = NULL; 2364 buf_T *buffer = NULL;
2364 char_u *p; 2365 char_u *p;
2374 if (cbitem != NULL) 2375 if (cbitem != NULL)
2375 { 2376 {
2376 callback = cbitem->cq_callback; 2377 callback = cbitem->cq_callback;
2377 partial = cbitem->cq_partial; 2378 partial = cbitem->cq_partial;
2378 } 2379 }
2379 else if (channel->ch_part[part].ch_callback != NULL) 2380 else if (ch_part->ch_callback != NULL)
2380 { 2381 {
2381 callback = channel->ch_part[part].ch_callback; 2382 callback = ch_part->ch_callback;
2382 partial = channel->ch_part[part].ch_partial; 2383 partial = ch_part->ch_partial;
2383 } 2384 }
2384 else 2385 else
2385 { 2386 {
2386 callback = channel->ch_callback; 2387 callback = channel->ch_callback;
2387 partial = channel->ch_partial; 2388 partial = channel->ch_partial;
2388 } 2389 }
2389 2390
2390 buffer = channel->ch_part[part].ch_bufref.br_buf; 2391 buffer = ch_part->ch_bufref.br_buf;
2391 if (buffer != NULL && !bufref_valid(&channel->ch_part[part].ch_bufref)) 2392 if (buffer != NULL && !bufref_valid(&ch_part->ch_bufref))
2392 { 2393 {
2393 /* buffer was wiped out */ 2394 /* buffer was wiped out */
2394 channel->ch_part[part].ch_bufref.br_buf = NULL; 2395 ch_part->ch_bufref.br_buf = NULL;
2395 buffer = NULL; 2396 buffer = NULL;
2396 } 2397 }
2397 2398
2398 if (ch_mode == MODE_JSON || ch_mode == MODE_JS) 2399 if (ch_mode == MODE_JSON || ch_mode == MODE_JS)
2399 { 2400 {
2450 return FALSE; 2451 return FALSE;
2451 } 2452 }
2452 2453
2453 if (ch_mode == MODE_NL) 2454 if (ch_mode == MODE_NL)
2454 { 2455 {
2455 char_u *nl; 2456 char_u *nl = NULL;
2456 char_u *buf; 2457 char_u *buf;
2457 readq_T *node; 2458 readq_T *node;
2458 2459
2459 /* See if we have a message ending in NL in the first buffer. If 2460 /* See if we have a message ending in NL in the first buffer. If
2460 * not try to concatenate the first and the second buffer. */ 2461 * not try to concatenate the first and the second buffer. */
2463 node = channel_peek(channel, part); 2464 node = channel_peek(channel, part);
2464 nl = channel_first_nl(node); 2465 nl = channel_first_nl(node);
2465 if (nl != NULL) 2466 if (nl != NULL)
2466 break; 2467 break;
2467 if (channel_collapse(channel, part, TRUE) == FAIL) 2468 if (channel_collapse(channel, part, TRUE) == FAIL)
2469 {
2470 if (ch_part->ch_fd == INVALID_FD && node->rq_buflen > 0)
2471 break;
2468 return FALSE; /* incomplete message */ 2472 return FALSE; /* incomplete message */
2473 }
2469 } 2474 }
2470 buf = node->rq_buffer; 2475 buf = node->rq_buffer;
2476
2477 if (nl == NULL)
2478 {
2479 /* Flush remaining message that is missing a NL. */
2480 buf = vim_realloc(buf, node->rq_buflen + 1);
2481 if (buf == NULL)
2482 return FALSE;
2483 node->rq_buffer = buf;
2484 nl = buf + node->rq_buflen++;
2485 *nl = NUL;
2486 }
2471 2487
2472 /* Convert NUL to NL, the internal representation. */ 2488 /* Convert NUL to NL, the internal representation. */
2473 for (p = buf; p < nl && p < buf + node->rq_buflen; ++p) 2489 for (p = buf; p < nl && p < buf + node->rq_buflen; ++p)
2474 if (*p == NUL) 2490 if (*p == NUL)
2475 *p = NL; 2491 *p = NL;