Skip to content

Commit 9235d12

Browse files
committed
Merge remote-tracking branch 'vim/master'
2 parents 78f80e2 + 65189a1 commit 9235d12

17 files changed

Lines changed: 730 additions & 498 deletions

src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,8 +2089,6 @@ test1 \
20892089
test_getcwd \
20902090
test_insertcount \
20912091
test_listchars \
2092-
test_listlbr \
2093-
test_listlbr_utf8 \
20942092
test_search_mbyte \
20952093
test_wordcount \
20962094
test3 test4 test5 test6 test7 test8 test9 \
@@ -2165,6 +2163,8 @@ test_arglist \
21652163
test_langmap \
21662164
test_largefile \
21672165
test_lispwords \
2166+
test_listlbr \
2167+
test_listlbr_utf8 \
21682168
test_lua \
21692169
test_man \
21702170
test_mapping \

src/channel.c

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,39 +1861,42 @@ channel_save(channel_T *channel, ch_part_T part, char_u *buf, int len,
18611861
return OK;
18621862
}
18631863

1864+
/*
1865+
* Try to fill the buffer of "reader".
1866+
* Returns FALSE when nothing was added.
1867+
*/
18641868
static int
18651869
channel_fill(js_read_T *reader)
18661870
{
18671871
channel_T *channel = (channel_T *)reader->js_cookie;
18681872
ch_part_T part = reader->js_cookie_arg;
18691873
char_u *next = channel_get(channel, part);
1870-
int unused;
1871-
int len;
1874+
int keeplen;
1875+
int addlen;
18721876
char_u *p;
18731877

18741878
if (next == NULL)
18751879
return FALSE;
18761880

1877-
unused = reader->js_end - reader->js_buf - reader->js_used;
1878-
if (unused > 0)
1881+
keeplen = reader->js_end - reader->js_buf;
1882+
if (keeplen > 0)
18791883
{
18801884
/* Prepend unused text. */
1881-
len = (int)STRLEN(next);
1882-
p = alloc(unused + len + 1);
1885+
addlen = (int)STRLEN(next);
1886+
p = alloc(keeplen + addlen + 1);
18831887
if (p == NULL)
18841888
{
18851889
vim_free(next);
18861890
return FALSE;
18871891
}
1888-
mch_memmove(p, reader->js_buf + reader->js_used, unused);
1889-
mch_memmove(p + unused, next, len + 1);
1892+
mch_memmove(p, reader->js_buf, keeplen);
1893+
mch_memmove(p + keeplen, next, addlen + 1);
18901894
vim_free(next);
18911895
next = p;
18921896
}
18931897

18941898
vim_free(reader->js_buf);
18951899
reader->js_buf = next;
1896-
reader->js_used = 0;
18971900
return TRUE;
18981901
}
18991902

@@ -1973,16 +1976,20 @@ channel_parse_json(channel_T *channel, ch_part_T part)
19731976
}
19741977

19751978
if (status == OK)
1976-
chanpart->ch_waiting = FALSE;
1979+
chanpart->ch_wait_len = 0;
19771980
else if (status == MAYBE)
19781981
{
1979-
if (!chanpart->ch_waiting)
1982+
size_t buflen = STRLEN(reader.js_buf);
1983+
1984+
if (chanpart->ch_wait_len < buflen)
19801985
{
1981-
/* First time encountering incomplete message, set a deadline of
1982-
* 100 msec. */
1983-
ch_log(channel, "Incomplete message - wait for more");
1986+
/* First time encountering incomplete message or after receiving
1987+
* more (but still incomplete): set a deadline of 100 msec. */
1988+
ch_logn(channel,
1989+
"Incomplete message (%d bytes) - wait 100 msec for more",
1990+
buflen);
19841991
reader.js_used = 0;
1985-
chanpart->ch_waiting = TRUE;
1992+
chanpart->ch_wait_len = buflen;
19861993
#ifdef WIN32
19871994
chanpart->ch_deadline = GetTickCount() + 100L;
19881995
#else
@@ -2013,7 +2020,8 @@ channel_parse_json(channel_T *channel, ch_part_T part)
20132020
if (timeout)
20142021
{
20152022
status = FAIL;
2016-
chanpart->ch_waiting = FALSE;
2023+
chanpart->ch_wait_len = 0;
2024+
ch_log(channel, "timed out");
20172025
}
20182026
else
20192027
{
@@ -2027,7 +2035,7 @@ channel_parse_json(channel_T *channel, ch_part_T part)
20272035
{
20282036
ch_error(channel, "Decoding failed - discarding input");
20292037
ret = FALSE;
2030-
chanpart->ch_waiting = FALSE;
2038+
chanpart->ch_wait_len = 0;
20312039
}
20322040
else if (reader.js_buf[reader.js_used] != NUL)
20332041
{
@@ -3394,7 +3402,7 @@ channel_read_json_block(
33943402
/* Wait for up to the timeout. If there was an incomplete message
33953403
* use the deadline for that. */
33963404
timeout = timeout_arg;
3397-
if (chanpart->ch_waiting)
3405+
if (chanpart->ch_wait_len > 0)
33983406
{
33993407
#ifdef WIN32
34003408
timeout = chanpart->ch_deadline - GetTickCount() + 1;
@@ -3414,7 +3422,7 @@ channel_read_json_block(
34143422
{
34153423
/* Something went wrong, channel_parse_json() didn't
34163424
* discard message. Cancel waiting. */
3417-
chanpart->ch_waiting = FALSE;
3425+
chanpart->ch_wait_len = 0;
34183426
timeout = timeout_arg;
34193427
}
34203428
else if (timeout > timeout_arg)

src/structs.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1566,9 +1566,11 @@ typedef struct {
15661566
jsonq_T ch_json_head; /* header for circular json read queue */
15671567
int ch_block_id; /* ID that channel_read_json_block() is
15681568
waiting for */
1569-
/* When ch_waiting is TRUE use ch_deadline to wait for incomplete message
1570-
* to be complete. */
1571-
int ch_waiting;
1569+
/* When ch_wait_len is non-zero use ch_deadline to wait for incomplete
1570+
* message to be complete. The value is the length of the incomplete
1571+
* message when the deadline was set. If it gets longer (something was
1572+
* received) the deadline is reset. */
1573+
size_t ch_wait_len;
15721574
#ifdef WIN32
15731575
DWORD ch_deadline;
15741576
#else

src/testdir/Make_all.mak

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ SCRIPTS_ALL = \
8282
test_getcwd.out \
8383
test_insertcount.out \
8484
test_listchars.out \
85-
test_listlbr.out \
8685
test_search_mbyte.out \
8786
test_wordcount.out
8887

@@ -101,8 +100,7 @@ SCRIPTS_MORE2 = \
101100
test12.out \
102101
test25.out \
103102
test49.out \
104-
test97.out \
105-
test_listlbr_utf8.out
103+
test97.out
106104

107105

108106
# Tests that run on most systems, but not MingW and Cygwin.
@@ -164,6 +162,8 @@ NEW_TESTS = test_arglist.res \
164162
test_job_fails.res \
165163
test_json.res \
166164
test_langmap.res \
165+
test_listlbr.res \
166+
test_listlbr_utf8.res \
167167
test_lua.res \
168168
test_man.res \
169169
test_marks.res \

0 commit comments

Comments
 (0)