summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDavid Herrmann <dh.herrmann@gmail.com>2013-10-29 15:20:31 +0100
committerDavid Herrmann <dh.herrmann@gmail.com>2013-10-29 15:20:31 +0100
commit346bcbcb26fee9c053b7af3ce26165d15b687126 (patch)
treea468760df2e8f0ce13b1ecfd1bfc78428b9ac24a /src
parent303dab3dcb866ade29267c3ad585f433d60638f1 (diff)
owfd: wpa_ctrl: use ppoll() instead of poll()
Provide better precision by using ppoll() and prepare for sigmask handling. Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Diffstat (limited to 'src')
-rw-r--r--src/shared.c6
-rw-r--r--src/shared.h1
-rw-r--r--src/wpa_ctrl.c15
3 files changed, 16 insertions, 6 deletions
diff --git a/src/shared.c b/src/shared.c
index 5ce34f8..3522144 100644
--- a/src/shared.c
+++ b/src/shared.c
@@ -45,3 +45,9 @@ int64_t get_time_us(void)
return t;
}
+
+void us_to_timespec(struct timespec *ts, int64_t us)
+{
+ ts->tv_sec = us / (1000LL * 1000LL);
+ ts->tv_nsec = (us % (1000LL * 1000LL)) * 1000LL;
+}
diff --git a/src/shared.h b/src/shared.h
index 59c85b2..42b1367 100644
--- a/src/shared.h
+++ b/src/shared.h
@@ -35,6 +35,7 @@ extern "C" {
#endif
int64_t get_time_us(void);
+void us_to_timespec(struct timespec *ts, int64_t us);
#ifdef __cplusplus
}
diff --git a/src/wpa_ctrl.c b/src/wpa_ctrl.c
index 3eaf4fe..cc2a782 100644
--- a/src/wpa_ctrl.c
+++ b/src/wpa_ctrl.c
@@ -260,8 +260,7 @@ static int arm_timer(struct owfd_wpa_ctrl *wpa, int64_t usecs)
struct itimerspec spec;
int r;
- spec.it_value.tv_sec = usecs / 1000000LL;
- spec.it_value.tv_nsec = (usecs % 1000000LL) * 1000LL;
+ us_to_timespec(&spec.it_value, usecs);
spec.it_interval = spec.it_value;
r = timerfd_settime(wpa->tfd, 0, &spec, NULL);
@@ -532,6 +531,7 @@ static int timed_send(int fd, const void *cmd, size_t cmd_len,
int n;
struct pollfd fds[1];
const size_t max = sizeof(fds) / sizeof(*fds);
+ struct timespec ts;
start = get_time_us();
@@ -540,8 +540,9 @@ static int timed_send(int fd, const void *cmd, size_t cmd_len,
fds[0].fd = fd;
fds[0].events = POLLHUP | POLLERR | POLLOUT;
- n = poll(fds, max, *timeout / 1000LL);
- if (n < 0 && errno != EAGAIN && errno != EINTR) {
+ us_to_timespec(&ts, *timeout);
+ n = ppoll(fds, max, &ts, NULL);
+ if (n < 0 && errno != EAGAIN) {
return -errno;
} else if (!n) {
return -ETIMEDOUT;
@@ -584,6 +585,7 @@ static int timed_recv(int fd, void *reply, size_t *reply_len, int64_t *timeout)
int n;
struct pollfd fds[1];
const size_t max = sizeof(fds) / sizeof(*fds);
+ struct timespec ts;
start = get_time_us();
@@ -592,8 +594,9 @@ static int timed_recv(int fd, void *reply, size_t *reply_len, int64_t *timeout)
fds[0].fd = fd;
fds[0].events = POLLHUP | POLLERR | POLLIN;
- n = poll(fds, max, *timeout / 1000LL);
- if (n < 0 && errno != EAGAIN && errno != EINTR) {
+ us_to_timespec(&ts, *timeout);
+ n = ppoll(fds, max, &ts, NULL);
+ if (n < 0 && errno != EAGAIN) {
return -errno;
} else if (!n) {
return -ETIMEDOUT;