Reengineering the timeout manager. Allows to create an arbitrary number of timer

with the possibility to invoke a callback function on timeout.
This commit is contained in:
vemax78
2014-03-02 19:31:27 +01:00
parent aa87719432
commit 6042161d75
31 changed files with 1259 additions and 1138 deletions

View File

@ -309,21 +309,19 @@ int capwap_compare_ip(struct sockaddr_storage* addr1, struct sockaddr_storage* a
}
/* Wait receive packet with timeout */
int capwap_wait_recvready(struct pollfd* fds, int fdscount, struct timeout_control* timeout) {
int capwap_wait_recvready(struct pollfd* fds, int fdscount, struct capwap_timeout* timeout) {
int i;
int readysocket;
int polltimeout = -1;
int polltimeout = CAPWAP_TIMEOUT_INFINITE;
ASSERT(fds);
ASSERT(fdscount > 0);
/* Check timeout */
if (timeout) {
long indextimer;
capwap_timeout_update(timeout);
polltimeout = capwap_timeout_get(timeout, &indextimer);
if ((polltimeout <= 0) && (indextimer != CAPWAP_TIMER_UNDEF)) {
polltimeout = capwap_timeout_getcoming(timeout);
if (!polltimeout) {
capwap_timeout_hasexpired(timeout);
return CAPWAP_RECV_ERROR_TIMEOUT;
}
}
@ -343,12 +341,8 @@ int capwap_wait_recvready(struct pollfd* fds, int fdscount, struct timeout_contr
return CAPWAP_RECV_ERROR_SOCKET;
}
}
} else if (readysocket == 0) {
/* Update timer for detect timeout */
if (timeout) {
capwap_timeout_update(timeout);
}
} else if (!readysocket && timeout) {
capwap_timeout_hasexpired(timeout);
return CAPWAP_RECV_ERROR_TIMEOUT;
} else if (errno == EINTR) {
return CAPWAP_RECV_ERROR_INTR;
@ -451,7 +445,7 @@ int capwap_recvfrom_fd(int fd, void* buffer, int* size, struct sockaddr_storage*
}
/* Receive packet with timeout */
int capwap_recvfrom(struct pollfd* fds, int fdscount, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr, struct timeout_control* timeout) {
int capwap_recvfrom(struct pollfd* fds, int fdscount, void* buffer, int* size, struct sockaddr_storage* recvfromaddr, struct sockaddr_storage* recvtoaddr, struct capwap_timeout* timeout) {
int index;
ASSERT(fds);