gpio: add dummy read before poll()

this fixes blocking polls on some platforms.

resolves #5.

Signed-off-by: Vanya A. Sergeev <v@sergeev.io>
This commit is contained in:
Михаил Корнилов
2016-11-22 13:05:44 +03:00
committed by Vanya A. Sergeev
parent e0871c09fc
commit 0643fe91eb

View File

@@ -159,8 +159,13 @@ int gpio_write(gpio_t *gpio, bool value) {
int gpio_poll(gpio_t *gpio, int timeout_ms) {
struct pollfd fds[1];
char buf[1];
int ret;
/* Dummy read before poll */
if (read(gpio->fd, buf, 1) < 0)
return _gpio_error(gpio, GPIO_ERROR_IO, errno, "Reading GPIO 'value'");
/* Seek to end */
if (lseek(gpio->fd, 0, SEEK_END) < 0)
return _gpio_error(gpio, GPIO_ERROR_IO, errno, "Seeking to end of GPIO 'value'");
@@ -345,4 +350,3 @@ unsigned int gpio_pin(gpio_t *gpio) {
int gpio_fd(gpio_t *gpio) {
return gpio->fd;
}