Increase buffer size for channel

pull/26/head
Sheng 6 years ago
parent 41740690ac
commit 5f3641701e

@ -65,7 +65,7 @@ class Server(paramiko.ServerInterface):
def check_auth_password(self, username, password):
print('Auth attempt with username: {!r} & password: {!r}'.format(username, password)) # noqa
if (username in ['robey', 'bar']) and (password == 'foo'):
if (username in ['robey', 'bar', 'foo']) and (password == 'foo'):
return paramiko.AUTH_SUCCESSFUL
return paramiko.AUTH_FAILED
@ -150,6 +150,17 @@ def run_ssh_server(port=2200, running=True):
if username == 'bar':
msg = chan.recv(1024)
chan.send(msg)
elif username == 'foo':
lst = []
while True:
msg = chan.recv(32 * 1024)
lst.append(msg)
if msg.endswith(b'\r\n\r\n'):
break
data = b''.join(lst)
while data:
s = chan.send(data)
data = data[s:]
chan.close()
t.close()

@ -487,4 +487,32 @@ class TestAppInDebug(OtherTestBase):
class TestAppMiscell(OtherTestBase):
debug = False
@tornado.testing.gen_test
def test_app_for_sending_message_with_large_size(self):
url = self.get_url('/')
client = self.get_http_client()
body = urlencode(dict(self.body, username='foo'))
response = yield client.fetch(url, method='POST', body=body,
headers=self.headers)
data = json.loads(to_str(response.body))
self.assertIsNone(data['status'])
self.assertIsNotNone(data['id'])
self.assertIsNotNone(data['encoding'])
url = url.replace('http', 'ws')
ws_url = url + 'ws?id=' + data['id']
ws = yield tornado.websocket.websocket_connect(ws_url)
msg = yield ws.read_message()
self.assertEqual(to_str(msg, data['encoding']), banner)
send = 'h' * (64 * 1024) + '\r\n\r\n'
yield ws.write_message(json.dumps({'data': send}))
lst = []
while True:
msg = yield ws.read_message()
lst.append(msg)
if msg.endswith(b'\r\n\r\n'):
break
recv = b''.join(lst).decode(data['encoding'])
self.assertEqual(send, recv)
ws.close()

@ -6,7 +6,7 @@ from tornado.iostream import _ERRNO_CONNRESET
from tornado.util import errno_from_exception
BUF_SIZE = 1024
BUF_SIZE = 32 * 1024
workers = {}
@ -46,6 +46,8 @@ class Worker(object):
if self.mode != mode:
self.loop.update_handler(self.fd, mode)
self.mode = mode
if mode == IOLoop.WRITE:
self.loop.call_later(0.1, self, self.fd, IOLoop.WRITE)
def on_read(self):
logging.debug('worker {} on read'.format(self.id))

Loading…
Cancel
Save