commit ef13e4cd1beac8e49052a7a711235733b5f35226
parent 52fa041ff7a3836cdb148fccbfd0cb01c1d6b0c6
Author: konkers <konkers@konkers.net>
Date: Thu, 21 Mar 2013 12:35:15 -0700
Merge pull request #4 from colincross/master
Switch the serial port to blocking after opening
Diffstat:
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));