worker.h
// the fd_deq logic in worker thread
the fd_deq logic in worker thread
the fd_deq logic in worker thread
static inline int worker_deq(int ctl_fd, struct fd_queue* fd_queue)
{
    int status;
    pthread_t tid;
    int fd;
    struct http_client* data;
    while (1)
    {
        fd = fd_deq(fd_queue);
        if (fd == -1) {
            return 0;
        }
#if defined __linux__
        LOG(INFO, "file desciptor %d in tid=%ld\n", fd, tid);
#elif defined __APPLE__ && __MACH__
        LOG(INFO, "file desciptor %d in tid=%p\n", fd, &tid->__opaque);
#endif
        data = new_http_client(ctl_fd, fd);
        if (data == NULL) {
            LOG(WARN, "new_http_client error\n");
            close(fd);
        } else {
#if defined __linux__
            struct epoll_event event;
            event.events = EPOLLIN | EPOLLET;
            event.data.ptr = (void*) data;
            status = epoll_ctl(ctl_fd, EPOLL_CTL_ADD, fd, &event);
            if (status == -1) {
                LOG(WARN, "epoll: conn_sock error\n");
                sock_close(data);
            }
#elif defined __APPLE__ && __MACH__
            struct kevent event;
            EV_SET(&event, fd, EVFILT_READ, EV_ADD, 0, 0, (void*) data);
            status = kevent(ctl_fd, &event, 1, NULL, 0, NULL);
            if (status == -1) {
                LOG(WARN, "kevent: conn_sock error\n");
                sock_close(data);
            }
#endif
        }
    } 
    return -1; 
}
static inline int worker_deq ( int ctl_fd , struct fd_queue * fd_queue ) { int status ; pthread_t tid ; int fd ; struct http_client * data ; while ( 1 ) { fd = fd_deq ( fd_queue ) ; if ( fd == -1 ) { return 0 ; } #if defined __linux__ LOG ( INFO , " \n " , fd , tid ) ; #elif defined __APPLE__ && __MACH__ LOG ( INFO , " \n " , fd , & tid -> __opaque ) ; #endif data = new_http_client ( ctl_fd , fd ) ; if ( data == NULL ) { LOG ( WARN , " \n " ) ; close ( fd ) ; } else { #if defined __linux__ struct epoll_event event ; event . events = EPOLLIN | EPOLLET ; event . data . ptr = ( void * ) data ; status = epoll_ctl ( ctl_fd , EPOLL_CTL_ADD , fd , & event ) ; if ( status == -1 ) { LOG ( WARN , " \n " ) ; sock_close ( data ) ; } #elif defined __APPLE__ && __MACH__ struct kevent event ; EV_SET ( & event , fd , EVFILT_READ , EV_ADD , 0 , 0 , ( void * ) data ) ; status = kevent ( ctl_fd , & event , 1 , NULL , 0 , NULL ) ; if ( status == -1 ) { LOG ( WARN , " \n " ) ; sock_close ( data ) ; } #endif } } return -1 ; }
the fd_deq logic in worker thread
the fd_deq logic in worker thread
// new a http_client for the fd // Listen on the new socket // End of fd_queue dequeue // strange state