sconsole

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit b6f6965252c97768365e12fe908fa710cd3c2fb7
parent ed15a97ae2d034f3683e3a51802ee31520967e7c
Author: Colin Cross <ccross@android.com>
Date:   Wed, 20 Mar 2013 18:19:45 -0700

Switch the serial port to blocking after opening

The serial port must be opened non-blocking to avoid waiting for
carrier detect during open, but leaving it set to non-blocking
causes later writes to fail with "Resource temporarily unavailable".
Switch the fd back to blocking mode after opening.

Diffstat:
Msconsole.c | 16++++++++++++++++
1 file changed, 16 insertions(+), 0 deletions(-)

diff --git a/sconsole.c b/sconsole.c @@ -103,11 +103,27 @@ int openserial(const char *device, int speed) { struct termios tio; int fd; + int fl; + + /* open the serial port non-blocking to avoid waiting for cd */ fd = open(device, O_RDWR | O_NOCTTY | O_NDELAY); if (fd < 0) return -1; + + /* then switch the fd to blocking */ + fl = fcntl(fd, F_GETFL, 0); + if (fl < 0) { + close(fd); + return -1; + } + fl = fcntl(fd, F_SETFL, fl & ~O_NDELAY); + if (fl < 0) { + close(fd); + return -1; + } + if (tcgetattr(fd, &tio)) memset(&tio, 0, sizeof(tio));