aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-08-14 16:34:54 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-08-14 21:08:28 -0400
commit4b5109c1b9bf5ac74d749dc63a17dbf3f840482f (patch)
treef74c1ca2d3cdb775930ccc857a182ce10ca22f16
parent085817d33252aa98b6bc232bb5ed12b5f77aebcb (diff)
downloadkutter-4b5109c1b9bf5ac74d749dc63a17dbf3f840482f.tar.gz
kutter-4b5109c1b9bf5ac74d749dc63a17dbf3f840482f.tar.xz
kutter-4b5109c1b9bf5ac74d749dc63a17dbf3f840482f.zip
serialqueue: Make sure fds are in non-blocking mode
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
-rw-r--r--klippy/serialqueue.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/klippy/serialqueue.c b/klippy/serialqueue.c
index a0f89239..6ad1b916 100644
--- a/klippy/serialqueue.c
+++ b/klippy/serialqueue.c
@@ -12,6 +12,7 @@
// clock times, prioritizes commands, and handles retransmissions. A
// background thread is launched to do this work and minimize latency.
+#include <fcntl.h> // fcntl
#include <math.h> // ceil
#include <poll.h> // poll
#include <pthread.h> // pthread_mutex_lock
@@ -178,6 +179,22 @@ pollreactor_is_exit(struct pollreactor *pr)
return pr->must_exit;
}
+static int
+set_non_blocking(int fd)
+{
+ int flags = fcntl(fd, F_GETFL);
+ if (flags < 0) {
+ report_errno("fcntl getfl", flags);
+ return -1;
+ }
+ int ret = fcntl(fd, F_SETFL, flags | O_NONBLOCK);
+ if (ret < 0) {
+ report_errno("fcntl setfl", flags);
+ return -1;
+ }
+ return 0;
+}
+
/****************************************************************
* Serial protocol helpers
@@ -776,6 +793,9 @@ serialqueue_alloc(int serial_fd, int write_only)
pollreactor_add_fd(&sq->pr, SQPF_PIPE, sq->pipe_fds[0], kick_event);
pollreactor_add_timer(&sq->pr, SQPT_RETRANSMIT, retransmit_event);
pollreactor_add_timer(&sq->pr, SQPT_COMMAND, command_event);
+ set_non_blocking(serial_fd);
+ set_non_blocking(sq->pipe_fds[0]);
+ set_non_blocking(sq->pipe_fds[1]);
// Retransmit setup
sq->send_seq = 1;