After an iou reload you can write on the console

This commit is contained in:
Julien Duponchelle 2015-02-26 15:47:47 +01:00
parent 5e59145948
commit 62afef06af

View File

@ -171,6 +171,9 @@ class TTY(Console):
self.epoll = epoll
epoll.register(self.fd, select.EPOLLIN | select.EPOLLET)
def unregister(self, epoll):
epoll.unregister(self.fd)
def __enter__(self):
try:
self.fd = open('/dev/tty', 'r+b', buffering=0)
@ -240,6 +243,9 @@ class TelnetServer(Console):
self.epoll = epoll
epoll.register(self.sock_fd, select.EPOLLIN)
def unregister(self, epoll):
epoll.unregister(self.sock_fd)
def _read_block(self, bufsize):
buf = self._read_cur(bufsize, socket.MSG_WAITALL)
# If we don't get everything we were looking for then the
@ -420,6 +426,9 @@ class IOU:
self.epoll = epoll
epoll.register(self.fd, select.EPOLLIN | select.EPOLLET)
def unregister(self, epoll):
epoll.unregister(self.fd)
def fileno(self):
return self.fd.fileno()
@ -468,12 +477,11 @@ def mkdir_netio(netio_dir):
raise NetioError("Couldn't create directory {}: {}".format(netio_dir, e))
def send_recv_loop(console, router, esc_char, stop_event):
epoll = select.epoll()
def send_recv_loop(epoll, console, router, esc_char, stop_event):
router.register(epoll)
console.register(epoll)
try:
router_fileno = router.fileno()
esc_quit = bytes(ESC_QUIT.upper(), 'ascii')
esc_state = False
@ -532,6 +540,10 @@ def send_recv_loop(console, router, esc_char, stop_event):
esc_state = True
else:
router.write(buf)
finally:
log.debug("Finally")
router.unregister(epoll)
console.unregister(epoll)
def get_args():
@ -609,6 +621,7 @@ def start_ioucon(cmdline_args, stop_event):
'ADDR:PORT (like 127.0.0.1:20000)')
while not stop_event.is_set():
epoll = select.epoll()
try:
if args.telnet_server:
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():
try:
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:
pass
else:
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:
pass
except KeyboardInterrupt: