DbgMuxConnHandler: implement DbgMuxConnInteractiveTerminal

This commit is contained in:
Vadim Yanitskiy 2022-06-30 19:33:45 +07:00
parent c58e7e3f07
commit 91abeb7220
1 changed files with 28 additions and 0 deletions

View File

@ -22,6 +22,7 @@ import socket
import queue
import enum
import abc
import sys
from typing import Any, Optional
from construct import Container
@ -123,6 +124,33 @@ class DbgMuxConnHandler(DbgMuxFrameHandler):
''' Called on connection termination '''
class DbgMuxConnInteractiveTerminal(DbgMuxConnHandler):
def __init__(self, *args, **kw):
self.attached: bool = False
super().__init__(*args)
def attach(self):
self.attached = True
while True:
try:
line = input()
if self.conn_state == ConnState.Established:
self.send_data(bytes(line, 'ascii'))
except (KeyboardInterrupt, EOFError) as e:
break
self.attached = False
def _handle_data(self, data: bytes) -> None:
if self.attached:
sys.stdout.write(data.decode('ascii'))
def _handle_establish(self) -> None:
pass
def _handle_terminate(self) -> None:
pass
class DbgMuxConnUdpBridge(DbgMuxConnHandler):
DGRAM_MAX_LEN: int = 1024