Browse Source

lib update

master
Olaf Rempel 10 years ago
parent
commit
3a379757b6
3 changed files with 21 additions and 4 deletions
  1. +13
    -2
      daemon/event.c
  2. +1
    -0
      daemon/event.h
  3. +7
    -2
      daemon/logging.c

+ 13
- 2
daemon/event.c View File

@@ -30,6 +30,7 @@

static LIST_HEAD(event_fd_list);
static LIST_HEAD(event_timeout_list);
static int leave_loop;

struct event_fd {
struct list_head list;
@@ -198,6 +199,11 @@ void event_remove_timeout(struct event_timeout *entry)
entry->flags |= EVENT_DELETE;
}

void event_loop_break(void)
{
leave_loop = 1;
}

int event_loop(void)
{
fd_set *fdsets = malloc(sizeof(fd_set) * 2);
@@ -206,7 +212,8 @@ int event_loop(void)
return -1;
}

while (1) {
leave_loop = 0;
while (!leave_loop) {
struct timeval timeout, *timeout_p = NULL;
if (!list_empty(&event_timeout_list)) {
struct timeval now;
@@ -247,6 +254,7 @@ int event_loop(void)

fd_set *readfds = NULL, *writefds = NULL;
struct event_fd *entry, *tmp;
int maxfd = -1;

list_for_each_entry_safe(entry, tmp, &event_fd_list, list) {
entry->flags &= ~EVENT_NEW;
@@ -272,9 +280,11 @@ int event_loop(void)
}
FD_SET(entry->fd, writefds);
}

maxfd = (entry->fd > maxfd) ? entry->fd : maxfd;
}

int i = select(FD_SETSIZE, readfds, writefds, NULL, timeout_p);
int i = select(maxfd +1, readfds, writefds, NULL, timeout_p);
if (i <= 0) {
/* On error, -1 is returned, and errno is set
* appropriately; the sets and timeout become
@@ -295,4 +305,5 @@ int event_loop(void)
}
}
free(fdsets);
return 0;
}

+ 1
- 0
daemon/event.h View File

@@ -37,6 +37,7 @@ struct event_timeout * event_add_timeout(

void event_remove_timeout(struct event_timeout *entry);

void event_loop_break(void);
int event_loop(void);

#endif /* _EVENT_H_ */

+ 7
- 2
daemon/logging.c View File

@@ -77,11 +77,15 @@ int log_print(int prio, const char *fmt, ...)

void log_close(void)
{
if (buffer)
if (buffer) {
free(buffer);
buffer = NULL;
}

if (log_fd)
if (log_fd) {
fclose(log_fd);
log_fd = NULL;
}
}

int log_init(const char *logfile)
@@ -100,6 +104,7 @@ int log_init(const char *logfile)
return -1;
}

log_prio = LOG_EVERYTIME;
return 0;
}


Loading…
Cancel
Save