mirror of
https://github.com/GNS3/gns3-server.git
synced 2025-01-18 07:23:47 +02:00
After an iou reload you can write on the console
This commit is contained in:
parent
5e59145948
commit
62afef06af
@ -171,6 +171,9 @@ class TTY(Console):
|
|||||||
self.epoll = epoll
|
self.epoll = epoll
|
||||||
epoll.register(self.fd, select.EPOLLIN | select.EPOLLET)
|
epoll.register(self.fd, select.EPOLLIN | select.EPOLLET)
|
||||||
|
|
||||||
|
def unregister(self, epoll):
|
||||||
|
epoll.unregister(self.fd)
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
try:
|
try:
|
||||||
self.fd = open('/dev/tty', 'r+b', buffering=0)
|
self.fd = open('/dev/tty', 'r+b', buffering=0)
|
||||||
@ -240,6 +243,9 @@ class TelnetServer(Console):
|
|||||||
self.epoll = epoll
|
self.epoll = epoll
|
||||||
epoll.register(self.sock_fd, select.EPOLLIN)
|
epoll.register(self.sock_fd, select.EPOLLIN)
|
||||||
|
|
||||||
|
def unregister(self, epoll):
|
||||||
|
epoll.unregister(self.sock_fd)
|
||||||
|
|
||||||
def _read_block(self, bufsize):
|
def _read_block(self, bufsize):
|
||||||
buf = self._read_cur(bufsize, socket.MSG_WAITALL)
|
buf = self._read_cur(bufsize, socket.MSG_WAITALL)
|
||||||
# If we don't get everything we were looking for then the
|
# If we don't get everything we were looking for then the
|
||||||
@ -420,6 +426,9 @@ class IOU:
|
|||||||
self.epoll = epoll
|
self.epoll = epoll
|
||||||
epoll.register(self.fd, select.EPOLLIN | select.EPOLLET)
|
epoll.register(self.fd, select.EPOLLIN | select.EPOLLET)
|
||||||
|
|
||||||
|
def unregister(self, epoll):
|
||||||
|
epoll.unregister(self.fd)
|
||||||
|
|
||||||
def fileno(self):
|
def fileno(self):
|
||||||
return self.fd.fileno()
|
return self.fd.fileno()
|
||||||
|
|
||||||
@ -468,70 +477,73 @@ def mkdir_netio(netio_dir):
|
|||||||
raise NetioError("Couldn't create directory {}: {}".format(netio_dir, e))
|
raise NetioError("Couldn't create directory {}: {}".format(netio_dir, e))
|
||||||
|
|
||||||
|
|
||||||
def send_recv_loop(console, router, esc_char, stop_event):
|
def send_recv_loop(epoll, console, router, esc_char, stop_event):
|
||||||
|
|
||||||
epoll = select.epoll()
|
|
||||||
router.register(epoll)
|
router.register(epoll)
|
||||||
console.register(epoll)
|
console.register(epoll)
|
||||||
|
|
||||||
router_fileno = router.fileno()
|
try:
|
||||||
esc_quit = bytes(ESC_QUIT.upper(), 'ascii')
|
router_fileno = router.fileno()
|
||||||
esc_state = False
|
esc_quit = bytes(ESC_QUIT.upper(), 'ascii')
|
||||||
|
esc_state = False
|
||||||
|
|
||||||
while not stop_event.is_set():
|
while not stop_event.is_set():
|
||||||
event_list = epoll.poll(timeout=POLL_TIMEOUT)
|
event_list = epoll.poll(timeout=POLL_TIMEOUT)
|
||||||
|
|
||||||
# When/if the poll times out we send an empty datagram. If IOU
|
# When/if the poll times out we send an empty datagram. If IOU
|
||||||
# has gone away then this will toss a ConnectionRefusedError
|
# has gone away then this will toss a ConnectionRefusedError
|
||||||
# exception.
|
# exception.
|
||||||
if not event_list:
|
if not event_list:
|
||||||
router.write(b'')
|
router.write(b'')
|
||||||
continue
|
continue
|
||||||
|
|
||||||
for fileno, event in event_list:
|
for fileno, event in event_list:
|
||||||
buf = bytearray()
|
buf = bytearray()
|
||||||
|
|
||||||
# IOU --> tty(s)
|
# IOU --> tty(s)
|
||||||
if fileno == router_fileno:
|
if fileno == router_fileno:
|
||||||
while not stop_event.is_set():
|
while not stop_event.is_set():
|
||||||
data = router.read(BUFFER_SIZE)
|
data = router.read(BUFFER_SIZE)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
buf.extend(data)
|
buf.extend(data)
|
||||||
console.write(buf)
|
console.write(buf)
|
||||||
|
|
||||||
# tty --> IOU
|
# tty --> IOU
|
||||||
else:
|
|
||||||
while not stop_event.is_set():
|
|
||||||
data = console.read(fileno, BUFFER_SIZE)
|
|
||||||
if not data:
|
|
||||||
break
|
|
||||||
buf.extend(data)
|
|
||||||
|
|
||||||
# If we just received the escape character then
|
|
||||||
# enter the escape state.
|
|
||||||
#
|
|
||||||
# If we are in the escape state then check for a
|
|
||||||
# quit command. Or if it's the escape character then
|
|
||||||
# send the escape character. Else, send the escape
|
|
||||||
# character we ate earlier and whatever character we
|
|
||||||
# just got. Exit escape state.
|
|
||||||
#
|
|
||||||
# If we're not in the escape state and this isn't an
|
|
||||||
# escape character then just send it to IOU.
|
|
||||||
if esc_state:
|
|
||||||
if buf.upper() == esc_quit:
|
|
||||||
sys.exit(EXIT_SUCCESS)
|
|
||||||
elif buf == esc_char:
|
|
||||||
router.write(esc_char)
|
|
||||||
else:
|
|
||||||
router.write(esc_char)
|
|
||||||
router.write(buf)
|
|
||||||
esc_state = False
|
|
||||||
elif buf == esc_char:
|
|
||||||
esc_state = True
|
|
||||||
else:
|
else:
|
||||||
router.write(buf)
|
while not stop_event.is_set():
|
||||||
|
data = console.read(fileno, BUFFER_SIZE)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
buf.extend(data)
|
||||||
|
|
||||||
|
# If we just received the escape character then
|
||||||
|
# enter the escape state.
|
||||||
|
#
|
||||||
|
# If we are in the escape state then check for a
|
||||||
|
# quit command. Or if it's the escape character then
|
||||||
|
# send the escape character. Else, send the escape
|
||||||
|
# character we ate earlier and whatever character we
|
||||||
|
# just got. Exit escape state.
|
||||||
|
#
|
||||||
|
# If we're not in the escape state and this isn't an
|
||||||
|
# escape character then just send it to IOU.
|
||||||
|
if esc_state:
|
||||||
|
if buf.upper() == esc_quit:
|
||||||
|
sys.exit(EXIT_SUCCESS)
|
||||||
|
elif buf == esc_char:
|
||||||
|
router.write(esc_char)
|
||||||
|
else:
|
||||||
|
router.write(esc_char)
|
||||||
|
router.write(buf)
|
||||||
|
esc_state = False
|
||||||
|
elif buf == esc_char:
|
||||||
|
esc_state = True
|
||||||
|
else:
|
||||||
|
router.write(buf)
|
||||||
|
finally:
|
||||||
|
log.debug("Finally")
|
||||||
|
router.unregister(epoll)
|
||||||
|
console.unregister(epoll)
|
||||||
|
|
||||||
|
|
||||||
def get_args():
|
def get_args():
|
||||||
@ -609,6 +621,7 @@ def start_ioucon(cmdline_args, stop_event):
|
|||||||
'ADDR:PORT (like 127.0.0.1:20000)')
|
'ADDR:PORT (like 127.0.0.1:20000)')
|
||||||
|
|
||||||
while not stop_event.is_set():
|
while not stop_event.is_set():
|
||||||
|
epoll = select.epoll()
|
||||||
try:
|
try:
|
||||||
if args.telnet_server:
|
if args.telnet_server:
|
||||||
with TelnetServer(addr, nport, stop_event) as console:
|
with TelnetServer(addr, nport, stop_event) as console:
|
||||||
@ -616,12 +629,12 @@ def start_ioucon(cmdline_args, stop_event):
|
|||||||
while not stop_event.is_set():
|
while not stop_event.is_set():
|
||||||
try:
|
try:
|
||||||
with IOU(ttyC, ttyS, stop_event) as router:
|
with IOU(ttyC, ttyS, stop_event) as router:
|
||||||
send_recv_loop(console, router, b'', stop_event)
|
send_recv_loop(epoll, console, router, b'', stop_event)
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
with IOU(ttyC, ttyS, stop_event) as router, TTY() as console:
|
with IOU(ttyC, ttyS, stop_event) as router, TTY() as console:
|
||||||
send_recv_loop(console, router, esc_char, stop_event)
|
send_recv_loop(epoll, console, router, esc_char, stop_event)
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
pass
|
pass
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
Loading…
Reference in New Issue
Block a user