assert (terminal->fd < 0);
assert (terminal->fd_watch == NULL);
- terminal->fd = open (terminal->name, O_RDWR | O_NOCTTY);
+ terminal->fd = open (terminal->name, O_RDWR | O_NOCTTY | O_NONBLOCK);
if (terminal->fd < 0) {
ply_trace ("Unable to open terminal device '%s': %m", terminal->name);
return PLY_TERMINAL_OPEN_RESULT_FAILURE;
}
+ ply_set_fd_as_blocking (terminal->fd);
+
terminal->fd_watch = ply_event_loop_watch_fd (terminal->loop, terminal->fd,
PLY_EVENT_LOOP_FD_STATUS_HAS_DATA,
(ply_event_handler_t) on_tty_input,
return (flags & O_NONBLOCK) != 0;
}
+bool
+ply_set_fd_as_blocking (int fd)
+{
+ int flags;
+ int ret = 0;
+
+ assert (fd >= 0);
+
+ flags = fcntl (fd, F_GETFL);
+
+ if (flags == -1) {
+ return false;
+ }
+
+ if (flags & O_NONBLOCK) {
+ flags &= ~O_NONBLOCK;
+
+ ret = fcntl (fd, F_SETFL, flags);
+ }
+
+ return ret == 0;
+}
+
char **
ply_copy_string_array (const char *const *array)
{
bool ply_fd_has_data (int fd);
bool ply_fd_can_take_data (int fd);
bool ply_fd_may_block (int fd);
+bool ply_set_fd_as_blocking (int fd);
char **ply_copy_string_array (const char *const *array);
void ply_free_string_array (char **array);
bool ply_string_has_prefix (const char *string,