// File: /workspace/github_c_makefile_star2_O2/sszllzss[P]webSocket_Libevent_ThreadPool/ev_httpd.cpp
// Function: bufferev_event_cb(bufferevent*, short, void*)
static void bufferev_event_cb(struct bufferevent *bev, short events,void *ctx)
{
    httpChilent_t *client = (httpChilent_t *)ctx;
    struct sockaddr_in *address = NULL; 
    char ip[INET_ADDRSTRLEN];
    BufferevMap::iterator i;
    do
    {
        if(client == NULL)
        {
            De_printf("httpChilent NULL\r\n");
            break;
        }
        pthread_mutex_lock(&client->lock);
        address = (struct sockaddr_in *)&(client->addr);
        if(address != NULL)
        {
            inet_ntop(AF_INET, &address->sin_addr,ip, INET_ADDRSTRLEN);
        }
        if(events & BEV_EVENT_ERROR)
        {
            if(address != NULL)
                De_printf("%s:%d[ Error from bufferevnt:%s\r\n", inet_ntop(AF_INET,&address->sin_addr, ip,(socklen_t) sizeof(ip)), ntohs(address->sin_port), strerror(errno));  
            else
                De_printf("Unknown[ Error from bufferevnt:%s\r\n",strerror(errno));
        }
        else if(events & (BEV_EVENT_EOF))
        {
            if(address != NULL)
                De_printf("Connection close:%s:%d\r\n", inet_ntop(AF_INET,&address->sin_addr, ip,(socklen_t) sizeof(ip)), ntohs(address->sin_port));  
            else
                De_printf("Connection close: Unknown\r\n");
        }
        pthread_mutex_unlock(&client->lock);
    }
    while(0);
    bufferevent_lock(bev);
    bufferevent_disable(bev, EV_WRITE | EV_READ);
    if(client != NULL)
    {
        if(client->stat == HTTP_WS_DATA && client->ws_weite_cb_flage)
        {
            WebddSocket_Thread_Cb_arg_t * cb_arg = (WebddSocket_Thread_Cb_arg_t *)malloc(sizeof(WebddSocket_Thread_Cb_arg_t));
            cb_arg->client = client;
            cb_arg->type = Ws_Cb_Type_disconnect;
            threadpool_add(evbase_threadpool_get_threadpool(client->httpServer->evb_thpool), webSocke_thread_cb, cb_arg);
        }
        pthread_mutex_lock(&client->lock);
        evbase_threadpool_close_event(client->httpServer->evb_thpool, bufferevent_get_base(bev));
        pthread_mutex_lock(&client->httpServer->clientMap_lock);
        client->httpServer->clientMap->erase(bev);
        pthread_mutex_unlock(&client->httpServer->clientMap_lock);

        pthread_mutex_unlock(&client->lock);
        httpChilent_free(client);
    }
    //close(bufferevent_getfd(bev));
    bufferevent_lock(bev);
    bufferevent_free(bev);
    /* bufferevent_unlock(bev); */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x28, %rsp
movq %rdx, %rbx
movq %rdi, %r14
movq %rdi, 0x8(%rsp)
testq %rdx, %rdx
je 0x6847
movl %esi, %ebp
movq %rbx, %rdi
callq 0x3650
leaq 0xa8(%rbx), %r15
pushq $0x2
popq %rdi
leaq 0x10(%rsp), %rdx
pushq $0x10
popq %rcx
movq %r15, %rsi
callq 0x34a0
movzwl %bp, %eax
testb $0x20, %al
jne 0x6882
testb $0x10, %al
je 0x68f5
leaq 0x39b5(%rip), %rdi      # 0xa1ab
leaq 0x540e(%rip), %rsi      # 0xbc0b
leaq 0x52da(%rip), %rdx      # 0xbade
movl $0x3be, %ecx            # imm = 0x3BE
xorl %eax, %eax
callq 0x3080
pushq $0x2
popq %rdi
leaq 0x10(%rsp), %rdx
pushq $0x10
popq %rcx
movq %r15, %rsi
callq 0x34a0
movzwl 0xa6(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
leaq 0x52e1(%rip), %rdi      # 0xbb19
movq %rax, %rsi
xorl %eax, %eax
callq 0x3080
jmp 0x68e9
leaq 0x395d(%rip), %rdi      # 0xa1ab
leaq 0x53b6(%rip), %rsi      # 0xbc0b
leaq 0x5282(%rip), %rdx      # 0xbade
movl $0x3ab, %ecx            # imm = 0x3AB
xorl %eax, %eax
callq 0x3080
leaq 0x5501(%rip), %rdi      # 0xbd70
callq 0x36b0
leaq 0x3c63(%rip), %rdi      # 0xa4de
callq 0x36b0
jmp 0x68fd
leaq 0x3922(%rip), %rdi      # 0xa1ab
leaq 0x537b(%rip), %rsi      # 0xbc0b
leaq 0x5247(%rip), %rdx      # 0xbade
movl $0x3b7, %ecx            # imm = 0x3B7
xorl %eax, %eax
callq 0x3080
pushq $0x2
popq %rdi
leaq 0x10(%rsp), %rdx
pushq $0x10
popq %rcx
movq %r15, %rsi
callq 0x34a0
movq %rax, %r15
movzwl 0xa6(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %ebp
callq 0x3070
movl (%rax), %edi
callq 0x3170
leaq 0x5343(%rip), %rdi      # 0xbc1d
movq %r15, %rsi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3080
leaq 0x3bee(%rip), %rdi      # 0xa4de
callq 0x36b0
movq %rbx, %rdi
callq 0x3320
movq %r14, %rdi
callq 0x3640
pushq $0x6
popq %rsi
movq %r14, %rdi
callq 0x3680
testq %rbx, %rbx
je 0x69c1
cmpl $0x5, 0x38(%rbx)
jne 0x695c
cmpb $0x0, 0xc8(%rbx)
je 0x695c
pushq $0x10
popq %rdi
callq 0x35d0
movq %rax, %r15
movq %rbx, (%rax)
movl $0x3, 0x8(%rax)
movq 0x28(%rbx), %rax
movq 0x60(%rax), %rdi
callq 0x7c78
leaq -0x109b(%rip), %rsi     # 0x58b6
movq %rax, %rdi
movq %r15, %rdx
callq 0x8979
movq %rbx, %rdi
callq 0x3650
movq 0x28(%rbx), %rax
movq 0x60(%rax), %r15
movq %r14, %rdi
callq 0x3760
movq %r15, %rdi
movq %rax, %rsi
callq 0x8088
movq 0x28(%rbx), %rdi
addq $0x28, %rdi
callq 0x3650
movq 0x28(%rbx), %rax
movq 0x50(%rax), %rdi
leaq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x7af0
movq 0x28(%rbx), %rdi
addq $0x28, %rdi
callq 0x3320
movq %rbx, %rdi
callq 0x3320
movq %rbx, %rdi
callq 0x6745
movq (%r14), %r14
movq %r14, %rdi
callq 0x3640
movq 0x8(%rsp), %rdi
callq 0x3140
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq