// File: /workspace/github_c_makefile_star2_O2/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
pushq $0x2
popq %rdi
movq %rsp, %rdx
pushq $0x10
popq %rcx
callq 0x34a0
movq 0x60(%r14), %rdi
callq 0x7f54
testq %rax, %rax
je 0x70d6
pushq $0x1
popq %rdx
movq %rax, %rdi
movl %ebp, %esi
callq 0x3730
testq %rax, %rax
je 0x711c
movq %rax, %r12
pushq $0x1
popq %rdi
movl $0xd0, %esi
callq 0x32c0
testq %rax, %rax
je 0x7183
movq %rax, %r15
movq (%rbx), %rax
movq %rax, 0xa4(%r15)
movb $0x1, 0xc8(%r15)
movq %r12, 0x30(%r15)
movq %r14, 0x28(%r15)
movq %r15, %rdi
addq $0xb8, %rdi
xorl %esi, %esi
callq 0x36c0
testl %eax, %eax
jne 0x71c9
movl $0x1, 0x38(%r15)
movq %r15, %rdi
xorl %esi, %esi
callq 0x3660
testl %eax, %eax
jne 0x720f
callq 0x3060
movq %rax, 0x98(%r15)
testq %rax, %rax
je 0x7272
movq %rax, %rdi
xorl %esi, %esi
callq 0x3580
leaq 0x2ee(%rip), %rsi       # 0x7329
leaq 0x341(%rip), %rdx       # 0x7383
leaq -0x8af(%rip), %rcx      # 0x679a
movq %r12, %rdi
movq %r15, %r8
callq 0x3460
leaq 0x28(%r14), %r13
movq %r13, %rdi
callq 0x3650
movq 0x50(%r14), %rdi
leaq 0x18(%rsp), %rsi
movq %r12, (%rsi)
movq %r15, 0x8(%rsi)
callq 0x75a6
movq %r13, %rdi
callq 0x3320
pushq $0x6
popq %rsi
movq %r12, %rdi
callq 0x37c0
leaq 0x311c(%rip), %rdi      # 0xa1ab
leaq 0x4ba9(%rip), %rsi      # 0xbc3f
leaq 0x4a41(%rip), %rdx      # 0xbade
movl $0x451, %ecx            # imm = 0x451
xorl %eax, %eax
callq 0x3080
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %edx
leaq 0x4c3e(%rip), %rdi      # 0xbcf9
movq %rsp, %rsi
xorl %eax, %eax
callq 0x3080
leaq 0x3412(%rip), %rdi      # 0xa4de
callq 0x36b0
jmp 0x72d2
movq 0x8efb(%rip), %r14      # 0xffd8
movq (%r14), %rdi
leaq 0x30c4(%rip), %rsi      # 0xa1ab
leaq 0x4b51(%rip), %rdx      # 0xbc3f
leaq 0x49e9(%rip), %rcx      # 0xbade
movl $0x41d, %r8d            # imm = 0x41D
xorl %eax, %eax
callq 0x3610
movq (%r14), %rdi
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
leaq 0x4b34(%rip), %rsi      # 0xbc4b
jmp 0x72b3
movq 0x8eb5(%rip), %r15      # 0xffd8
movq (%r15), %rdi
leaq 0x307e(%rip), %rsi      # 0xa1ab
leaq 0x4b0b(%rip), %rdx      # 0xbc3f
leaq 0x49a3(%rip), %rcx      # 0xbade
movl $0x424, %r8d            # imm = 0x424
xorl %eax, %eax
callq 0x3610
movq (%r15), %r14
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %ebx
callq 0x3070
movl (%rax), %edi
callq 0x3170
leaq 0x4afa(%rip), %rsi      # 0xbc63
movq %rsp, %rdx
movq %r14, %rdi
movl %ebx, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x3610
movq (%r15), %rcx
jmp 0x72c0
movq 0x8e4e(%rip), %r14      # 0xffd8
movq (%r14), %rdi
leaq 0x3017(%rip), %rsi      # 0xa1ab
leaq 0x4aa4(%rip), %rdx      # 0xbc3f
leaq 0x493c(%rip), %rcx      # 0xbade
movl $0x42c, %r8d            # imm = 0x42C
xorl %eax, %eax
callq 0x3610
movq (%r14), %rdi
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
leaq 0x4ac1(%rip), %rsi      # 0xbc85
jmp 0x72b3
movq 0x8e08(%rip), %r14      # 0xffd8
movq (%r14), %rdi
leaq 0x2fd1(%rip), %rsi      # 0xa1ab
leaq 0x4a5e(%rip), %rdx      # 0xbc3f
leaq 0x48f6(%rip), %rcx      # 0xbade
movl $0x438, %r8d            # imm = 0x438
xorl %eax, %eax
callq 0x3610
movq (%r14), %rdi
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
leaq 0x4a9d(%rip), %rsi      # 0xbca7
jmp 0x72b3
movq 0x8dc2(%rip), %r14      # 0xffd8
movq (%r14), %rdi
leaq 0x2f8b(%rip), %rsi      # 0xa1ab
leaq 0x4a18(%rip), %rdx      # 0xbc3f
leaq 0x48b0(%rip), %rcx      # 0xbade
movl $0x43e, %r8d            # imm = 0x43E
xorl %eax, %eax
callq 0x3610
movq (%r14), %rcx
leaq 0x4a7e(%rip), %rdi      # 0xbcc3
pushq $0x19
popq %rsi
pushq $0x1
popq %rbx
movq %rbx, %rdx
callq 0x3800
movq (%r14), %rcx
leaq 0x4a47(%rip), %rdi      # 0xbca4
pushq $0x2
popq %rsi
movq %rbx, %rdx
callq 0x3800
movq %r15, %rdi
callq 0x6745
jmp 0x72d2
movq 0x8d5f(%rip), %r14      # 0xffd8
movq (%r14), %rdi
leaq 0x2f28(%rip), %rsi      # 0xa1ab
leaq 0x49b5(%rip), %rdx      # 0xbc3f
leaq 0x484d(%rip), %rcx      # 0xbade
movl $0x446, %r8d            # imm = 0x446
xorl %eax, %eax
callq 0x3610
movq (%r14), %rdi
movzwl 0x2(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %ecx
leaq 0x4a2a(%rip), %rsi      # 0xbcdd
movq %rsp, %rdx
xorl %eax, %eax
callq 0x3610
movq (%r14), %rcx
leaq 0x49dd(%rip), %rdi      # 0xbca4
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
callq 0x3800
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq