// File: /workspace/github_c_makefile_star2_O1/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 0x890d
testq %rax, %rax
je 0x7c79
movq %rax, %rdi
movl %ebp, %esi
movl $0x1, %edx
callq 0x3700
testq %rax, %rax
je 0x7c86
movq %rax, %r15
movl $0xd0, %edi
callq 0x35a0
testq %rax, %rax
je 0x7c93
movq %rax, %r12
movl $0xd0, %edx
movq %rax, %rdi
xorl %esi, %esi
callq 0x3250
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 0x7ca0
movl $0x1, 0x38(%r12)
movq %r12, %rdi
xorl %esi, %esi
callq 0x3630
testl %eax, %eax
jne 0x7cad
callq 0x3060
movq %rax, 0x98(%r12)
testq %rax, %rax
je 0x7cb7
movq %rax, %rdi
xorl %esi, %esi
callq 0x3560
leaq 0xf2(%rip), %rsi        # 0x7cc4
leaq 0x145(%rip), %rdx       # 0x7d1e
leaq -0x759(%rip), %rcx      # 0x7487
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 0x7fc4
movq %r13, %rdi
callq 0x3310
movq %r15, %rdi
movl $0x6, %esi
callq 0x3790
leaq 0x3583(%rip), %rdi      # 0xb1ab
leaq 0x5013(%rip), %rsi      # 0xcc42
leaq 0x4eab(%rip), %rdx      # 0xcae1
movl $0x451, %ecx            # imm = 0x451
xorl %eax, %eax
callq 0x3080
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
leaq 0x50a8(%rip), %rdi      # 0xccfc
movq %rsp, %rsi
xorl %eax, %eax
callq 0x3080
leaq 0x3879(%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 0x3e18
jmp 0x7c6a
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3d89
jmp 0x7c6a
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3d17
jmp 0x7c6a
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3bc3
jmp 0x7c6a
movq %r12, %rdi
callq 0x3c35
jmp 0x7c6a
movq %rsp, %rsi
movq %rbx, %rdi
callq 0x3ca5
jmp 0x7c6a