mirror of
https://github.com/vim/vim.git
synced 2025-09-06 21:53:38 -04:00
patch 7.4.1252
Problem: The channel test server may receive two messages concatenated. Solution: Split the messages.
This commit is contained in:
parent
bf087cead9
commit
e7bed627c8
@ -45,56 +45,69 @@ class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
|
|||||||
print("=== socket closed ===")
|
print("=== socket closed ===")
|
||||||
break
|
break
|
||||||
print("received: {}".format(data))
|
print("received: {}".format(data))
|
||||||
try:
|
|
||||||
decoded = json.loads(data)
|
|
||||||
except ValueError:
|
|
||||||
print("json decoding failed")
|
|
||||||
decoded = [-1, '']
|
|
||||||
|
|
||||||
# Send a response if the sequence number is positive.
|
# We may receive two messages at once. Take the part up to the
|
||||||
if decoded[0] >= 0:
|
# matching "]" (recognized by finding "][").
|
||||||
if decoded[1] == 'hello!':
|
while data != '':
|
||||||
# simply send back a string
|
splitidx = data.find('][')
|
||||||
response = "got it"
|
if splitidx < 0:
|
||||||
elif decoded[1] == 'make change':
|
todo = data
|
||||||
# Send two ex commands at the same time, before replying to
|
data = ''
|
||||||
# the request.
|
|
||||||
cmd = '["ex","call append(\\"$\\",\\"added1\\")"]'
|
|
||||||
cmd += '["ex","call append(\\"$\\",\\"added2\\")"]'
|
|
||||||
print("sending: {}".format(cmd))
|
|
||||||
thesocket.sendall(cmd.encode('utf-8'))
|
|
||||||
response = "ok"
|
|
||||||
elif decoded[1] == 'eval-works':
|
|
||||||
# Send an eval request. We ignore the response.
|
|
||||||
cmd = '["eval","\\"foo\\" . 123", -1]'
|
|
||||||
print("sending: {}".format(cmd))
|
|
||||||
thesocket.sendall(cmd.encode('utf-8'))
|
|
||||||
response = "ok"
|
|
||||||
elif decoded[1] == 'eval-fails':
|
|
||||||
# Send an eval request that will fail.
|
|
||||||
cmd = '["eval","xxx", -2]'
|
|
||||||
print("sending: {}".format(cmd))
|
|
||||||
thesocket.sendall(cmd.encode('utf-8'))
|
|
||||||
response = "ok"
|
|
||||||
elif decoded[1] == 'eval-result':
|
|
||||||
# Send back the last received eval result.
|
|
||||||
response = last_eval
|
|
||||||
elif decoded[1] == '!quit!':
|
|
||||||
# we're done
|
|
||||||
sys.exit(0)
|
|
||||||
elif decoded[1] == '!crash!':
|
|
||||||
# Crash!
|
|
||||||
42 / 0
|
|
||||||
else:
|
else:
|
||||||
response = "what?"
|
todo = data[:splitidx + 1]
|
||||||
|
data = data[splitidx + 1:]
|
||||||
|
print("using: {}".format(todo))
|
||||||
|
|
||||||
encoded = json.dumps([decoded[0], response])
|
try:
|
||||||
print("sending: {}".format(encoded))
|
decoded = json.loads(todo)
|
||||||
thesocket.sendall(encoded.encode('utf-8'))
|
except ValueError:
|
||||||
|
print("json decoding failed")
|
||||||
|
decoded = [-1, '']
|
||||||
|
|
||||||
# Negative numbers are used for "eval" responses.
|
# Send a response if the sequence number is positive.
|
||||||
elif decoded[0] < 0:
|
if decoded[0] >= 0:
|
||||||
last_eval = decoded
|
if decoded[1] == 'hello!':
|
||||||
|
# simply send back a string
|
||||||
|
response = "got it"
|
||||||
|
elif decoded[1] == 'make change':
|
||||||
|
# Send two ex commands at the same time, before replying to
|
||||||
|
# the request.
|
||||||
|
cmd = '["ex","call append(\\"$\\",\\"added1\\")"]'
|
||||||
|
cmd += '["ex","call append(\\"$\\",\\"added2\\")"]'
|
||||||
|
print("sending: {}".format(cmd))
|
||||||
|
thesocket.sendall(cmd.encode('utf-8'))
|
||||||
|
response = "ok"
|
||||||
|
elif decoded[1] == 'eval-works':
|
||||||
|
# Send an eval request. We ignore the response.
|
||||||
|
cmd = '["eval","\\"foo\\" . 123", -1]'
|
||||||
|
print("sending: {}".format(cmd))
|
||||||
|
thesocket.sendall(cmd.encode('utf-8'))
|
||||||
|
response = "ok"
|
||||||
|
elif decoded[1] == 'eval-fails':
|
||||||
|
# Send an eval request that will fail.
|
||||||
|
cmd = '["eval","xxx", -2]'
|
||||||
|
print("sending: {}".format(cmd))
|
||||||
|
thesocket.sendall(cmd.encode('utf-8'))
|
||||||
|
response = "ok"
|
||||||
|
elif decoded[1] == 'eval-result':
|
||||||
|
# Send back the last received eval result.
|
||||||
|
response = last_eval
|
||||||
|
elif decoded[1] == '!quit!':
|
||||||
|
# we're done
|
||||||
|
sys.exit(0)
|
||||||
|
elif decoded[1] == '!crash!':
|
||||||
|
# Crash!
|
||||||
|
42 / 0
|
||||||
|
else:
|
||||||
|
response = "what?"
|
||||||
|
|
||||||
|
encoded = json.dumps([decoded[0], response])
|
||||||
|
print("sending: {}".format(encoded))
|
||||||
|
thesocket.sendall(encoded.encode('utf-8'))
|
||||||
|
|
||||||
|
# Negative numbers are used for "eval" responses.
|
||||||
|
elif decoded[0] < 0:
|
||||||
|
last_eval = decoded
|
||||||
|
|
||||||
thesocket = None
|
thesocket = None
|
||||||
|
|
||||||
|
@ -742,6 +742,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 */
|
||||||
|
/**/
|
||||||
|
1252,
|
||||||
/**/
|
/**/
|
||||||
1251,
|
1251,
|
||||||
/**/
|
/**/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user