mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-30 14:08:21 +00:00
poll: rework timeout
This commit is contained in:
@@ -270,7 +270,7 @@ int arp_lookup(netdev_t *netdev, uint32_t ip, mac_t *mac) {
|
||||
}
|
||||
|
||||
MUTEX_RELEASE(&cachelock);
|
||||
int timedout = EVENT_WAIT(&eventlistener, to);
|
||||
e = EVENT_WAIT(&eventlistener, to);
|
||||
MUTEX_ACQUIRE(&cachelock);
|
||||
time = timekeeper_time();
|
||||
|
||||
@@ -279,7 +279,10 @@ int arp_lookup(netdev_t *netdev, uint32_t ip, mac_t *mac) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (timedout || time.s > end.s || (end.s == time.s && time.ns >= end.ns)) {
|
||||
if (e == EINTR)
|
||||
return e;
|
||||
|
||||
if (e == ETIMEDOUT || time.s > end.s || (end.s == time.s && time.ns >= end.ns)) {
|
||||
e = ENETUNREACH;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ static void timeout(context_t *, dpcarg_t arg) {
|
||||
spinlock_acquire(&desc->eventlock);
|
||||
|
||||
if (spinlock_try(&desc->lock))
|
||||
sched_wakeup(desc->thread, 1);
|
||||
sched_wakeup(desc->thread, ETIMEDOUT);
|
||||
|
||||
spinlock_release(&desc->eventlock);
|
||||
interrupt_set(intstate);
|
||||
@@ -115,15 +115,13 @@ int poll_dowait(polldesc_t *desc, size_t ustimeout) {
|
||||
ret = EINTR;
|
||||
}
|
||||
|
||||
if (ustimeout != 0 && ret != 1) {
|
||||
if (ustimeout != 0 && ret != ETIMEDOUT) {
|
||||
timer_remove(current_cpu()->timer, &sleepentry);
|
||||
sched_target_cpu(NULL);
|
||||
}
|
||||
|
||||
interrupt_set(intstate);
|
||||
|
||||
ret = ret == 1 ? 0 : ret;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
+7
-8
@@ -266,17 +266,16 @@ static int read(int minor, iovec_iterator_t *iovec_iterator, size_t size, uintma
|
||||
|
||||
error = poll_dowait(&desc, effectivetimeout);
|
||||
|
||||
|
||||
if (error == 0 && (desc.event == NULL || (desc.event && desc.event->revents == 0))) {
|
||||
// timed out!
|
||||
poll_leave(&desc);
|
||||
poll_destroydesc(&desc);
|
||||
break;
|
||||
}
|
||||
|
||||
poll_leave(&desc);
|
||||
poll_destroydesc(&desc);
|
||||
|
||||
if (error == ETIMEDOUT) {
|
||||
// this does not return an error on timeout.
|
||||
// instead, it just returns the number of bytes read.
|
||||
error = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
if (error)
|
||||
goto leave;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user