Ignore:
Timestamp:
Jul 8, 2006 7:46:43 PM (18 years ago)
Author:
bennylp
Message:

Attempted to fix epoll for Linux

File:
1 edited

Legend:

Unmodified
Added
Removed
  • pjproject/trunk/pjlib/src/pj/ioqueue_epoll.c

    r590 r592  
    142142#define THIS_FILE   "ioq_epoll" 
    143143 
    144 #define TRACE_(expr) PJ_LOG(3,expr) 
    145 //#define TRACE_(expr) 
     144//#define TRACE_(expr) PJ_LOG(3,expr) 
     145#define TRACE_(expr) 
    146146 
    147147/* 
     
    156156{ 
    157157    DECLARE_COMMON_KEY 
     158}; 
     159 
     160struct queue 
     161{ 
     162    pj_ioqueue_key_t        *key; 
     163    enum ioqueue_event_type  event_type; 
    158164}; 
    159165 
     
    168174    pj_ioqueue_key_t    hlist; 
    169175    int                 epfd; 
     176    struct epoll_event *events; 
     177    struct queue       *queue; 
    170178}; 
    171179 
     
    230238    } 
    231239     
     240    ioqueue->events = pj_pool_calloc(pool, max_fd, sizeof(struct epoll_event)); 
     241    PJ_ASSERT_RETURN(ioqueue->events != NULL, PJ_ENOMEM); 
     242 
     243    ioqueue->queue = pj_pool_calloc(pool, max_fd, sizeof(struct queue)); 
     244    PJ_ASSERT_RETURN(ioqueue->queue != NULL, PJ_ENOMEM); 
     245 
    232246    PJ_LOG(4, ("pjlib", "epoll I/O Queue created (%p)", ioqueue)); 
    233247 
     
    306320 
    307321    /* os_epoll_ctl. */ 
    308     ev.events = EPOLLIN | EPOLLOUT | EPOLLERR; 
     322    ev.events = EPOLLIN | EPOLLERR; 
    309323    ev.epoll_data = (epoll_data_type)key; 
    310324    status = os_epoll_ctl(ioqueue->epfd, EPOLL_CTL_ADD, sock, &ev); 
     
    323337    ++ioqueue->count; 
    324338 
     339    //TRACE_((THIS_FILE, "socket registered, count=%d", ioqueue->count)); 
     340 
    325341on_return: 
    326342    *p_key = key; 
     
    374390 */ 
    375391static void ioqueue_remove_from_set( pj_ioqueue_t *ioqueue, 
    376                                      pj_sock_t fd,  
     392                                     pj_ioqueue_key_t *key,  
    377393                                     enum ioqueue_event_type event_type) 
    378394{ 
     395    if (event_type == WRITEABLE_EVENT) { 
     396        struct epoll_event ev; 
     397 
     398        ev.events = EPOLLIN | EPOLLERR; 
     399        ev.epoll_data = (epoll_data_type)key; 
     400        os_epoll_ctl( ioqueue->epfd, EPOLL_CTL_MOD, key->fd, &ev); 
     401    }    
    379402} 
    380403 
     
    386409 */ 
    387410static void ioqueue_add_to_set( pj_ioqueue_t *ioqueue, 
    388                                 pj_sock_t fd, 
     411                                pj_ioqueue_key_t *key, 
    389412                                enum ioqueue_event_type event_type ) 
    390413{ 
     414    if (event_type == WRITEABLE_EVENT) { 
     415        struct epoll_event ev; 
     416 
     417        ev.events = EPOLLIN | EPOLLOUT | EPOLLERR; 
     418        ev.epoll_data = (epoll_data_type)key; 
     419        os_epoll_ctl( ioqueue->epfd, EPOLL_CTL_MOD, key->fd, &ev); 
     420    }    
    391421} 
    392422 
     
    398428{ 
    399429    int i, count, processed; 
    400     struct epoll_event events[PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL]; 
    401430    int msec; 
    402     struct queue { 
    403         pj_ioqueue_key_t        *key; 
    404         enum ioqueue_event_type  event_type; 
    405     } queue[PJ_IOQUEUE_MAX_EVENTS_IN_SINGLE_POLL]; 
     431    struct epoll_event *events = ioqueue->events; 
     432    struct queue *queue = ioqueue->queue; 
     433    pj_timestamp t1, t2; 
    406434     
    407435    PJ_CHECK_STACK(); 
    408436 
    409437    msec = timeout ? PJ_TIME_VAL_MSEC(*timeout) : 9000; 
    410      
    411     count = os_epoll_wait( ioqueue->epfd, events, PJ_ARRAY_SIZE(events), msec); 
    412     if (count == 0) 
     438 
     439    TRACE_((THIS_FILE, "start os_epoll_wait, msec=%d", msec)); 
     440    pj_get_timestamp(&t1); 
     441  
     442    count = os_epoll_wait( ioqueue->epfd, events, ioqueue->max, msec); 
     443    if (count == 0) { 
     444        TRACE_((THIS_FILE, "os_epoll_wait timed out")); 
    413445        return count; 
    414     else if (count < 0) 
     446    } 
     447    else if (count < 0) { 
     448        TRACE_((THIS_FILE, "os_epoll_wait error")); 
    415449        return -pj_get_netos_error(); 
     450    } 
     451 
     452    pj_get_timestamp(&t2); 
     453    TRACE_((THIS_FILE, "os_epoll_wait returns %d, time=%d usec", 
     454                       count, pj_elapsed_usec(&t1, &t2))); 
    416455 
    417456    /* Lock ioqueue. */ 
     
    421460        pj_ioqueue_key_t *h = (pj_ioqueue_key_t*)(epoll_data_type) 
    422461                                events[i].epoll_data; 
     462 
     463        TRACE_((THIS_FILE, "event %d: events=%d", i, events[i].events)); 
    423464 
    424465        /* 
     
    487528        pj_thread_sleep(msec); 
    488529    } 
     530 
     531    pj_get_timestamp(&t1); 
     532    TRACE_((THIS_FILE, "ioqueue_poll() returns %d, time=%d usec", 
     533                       processed, pj_elapsed_usec(&t2, &t1))); 
     534 
    489535    return processed; 
    490536} 
Note: See TracChangeset for help on using the changeset viewer.