else
new_cmd->param = NULL;
new_cmd->sent = 0;
+ new_cmd->tv_start.tv_sec = 0;
+ new_cmd->tv_start.tv_usec = 0;
+ gettimeofday(&new_cmd->tv_start, NULL);
new_cmd->next = NULL;
if(!(*first)) {
return 0;
}
+// timeout between 1 and 2 seconds
+int cmd_has_expired(const cmd_t cmd)
+{
+ struct timeval now;
+ now.tv_sec = 2;
+ now.tv_usec = 0;
+ gettimeofday(&now, NULL);
+
+ if(cmd.tv_start.tv_sec + 2 >= now.tv_sec)
+ return 1;
+
+ return 0;
+}
+
void cmd_pop(cmd_t** first)
{
if(!first || !(*first))
#ifndef _COMMAND_QUEUE_H_
#define _COMMAND_QUEUE_H_
+#include <sys/time.h>
+
enum cmd_id_enum { OPEN, CLOSE, TOGGLE, RESET, STATUS, LOG };
typedef enum cmd_id_enum cmd_id_t;
cmd_id_t cmd;
char* param;
int sent;
+ struct timeval tv_start;
struct cmd_struct* next;
};
typedef struct cmd_struct cmd_t;
int cmd_push(cmd_t** first, int fd, cmd_id_t cmd, const char* param);
+int cmd_has_expired(const cmd_t cmd);
void cmd_pop(cmd_t** first);
void cmd_clear(cmd_t** first);
FD_SET(sig_fd, &readfds);
max_fd = (max_fd < sig_fd) ? sig_fd : max_fd;
+ struct timeval timeout;
int return_value = 0;
while(!return_value) {
memcpy(&tmpfds, &readfds, sizeof(tmpfds));
- int ret = select(max_fd+1, &tmpfds, NULL, NULL, NULL);
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 200000;
+ int ret = select(max_fd+1, &tmpfds, NULL, NULL, &timeout);
if(ret == -1 && errno != EINTR) {
log_printf(ERROR, "select returned with error: %s", strerror(errno));
return_value = -1;
break;
}
- if(!ret || ret == -1)
+ if(ret == -1)
continue;
+ if(!ret) {
+ if(cmd_q && cmd_has_expired(*cmd_q)) {
+ log_printf(ERROR, "last command expired");
+ cmd_pop(&cmd_q);
+ }
+ else
+ continue;
+ }
if(FD_ISSET(sig_fd, &tmpfds)) {
if(signal_handle()) {