Skip to content

Commit

Permalink
use unbuffered I/O on ttys
Browse files Browse the repository at this point in the history
  • Loading branch information
cnvogelg committed Mar 9, 2020
1 parent f7e3da7 commit a1bd072
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions amitools/vamos/lib/dos/FileManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,19 @@ def __init__(self, path_mgr, alloc, mem):
self.umask = os.umask(0)
os.umask(self.umask)

def _create_fh(self, fileno, mode, ami_name, sys_name):
# create unbuffered raw stream if its a tty
if os.isatty(fileno):
fobj = open(fileno, mode, buffering=0)
else:
fobj = open(fileno, mode)
return FileHandle(fobj, ami_name, sys_name, need_close=True)

def setup(self, fs_handler_port):
self.fs_handler_port = fs_handler_port
# setup std input/output
self.std_input = FileHandle(sys.stdin.buffer,'<STDIN>','',need_close=False)
self.std_output = FileHandle(sys.stdout.buffer,'<STDOUT>','',need_close=False)
self.std_input = self._create_fh(sys.stdin.fileno(), 'rb', '<STDIN>', '/dev/stdin')
self.std_output = self._create_fh(sys.stdout.fileno(), 'wb', '<STDOUT>', '/dev/stdout')
self._register_file(self.std_input)
self._register_file(self.std_output)

Expand Down Expand Up @@ -74,7 +82,7 @@ def open(self, lock, ami_path, f_mode):
fh = FileHandle(fobj, ami_path, sys_name, is_nil = True)
elif uname == '*' or uname.startswith('CONSOLE:'):
sys_name = ''
fh = FileHandle(sys.stdout.buffer,'*','',need_close=False)
fh = self._create_fh(sys.stdout.fileno(), 'wb', '*', '')
else:
# map to system path
sys_path = self.path_mgr.ami_to_sys_path(lock,ami_path,searchMulti=True)
Expand Down

0 comments on commit a1bd072

Please sign in to comment.