Esempio n. 1
0
int32_t _del_session( struct session * self )
{
    // 销毁网络事件
    if ( self->evread )
    {
        event_destroy( self->evread );
        self->evread = NULL;
    }
    if ( self->evwrite )
    {
        event_destroy( self->evwrite );
        self->evwrite = NULL;
    }
    if ( self->evkeepalive )
    {
        event_destroy( self->evkeepalive );
        self->evkeepalive = NULL;
    }

    QUEUE_CLEAR(sendqueue)(&self->sendqueue);
    buffer_clear( &self->inbuffer );
    free( self );

    return 0;
}
Esempio n. 2
0
void * iothread_main( void * arg )
{
    uint32_t maxtasks = 0;

    struct iothread * thread = (struct iothread *)arg;
    struct iothreads * parent = (struct iothreads *)(thread->parent);

    sigset_t mask;
    sigfillset(&mask);
    pthread_sigmask(SIG_SETMASK, &mask, NULL);

    // 初始化队列
    struct taskqueue doqueue;
    QUEUE_INIT(taskqueue)( &doqueue, MSGQUEUE_DEFAULT_SIZE );

    for ( ; parent->runflags; )
    {
        uint32_t nprocess = 0;

        // 轮询网络事件
        evsets_dispatch( thread->sets );

        // 处理事件
        nprocess = _process( parent, thread, &doqueue );

        // 最大任务数
        maxtasks = MAX( maxtasks, nprocess );
    }

    // 清理队列中剩余数据
    _process( parent, thread, &doqueue );
    // 清空队列
    QUEUE_CLEAR(taskqueue)( &doqueue );

    // 日志
    syslog( LOG_INFO, "%s(INDEX=%d) : the Maximum Number of Requests is %d in EachFrame .",
            __FUNCTION__, thread->index, maxtasks );

    // 向主线程发送终止信号
    pthread_mutex_lock( &parent->lock );
    --parent->nrunthreads;
    pthread_cond_signal( &parent->cond );
    pthread_mutex_unlock( &parent->lock );

    return NULL;
}
Esempio n. 3
0
int32_t msgqueue_destroy( struct msgqueue * self )
{
    if ( self->popfd )
    {
        close( self->popfd );
        self->popfd = -1;
    }
    if ( self->pushfd )
    {
        close( self->pushfd );
        self->pushfd = -1;
    }

    QUEUE_CLEAR(taskqueue)(&self->queue);
    pthread_mutex_destroy( &self->lock );
    free( self );

    return 0;
}