Changeset 5842

Show
Ignore:
Timestamp:
03/17/10 15:12:44 (3 years ago)
Author:
blogic
Message:

uloop update

Location:
luci2/libubox
Files:
1 added
2 modified

Legend:

Unmodified
Added
Removed
  • luci2/libubox/Makefile

    r5840 r5842  
    99 
    1010libubox.so: ucix.c blob.c hash.c uhtbl.c ulog.c 
    11     $(CC) $(CFLAGS) -o $@ -shared -Wl,-soname,libubox.so $^ -luci 
     11    $(CC) $(CFLAGS) -g -o $@ -shared -Wl,-soname,libubox.so $^ -luci 
    1212 
    1313libuloop.so: uloop.c 
    14     $(CC) $(CFLAGS) -o $@ -shared -Wl,-soname,libuloop.so $^ -lubus -I../ubus/ -I./ 
     14    $(CC) $(CFLAGS) -g -o $@ -shared -Wl,-soname,libuloop.so $^ -lubus -I../ubus/ -I./ 
    1515 
    1616clean: 
  • luci2/libubox/uloop.c

    r5840 r5842  
    2525#include <poll.h> 
    2626#include <string.h> 
     27#include <time.h> 
    2728#include <fcntl.h> 
    2829#include <signal.h> 
     
    3233 
    3334#include <libubus.h> 
     35#include "uloop.h" 
    3436#include "ulog.h" 
    35  
    36 struct uloop_sock; 
    37 typedef void (*_uloop_sock_handler)(struct uloop_sock *u); 
    3837 
    3938struct uloop_sock 
     
    6867    ev.events = EPOLLIN | EPOLLET | EPOLLRDHUP; 
    6968    ev.data.fd = sock; 
     69    ev.data.ptr = u; 
    7070    epoll_ctl(epoll_fd, EPOLL_CTL_ADD, sock, &ev); 
    7171    return u; 
     
    7474void uloop_ubus_add(struct ubus_ctx *ctx) 
    7575{ 
    76     int s = ubus_get_sock(ctx); 
    7776    if(!uloop_ubus) 
    7877        uloop_ubus = ctx; 
    79     if(s) 
    80         uloop_sock_add(s, ctx, uloop_ubus_cb); 
    8178} 
    8279 
     
    107104} 
    108105 
    109 int uloop(void) 
     106int uloop(void (*cb)(void), int timeout) 
    110107{ 
    111108    #define MAX_EVENTS  10 
    112109    struct epoll_event events[MAX_EVENTS]; 
    113110    int nfds, n; 
     111    time_t t = time(0); 
    114112    uloop_loop = 1; 
    115113    uloop_setup_signals(); 
     
    127125                epoll_ctl(epoll_fd, EPOLL_CTL_DEL, u->sock, 0); 
    128126                uloop_sock_delete(u); 
    129             } else { 
    130                 u->cb(u); 
     127            } else if(events[n].events & EPOLLIN) 
     128            { 
     129                if(u->cb) 
     130                    u->cb(u); 
    131131            } 
     132        } 
     133        if(cb) 
     134        { 
     135            if(difftime(time(0), t) < timeout) 
     136                continue; 
     137            t = time(0); 
     138            cb(); 
    132139        } 
    133140    }