// File: /workspace/github_c_makefile_star2_O3/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 0x74f4
movl %esi, %ebp
movq %rbx, %rdi
callq 0x3620
leaq 0xa8(%rbx), %r15
leaq 0x10(%rsp), %rdx
movl $0x2, %edi
movq %r15, %rsi
movl $0x10, %ecx
callq 0x3480
movzwl %bp, %eax
testb $0x20, %al
jne 0x752f
testb $0x10, %al
je 0x75a6
leaq 0x3d0c(%rip), %rdi      # 0xb1ab
leaq 0x5765(%rip), %rsi      # 0xcc0b
leaq 0x5631(%rip), %rdx      # 0xcade
movl $0x3be, %ecx            # imm = 0x3BE
xorl %eax, %eax
callq 0x3080
leaq 0x10(%rsp), %rdx
movl $0x2, %edi
movq %r15, %rsi
movl $0x10, %ecx
callq 0x3480
movzwl 0xa6(%rbx), %ecx
rolw $0x8, %cx
movzwl %cx, %edx
leaq 0x5634(%rip), %rdi      # 0xcb19
movq %rax, %rsi
xorl %eax, %eax
callq 0x3080
jmp 0x759a
leaq 0x3cb0(%rip), %rdi      # 0xb1ab
leaq 0x5709(%rip), %rsi      # 0xcc0b
leaq 0x55d5(%rip), %rdx      # 0xcade
movl $0x3ab, %ecx            # imm = 0x3AB
xorl %eax, %eax
callq 0x3080
leaq 0x5854(%rip), %rdi      # 0xcd70
callq 0x3680
leaq 0x3fb6(%rip), %rdi      # 0xb4de
callq 0x3680
jmp 0x75ae
leaq 0x3c75(%rip), %rdi      # 0xb1ab
leaq 0x56ce(%rip), %rsi      # 0xcc0b
leaq 0x559a(%rip), %rdx      # 0xcade
movl $0x3b7, %ecx            # imm = 0x3B7
xorl %eax, %eax
callq 0x3080
leaq 0x10(%rsp), %rdx
movl $0x2, %edi
movq %r15, %rsi
movl $0x10, %ecx
callq 0x3480
movq %rax, %r15
movzwl 0xa6(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %ebp
callq 0x3070
movl (%rax), %edi
callq 0x3170
leaq 0x5692(%rip), %rdi      # 0xcc1d
movq %r15, %rsi
movl %ebp, %edx
movq %rax, %rcx
xorl %eax, %eax
callq 0x3080
leaq 0x3f3d(%rip), %rdi      # 0xb4de
callq 0x3680
movq %rbx, %rdi
callq 0x3310
movq %r14, %rdi
callq 0x3610
movq %r14, %rdi
movl $0x6, %esi
callq 0x3650
testq %rbx, %rbx
je 0x7684
cmpl $0x5, 0x38(%rbx)
jne 0x7611
cmpb $0x0, 0xc8(%rbx)
je 0x7611
movl $0x10, %edi
callq 0x35a0
movq %rax, %r15
movq %rbx, (%rax)
movl $0x3, 0x8(%rax)
movq 0x28(%rbx), %rax
movq 0x60(%rax), %rdi
callq 0x855c
leaq -0x123b(%rip), %rsi     # 0x63cb
movq %rax, %rdi
movq %r15, %rdx
callq 0x9179
movq %rbx, %rdi
callq 0x3620
movq 0x28(%rbx), %rax
movq 0x60(%rax), %r15
movq %r14, %rdi
callq 0x3730
movq %r15, %rdi
movq %rax, %rsi
callq 0x89ed
movq 0x28(%rbx), %rdi
addq $0x28, %rdi
callq 0x3620
movq 0x28(%rbx), %rax
movq 0x50(%rax), %r14
leaq 0x8(%rsp), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x8434
movq %r14, %rdi
movq %rax, %rsi
callq 0x84b6
movq 0x28(%rbx), %rdi
addq $0x28, %rdi
callq 0x3310
movq %rbx, %rdi
callq 0x3310
movq %rbx, %rdi
callq 0x73e8
movq (%r15), %r14
movq %r14, %rdi
callq 0x3610
movq 0x8(%rsp), %rdi
callq 0x3140
addq $0x28, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq