mirror of https://gerrit.osmocom.org/libosmocore
serial: Open devie in non-blocking mode and then switch to blocking
There are some serial ports that apparently block during the open in some circumstances. We don't want that. We want to either open it immediately, or fail fast. Change-Id: I626b138574bc50f4f4b09c4d609f3623ff512dff
This commit is contained in:
parent
a0f74f218b
commit
1db37820aa
20
src/serial.c
20
src/serial.c
|
@ -59,16 +59,30 @@
|
|||
int
|
||||
osmo_serial_init(const char *dev, speed_t baudrate)
|
||||
{
|
||||
int rc, fd=0, v24;
|
||||
int rc, fd=0, v24, flags;
|
||||
struct termios tio;
|
||||
|
||||
/* Open device */
|
||||
fd = open(dev, O_RDWR | O_NOCTTY);
|
||||
/* Use nonblock as the device might block otherwise */
|
||||
fd = open(dev, O_RDWR | O_NOCTTY | O_SYNC | O_NONBLOCK);
|
||||
if (fd < 0) {
|
||||
dbg_perror("open");
|
||||
return -errno;
|
||||
}
|
||||
|
||||
/* now put it into blcoking mode */
|
||||
flags = fcntl(fd, F_GETFL, 0);
|
||||
if (flags < 0) {
|
||||
dbg_perror("fcntl get flags");
|
||||
return -1;
|
||||
}
|
||||
|
||||
flags &= ~O_NONBLOCK;
|
||||
rc = fcntl(fd, F_SETFL, flags);
|
||||
if (rc != 0) {
|
||||
dbg_perror("fcntl set flags");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Configure serial interface */
|
||||
rc = tcgetattr(fd, &tio);
|
||||
if (rc < 0) {
|
||||
|
|
Loading…
Reference in New Issue