mirror of
https://github.com/vim/vim.git
synced 2025-09-24 03:44:06 -04:00
patch 7.4.1483
Problem: A one-time callback is not used for a raw channel. Solution: Use a one-time callback when it exists.
This commit is contained in:
@@ -1390,6 +1390,23 @@ channel_exe_cmd(channel_T *channel, int part, typval_T *argv)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
invoke_one_time_callback(
|
||||||
|
channel_T *channel,
|
||||||
|
cbq_T *cbhead,
|
||||||
|
cbq_T *item,
|
||||||
|
typval_T *argv)
|
||||||
|
{
|
||||||
|
ch_logs(channel, "Invoking one-time callback %s",
|
||||||
|
(char *)item->cq_callback);
|
||||||
|
/* Remove the item from the list first, if the callback
|
||||||
|
* invokes ch_close() the list will be cleared. */
|
||||||
|
remove_cb_node(cbhead, item);
|
||||||
|
invoke_callback(channel, item->cq_callback, argv);
|
||||||
|
vim_free(item->cq_callback);
|
||||||
|
vim_free(item);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Invoke a callback for "channel"/"part" if needed.
|
* Invoke a callback for "channel"/"part" if needed.
|
||||||
* Return TRUE when a message was handled, there might be another one.
|
* Return TRUE when a message was handled, there might be another one.
|
||||||
@@ -1402,6 +1419,8 @@ may_invoke_callback(channel_T *channel, int part)
|
|||||||
typval_T argv[CH_JSON_MAX_ARGS];
|
typval_T argv[CH_JSON_MAX_ARGS];
|
||||||
int seq_nr = -1;
|
int seq_nr = -1;
|
||||||
ch_mode_T ch_mode = channel->ch_part[part].ch_mode;
|
ch_mode_T ch_mode = channel->ch_part[part].ch_mode;
|
||||||
|
cbq_T *cbhead = &channel->ch_part[part].ch_cb_head;
|
||||||
|
cbq_T *cbitem = cbhead->cq_next;
|
||||||
char_u *callback = NULL;
|
char_u *callback = NULL;
|
||||||
buf_T *buffer = NULL;
|
buf_T *buffer = NULL;
|
||||||
|
|
||||||
@@ -1409,7 +1428,10 @@ may_invoke_callback(channel_T *channel, int part)
|
|||||||
/* this channel is handled elsewhere (netbeans) */
|
/* this channel is handled elsewhere (netbeans) */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
if (channel->ch_part[part].ch_callback != NULL)
|
/* use a message-specific callback, part callback or channel callback */
|
||||||
|
if (cbitem != NULL)
|
||||||
|
callback = cbitem->cq_callback;
|
||||||
|
else if (channel->ch_part[part].ch_callback != NULL)
|
||||||
callback = channel->ch_part[part].ch_callback;
|
callback = channel->ch_part[part].ch_callback;
|
||||||
else
|
else
|
||||||
callback = channel->ch_callback;
|
callback = channel->ch_callback;
|
||||||
@@ -1525,27 +1547,18 @@ may_invoke_callback(channel_T *channel, int part)
|
|||||||
|
|
||||||
if (seq_nr > 0)
|
if (seq_nr > 0)
|
||||||
{
|
{
|
||||||
cbq_T *head = &channel->ch_part[part].ch_cb_head;
|
|
||||||
cbq_T *item = head->cq_next;
|
|
||||||
int done = FALSE;
|
int done = FALSE;
|
||||||
|
|
||||||
/* invoke the one-time callback with the matching nr */
|
/* invoke the one-time callback with the matching nr */
|
||||||
while (item != NULL)
|
while (cbitem != NULL)
|
||||||
{
|
{
|
||||||
if (item->cq_seq_nr == seq_nr)
|
if (cbitem->cq_seq_nr == seq_nr)
|
||||||
{
|
{
|
||||||
ch_logs(channel, "Invoking one-time callback %s",
|
invoke_one_time_callback(channel, cbhead, cbitem, argv);
|
||||||
(char *)item->cq_callback);
|
|
||||||
/* Remove the item from the list first, if the callback
|
|
||||||
* invokes ch_close() the list will be cleared. */
|
|
||||||
remove_cb_node(head, item);
|
|
||||||
invoke_callback(channel, item->cq_callback, argv);
|
|
||||||
vim_free(item->cq_callback);
|
|
||||||
vim_free(item);
|
|
||||||
done = TRUE;
|
done = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
item = item->cq_next;
|
cbitem = cbitem->cq_next;
|
||||||
}
|
}
|
||||||
if (!done)
|
if (!done)
|
||||||
ch_logn(channel, "Dropping message %d without callback", seq_nr);
|
ch_logn(channel, "Dropping message %d without callback", seq_nr);
|
||||||
@@ -1599,11 +1612,18 @@ may_invoke_callback(channel_T *channel, int part)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (callback != NULL)
|
if (callback != NULL)
|
||||||
{
|
{
|
||||||
/* invoke the channel callback */
|
if (cbitem != NULL)
|
||||||
ch_logs(channel, "Invoking channel callback %s", (char *)callback);
|
invoke_one_time_callback(channel, cbhead, cbitem, argv);
|
||||||
invoke_callback(channel, callback, argv);
|
else
|
||||||
|
{
|
||||||
|
/* invoke the channel callback */
|
||||||
|
ch_logs(channel, "Invoking channel callback %s",
|
||||||
|
(char *)callback);
|
||||||
|
invoke_callback(channel, callback, argv);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -62,6 +62,9 @@ class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
|
|||||||
if decoded[1] == 'hello!':
|
if decoded[1] == 'hello!':
|
||||||
# simply send back a string
|
# simply send back a string
|
||||||
response = "got it"
|
response = "got it"
|
||||||
|
elif decoded[1].startswith("echo "):
|
||||||
|
# send back the argument
|
||||||
|
response = decoded[1][5:]
|
||||||
elif decoded[1] == 'make change':
|
elif decoded[1] == 'make change':
|
||||||
# Send two ex commands at the same time, before
|
# Send two ex commands at the same time, before
|
||||||
# replying to the request.
|
# replying to the request.
|
||||||
|
@@ -257,6 +257,8 @@ func Test_server_crash()
|
|||||||
call s:run_server('s:server_crash')
|
call s:run_server('s:server_crash')
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
"""""""""
|
||||||
|
|
||||||
let s:reply = ""
|
let s:reply = ""
|
||||||
func s:Handler(chan, msg)
|
func s:Handler(chan, msg)
|
||||||
unlet s:reply
|
unlet s:reply
|
||||||
@@ -290,6 +292,61 @@ func Test_channel_handler()
|
|||||||
unlet s:chopt.callback
|
unlet s:chopt.callback
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
"""""""""
|
||||||
|
|
||||||
|
let s:reply1 = ""
|
||||||
|
func s:HandleRaw1(chan, msg)
|
||||||
|
unlet s:reply1
|
||||||
|
let s:reply1 = a:msg
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
let s:reply2 = ""
|
||||||
|
func s:HandleRaw2(chan, msg)
|
||||||
|
unlet s:reply2
|
||||||
|
let s:reply2 = a:msg
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
let s:reply3 = ""
|
||||||
|
func s:HandleRaw3(chan, msg)
|
||||||
|
unlet s:reply3
|
||||||
|
let s:reply3 = a:msg
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func s:raw_one_time_callback(port)
|
||||||
|
let handle = ch_open('localhost:' . a:port, s:chopt)
|
||||||
|
if ch_status(handle) == "fail"
|
||||||
|
call assert_false(1, "Can't open channel")
|
||||||
|
return
|
||||||
|
endif
|
||||||
|
call ch_setoptions(handle, {'mode': 'raw'})
|
||||||
|
|
||||||
|
" The message are sent raw, we do our own JSON strings here.
|
||||||
|
call ch_sendraw(handle, "[1, \"hello!\"]", {'callback': 's:HandleRaw1'})
|
||||||
|
sleep 10m
|
||||||
|
call assert_equal("[1, \"got it\"]", s:reply1)
|
||||||
|
call ch_sendraw(handle, "[2, \"echo something\"]", {'callback': 's:HandleRaw2'})
|
||||||
|
call ch_sendraw(handle, "[3, \"wait a bit\"]", {'callback': 's:HandleRaw3'})
|
||||||
|
sleep 10m
|
||||||
|
call assert_equal("[2, \"something\"]", s:reply2)
|
||||||
|
" wait for up to 500 msec for the 200 msec delayed reply
|
||||||
|
for i in range(50)
|
||||||
|
sleep 10m
|
||||||
|
if s:reply3 != ''
|
||||||
|
break
|
||||||
|
endif
|
||||||
|
endfor
|
||||||
|
call assert_equal("[3, \"waited\"]", s:reply3)
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
func Test_raw_one_time_callback()
|
||||||
|
call ch_logfile('channellog', 'w')
|
||||||
|
call ch_log('Test_raw_one_time_callback()')
|
||||||
|
call s:run_server('s:raw_one_time_callback')
|
||||||
|
call ch_logfile('')
|
||||||
|
endfunc
|
||||||
|
|
||||||
|
"""""""""
|
||||||
|
|
||||||
" Test that trying to connect to a non-existing port fails quickly.
|
" Test that trying to connect to a non-existing port fails quickly.
|
||||||
func Test_connect_waittime()
|
func Test_connect_waittime()
|
||||||
call ch_log('Test_connect_waittime()')
|
call ch_log('Test_connect_waittime()')
|
||||||
@@ -325,6 +382,8 @@ func Test_connect_waittime()
|
|||||||
endtry
|
endtry
|
||||||
endfunc
|
endfunc
|
||||||
|
|
||||||
|
"""""""""
|
||||||
|
|
||||||
func Test_raw_pipe()
|
func Test_raw_pipe()
|
||||||
if !has('job')
|
if !has('job')
|
||||||
return
|
return
|
||||||
|
@@ -743,6 +743,8 @@ static char *(features[]) =
|
|||||||
|
|
||||||
static int included_patches[] =
|
static int included_patches[] =
|
||||||
{ /* Add new patch number below this line */
|
{ /* Add new patch number below this line */
|
||||||
|
/**/
|
||||||
|
1483,
|
||||||
/**/
|
/**/
|
||||||
1482,
|
1482,
|
||||||
/**/
|
/**/
|
||||||
|
Reference in New Issue
Block a user