// File: /workspace/github_c_makefile_star2_O3/sszllzss[P]webSocket_Libevent_ThreadPool/ev_httpd.cpp
// Function: listener_cd(evconnlistener*, int, sockaddr*, int, void*)
static void listener_cd(struct evconnlistener *listener, evutil_socket_t fd, struct sockaddr *sa, int socklen, void *arg)
{
    httpServer_t *httpServer=(httpServer_t *)arg;
    listener = (struct evconnlistener *)listener;
    struct httpChilent_t *client;
    char ip[INET_ADDRSTRLEN];
    struct sockaddr_in * addr = (struct sockaddr_in *)sa;
    inet_ntop(AF_INET, &addr->sin_addr, ip, INET_ADDRSTRLEN);

    event_base *base = evbase_threadpool_add_event(httpServer->evb_thpool);
    if(base == NULL)
    {
        De_fprintf(stderr, "%s:%d[ base get fall!\r\n",ip, ntohs(addr->sin_port));
        return;
    }

    struct bufferevent *bev = bufferevent_socket_new(base, fd, BEV_OPT_CLOSE_ON_FREE);
    if(bev == NULL)
    {
        De_fprintf(stderr, "%s:%d[ bufferevent new error:%s\r\n",ip, ntohs(addr->sin_port), evutil_socket_error_to_string(EVUTIL_SOCKET_ERROR()));
        return;
    }


    client = (struct httpChilent_t *) malloc(sizeof(struct httpChilent_t));
    if(client == NULL)
    {
        De_fprintf(stderr, "%s:%d[ httpChilent malloc fail!\r\n",ip, ntohs(addr->sin_port));
        return;
    }
    memset(client, 0, sizeof(struct httpChilent_t));

    memcpy(&client->addr, sa, sizeof(sizeof(struct sockaddr_in)));
    client->ws_weite_cb_flage = 1;
    client->bev = bev;
    client->httpServer = httpServer;

    if(gettimeofday(&client->final_optime, NULL) != 0)
    {
        De_fprintf(stderr, "%s:%d[ gettimeofday fail!\r\n",ip, ntohs(addr->sin_port));
        return;
    }
    client->stat = HTTP_CONNECTED;
    if(pthread_mutex_init(&client->lock, NULL)!=0)
    {
        De_fprintf(stderr, "client->lock init fail!\r\n");
        httpChilent_free(client);
        return;
    }

    client->receive_evbuff = evbuffer_new();
    if(client->receive_evbuff == NULL)
    {
        De_fprintf(stderr, "%s:%d[ evbuffer_new fail!\r\n",ip, ntohs(addr->sin_port));
        return;
    }
    evbuffer_enable_locking(client->receive_evbuff, NULL);

    bufferevent_setcb(bev, bufferev_read_cb, bufferev_write_cb, bufferev_event_cb, client);
    pthread_mutex_lock(&httpServer->clientMap_lock);
    httpServer->clientMap->insert(std::pair<struct bufferevent *, httpChilent_t *>(bev ,client));
    pthread_mutex_unlock(&httpServer->clientMap_lock);

    bufferevent_enable(bev, EV_READ| EV_WRITE);
    De_printf("client connection:%s:%d\r\n",ip, ntohs(addr->sin_port));
    socklen = (int)socklen;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r14
movq %rdx, %rbx
movl %esi, %ebp
leaq 0x4(%rdx), %rsi
movq %rsp, %rdx
movl $0x2, %edi
movl $0x10, %ecx
callq 0x3480
movq 0x60(%r14), %rdi
callq 0x888e
testq %rax, %rax
je 0x7c19
movq %rax, %rdi
movl %ebp, %esi
movl $0x1, %edx
callq 0x3700
testq %rax, %rax
je 0x7c26
movq %rax, %r15
movl $0x1, %edi
movl $0xd0, %esi
callq 0x32b0
testq %rax, %rax
je 0x7c33
movq %rax, %r12
movq (%rbx), %rax
movq %rax, 0xa4(%r12)
movb $0x1, 0xc8(%r12)
movq %r15, 0x30(%r12)
movq %r14, 0x28(%r12)
movq %r12, %rdi
addq $0xb8, %rdi
xorl %esi, %esi
callq 0x3690
testl %eax, %eax
jne 0x7c40
movl $0x1, 0x38(%r12)
movq %r12, %rdi
xorl %esi, %esi
callq 0x3630
testl %eax, %eax
jne 0x7c4d
callq 0x3060
movq %rax, 0x98(%r12)
testq %rax, %rax
je 0x7c57
movq %rax, %rdi
xorl %esi, %esi
callq 0x3560
leaq 0xf2(%rip), %rsi        # 0x7c64
leaq 0x145(%rip), %rdx       # 0x7cbe
leaq -0x741(%rip), %rcx      # 0x743f
movq %r15, %rdi
movq %r12, %r8
callq 0x3450
leaq 0x28(%r14), %r13
movq %r13, %rdi
callq 0x3620
movq 0x50(%r14), %rdi
leaq 0x18(%rsp), %rsi
movq %r15, (%rsi)
movq %r12, 0x8(%rsi)
callq 0x7f60
movq %r13, %rdi
callq 0x3310
movq %r15, %rdi
movl $0x6, %esi
callq 0x3790
leaq 0x35e3(%rip), %rdi      # 0xb1ab
leaq 0x5070(%rip), %rsi      # 0xcc3f
leaq 0x4f08(%rip), %rdx      # 0xcade
movl $0x451, %ecx            # imm = 0x451
xorl %eax, %eax
callq 0x3080
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
leaq 0x5105(%rip), %rdi      # 0xccf9
movq %rsp, %rsi
xorl %eax, %eax
callq 0x3080
leaq 0x38d9(%rip), %rdi      # 0xb4de
callq 0x3680
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3ec8
jmp 0x7c0a
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3e39
jmp 0x7c0a
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3dc7
jmp 0x7c0a
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3c73
jmp 0x7c0a
movq %r12, %rdi
callq 0x3ce5
jmp 0x7c0a
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3d55
jmp 0x7c0a