Skip to content

Commit

Permalink
issue ansible#319: have cfsetraw() generate sensible flags.
Browse files Browse the repository at this point in the history
Attempting to fix issue on WSL.

Closes ansible#71
  • Loading branch information
dw committed Jul 27, 2018
1 parent 441c60a commit 56943d3
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions mitogen/parent.py
Expand Up @@ -102,26 +102,23 @@ def is_immediate_child(msg, stream):
def flags(names):
"""Return the result of ORing a set of (space separated) :py:mod:`termios`
module constants together."""
return sum(getattr(termios, name) for name in names.split())
return sum(getattr(termios, name, 0)
for name in names.split())


def cfmakeraw(tflags):
"""Given a list returned by :py:func:`termios.tcgetattr`, return a list
that has been modified in the same manner as the `cfmakeraw()` C library
function."""
modified in a manner similar to the `cfmakeraw()` C library function, but
additionally disabling local echo."""
# BSD: https://github.com/freebsd/freebsd/blob/master/lib/libc/gen/termios.c#L162
# Linux: https://github.com/lattera/glibc/blob/master/termios/cfmakeraw.c#L20
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = tflags
iflag &= ~flags('IGNBRK BRKINT PARMRK ISTRIP INLCR IGNCR ICRNL IXON')
oflag &= ~flags('OPOST IXOFF')
lflag &= ~flags('ECHO ECHOE ECHONL ICANON ISIG IEXTEN')
iflag &= ~flags('IMAXBEL IXOFF INPCK BRKINT PARMRK ISTRIP INLCR ICRNL IXON IGNPAR')
iflag &= ~flags('IGNBRK BRKINT PARMRK')
oflag &= ~flags('OPOST')
lflag &= ~flags('ECHO ECHOE ECHOK ECHONL ICANON ISIG IEXTEN NOFLSH TOSTOP PENDIN')
cflag &= ~flags('CSIZE PARENB')
cflag |= flags('CS8')

# TODO: one or more of the above bit twiddles sets or omits a necessary
# flag. Forcing these fields to zero, as shown below, gets us what we want
# on Linux/OS X, but it is possibly broken on some other OS.
iflag = 0
oflag = 0
lflag = 0
cflag |= flags('CS8 CREAD')
return [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]


Expand Down

0 comments on commit 56943d3

Please sign in to comment.