// File: /workspace/github_c_makefile_star2_O0/sszllzss[P]webSocket_Libevent_ThreadPool/ev_httpd.cpp
// Function: httpd_handler_thread(void*)
void *httpd_handler_thread(void *arg)
{
    struct httpChilent_t *client = (struct httpChilent_t *)arg;
    struct httpServer_t *httpServer = client->httpServer;
    struct bufferevent * bev = client->bev;
    char respondKey[128];
    char c = 0;
    pthread_mutex_lock(&client->lock);
    gettimeofday(&client->final_optime, NULL);
    do
    {

        bufferevent_lock(bev);
        evbuffer_lock(client->receive_evbuff);
        bufferevent_disable(bev, EV_READ);
        while(1)
        {
            if(bufferevent_read(bev,&c,1) == 0 )
            {
                break;
            }
            evbuffer_add(client->receive_evbuff, &c , 1);
        }
        bufferevent_enable(bev, EV_READ);
        evbuffer_unlock(client->receive_evbuff);
        bufferevent_unlock(bev);


        pthread_mutex_unlock(&client->lock);
        int ret = accept_request(client);
        pthread_mutex_lock(&client->lock);
        if(ret != 0)
        {
            switch(ret)
            {
            case REQUEST_ERROR:
                client->resqonse.resqonseCode = HTTP_INTERNAL;
                break;
            case REQUEST_NOCONTENT:
                client->resqonse.resqonseCode = HTTP_NOCONTENT;
                break;
            case REQUEST_BADREQUEST:
                client->resqonse.resqonseCode = HTTP_BADREQUEST;
                break;
            case REQUEST_ENTITYTOOLARGE:
                client->resqonse.resqonseCode = HTTP_ENTITYTOOLARGE;
                break;
            case REQUEST_INTERNAL:
                client->resqonse.resqonseCode = HTTP_INTERNAL;
                break;
            case REQUEST_NOTIMPLEMENTED:
                client->resqonse.resqonseCode = HTTP_NOTIMPLEMENTED;
                break;
            default:
                client->resqonse.resqonseCode = HTTP_INTERNAL;
                break;
            }
            pthread_mutex_unlock(&client->lock);
            resqonse(client);
            pthread_mutex_lock(&client->lock);
            http_request_free(&client->request);
            http_request_free(&client->request);
            http_resqonse_free(&client->resqonse);
        }
        else
        {
            if(client->request.HeadParameter != NULL)
            {
                HeadParameterMap::iterator v = client->request.HeadParameter->find("Sec-WebSocket-Key");
                HeadParameterMap::iterator v1 = client->request.HeadParameter->find("Sec-WebSocket-Version");
                pthread_mutex_lock(&client->httpServer->lock);
                if(strcasecmp(client->request.method, "GET") == 0  && v1 != client->request.HeadParameter->end() && strcmp(v1->second.c_str(), "13") == 0  && v != client->request.HeadParameter->end() && strcmp(client->httpServer->webSocket_url, client->request.url) == 0)
                {
                    pthread_mutex_unlock(&client->httpServer->lock);
                    client->resqonse.resqonseCode = HTTP_SWITCHING_PROTOCOLS;
                    memset(respondKey, 0, sizeof(respondKey));
                    webSocket_buildRespondShakeKey((unsigned char *) v->second.c_str(), strlen(v->second.c_str()),( unsigned char *)respondKey);
                    client->resqonse.HeadParameter = new HeadParameterMap();
                    if(client->resqonse.HeadParameter == NULL)
                    {
                        client->resqonse.resqonseCode = HTTP_INTERNAL;
                        pthread_mutex_unlock(&client->lock);
                        resqonse(client);
                        pthread_mutex_lock(&client->lock);
                        http_request_free(&client->request);
                        http_resqonse_free(&client->resqonse);
                        break;
                    }
                    client->resqonse.HeadParameter->insert(HaedParameteMapPairi("Sec-WebSocket-Accept", respondKey));
                    pthread_mutex_unlock(&client->lock);
                    resqonse(client);
                    pthread_mutex_lock(&client->lock);
                    http_request_free(&client->request);
                    http_resqonse_free(&client->resqonse);
                    
                    break;
                }
                pthread_mutex_unlock(&client->httpServer->lock);
            }
            if(client->httpServer->handler != NULL)
            {
                httpd_handler_t handler;
                handler = client->httpServer->handler;
                client->resqonse.HeadParameter = new HeadParameterMap();
                pthread_mutex_unlock(&client->lock);
                handler(client);
                pthread_mutex_lock(&httpServer->clientMap_lock);
                BufferevMap::iterator v = httpServer->clientMap->find(bev);    
                if(httpServer->clientMap->end() == v)
                {
                    pthread_mutex_unlock(&httpServer->clientMap_lock);
                    return NULL;
                }
                pthread_mutex_unlock(&httpServer->clientMap_lock);
                pthread_mutex_lock(&client->lock);
                http_request_free(&client->request);
                http_resqonse_free(&client->resqonse);
            }
            else
            {
                //503错误
                client->resqonse.resqonseCode = HTTP_SERVUNAVAIL;
                pthread_mutex_unlock(&client->lock);
                resqonse(client);
                pthread_mutex_lock(&client->lock);
                http_request_free(&client->request);
                http_resqonse_free(&client->resqonse);

            }
        }
    }while(0);
    pthread_mutex_unlock(&client->lock);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x28(%rbp)
movb $0x0, -0xb1(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4720
movq -0x18(%rbp), %rdi
addq $0xb8, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x4780
movq -0x28(%rbp), %rdi
callq 0x4710
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rdi
callq 0x4350
movq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0x4750
movq -0x28(%rbp), %rdi
leaq -0xb1(%rbp), %rsi
movl $0x1, %edx
callq 0x4900
cmpq $0x0, %rax
jne 0x8927
jmp 0x8945
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rdi
leaq -0xb1(%rbp), %rsi
movl $0x1, %edx
callq 0x44d0
jmp 0x890a
movq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0x48b0
movq -0x18(%rbp), %rax
movq 0x98(%rax), %rdi
callq 0x48a0
movq -0x28(%rbp), %rdi
callq 0x47d0
movq -0x18(%rbp), %rdi
callq 0x4390
movq -0x18(%rbp), %rdi
callq 0x7d90
movl %eax, -0xb8(%rbp)
movq -0x18(%rbp), %rdi
callq 0x4720
cmpl $0x0, -0xb8(%rbp)
je 0x8a68
movl -0xb8(%rbp), %eax
addl $0x6, %eax
movl %eax, %ecx
movq %rcx, -0x1a8(%rbp)
subl $0x5, %eax
ja 0x8a16
movq -0x1a8(%rbp), %rax
leaq 0xbb61(%rip), %rcx      # 0x14520
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
movl $0x1f4, 0x78(%rax)      # imm = 0x1F4
jmp 0x8a21
movq -0x18(%rbp), %rax
movl $0xcc, 0x78(%rax)
jmp 0x8a21
movq -0x18(%rbp), %rax
movl $0x190, 0x78(%rax)      # imm = 0x190
jmp 0x8a21
movq -0x18(%rbp), %rax
movl $0x19d, 0x78(%rax)      # imm = 0x19D
jmp 0x8a21
movq -0x18(%rbp), %rax
movl $0x1f4, 0x78(%rax)      # imm = 0x1F4
jmp 0x8a21
movq -0x18(%rbp), %rax
movl $0x1f5, 0x78(%rax)      # imm = 0x1F5
jmp 0x8a21
movq -0x18(%rbp), %rax
movl $0x1f4, 0x78(%rax)      # imm = 0x1F4
movq -0x18(%rbp), %rdi
callq 0x4390
movq -0x18(%rbp), %rdi
callq 0x6c70
movq -0x18(%rbp), %rdi
callq 0x4720
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x87b0
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x87b0
movq -0x18(%rbp), %rdi
addq $0x78, %rdi
callq 0x90a0
jmp 0x906a
movq -0x18(%rbp), %rax
cmpq $0x0, 0x60(%rax)
je 0x8f0a
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x1b8(%rbp)
leaq -0xe1(%rbp), %rdi
movq %rdi, -0x1b0(%rbp)
callq 0x4850
movq -0x1b0(%rbp), %rdx
leaq 0xcfcb(%rip), %rsi      # 0x15a72
leaq -0xe0(%rbp), %rdi
callq 0xad80
jmp 0x8ab5
movq -0x1b8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0xad50
movq %rax, -0x1c0(%rbp)
jmp 0x8ad1
movq -0x1c0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x42f0
leaq -0xe1(%rbp), %rdi
callq 0x4560
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rax
movq %rax, -0x1d0(%rbp)
leaq -0x121(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x4850
movq -0x1c8(%rbp), %rdx
leaq 0xcf5d(%rip), %rsi      # 0x15a84
leaq -0x120(%rbp), %rdi
callq 0xad80
jmp 0x8b35
movq -0x1d0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0xad50
movq %rax, -0x1d8(%rbp)
jmp 0x8b51
movq -0x1d8(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x42f0
leaq -0x121(%rbp), %rdi
callq 0x4560
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x4720
movq -0x18(%rbp), %rax
movq 0x40(%rax), %rdi
leaq 0xced4(%rip), %rsi      # 0x15a67
callq 0x4580
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x1d9(%rbp)
jne 0x8c7c
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0xae60
movq %rax, -0x130(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0xaef0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x1d9(%rbp)
jne 0x8be6
jmp 0x8c7c
leaq -0x100(%rbp), %rdi
callq 0xae90
movq %rax, %rdi
addq $0x20, %rdi
callq 0x4200
movq %rax, %rdi
leaq 0xce92(%rip), %rsi      # 0x15a9a
callq 0x46c0
movl %eax, %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, -0x1d9(%rbp)
jne 0x8c7c
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rdi
callq 0xae60
movq %rax, -0x138(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0xaef0
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x1d9(%rbp)
jne 0x8c54
jmp 0x8c7c
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0xb0(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0x46c0
cmpl $0x0, %eax
sete %al
movb %al, -0x1d9(%rbp)
movb -0x1d9(%rbp), %al
testb $0x1, %al
jne 0x8c8b
jmp 0x8efd
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x4390
movq -0x18(%rbp), %rax
movl $0x65, 0x78(%rax)
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
movl $0x80, %edx
callq 0x4290
leaq -0xc0(%rbp), %rdi
callq 0xae90
movq %rax, %rdi
addq $0x20, %rdi
callq 0x4200
movq %rax, -0x1f0(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0xae90
movq %rax, %rdi
addq $0x20, %rdi
callq 0x4200
movq %rax, %rdi
callq 0x4220
movq -0x1f0(%rbp), %rdi
movl %eax, %esi
leaq -0xb0(%rbp), %rdx
callq 0x5100
movl $0x30, %edi
callq 0x44f0
movq %rax, %rdi
movq %rdi, -0x1e8(%rbp)
xorl %esi, %esi
movl $0x30, %edx
callq 0x4290
movq -0x1e8(%rbp), %rdi
callq 0xaf90
movq -0x1e8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x18(%rbp), %rax
cmpq $0x0, 0x80(%rax)
jne 0x8e25
movq -0x18(%rbp), %rax
movl $0x1f4, 0x78(%rax)      # imm = 0x1F4
movq -0x18(%rbp), %rdi
callq 0x4390
movq -0x18(%rbp), %rdi
callq 0x6c70
movq -0x18(%rbp), %rdi
callq 0x4720
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x87b0
movq -0x18(%rbp), %rdi
addq $0x78, %rdi
callq 0x90a0
jmp 0x906c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
jmp 0x8dd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x42f0
leaq -0xe1(%rbp), %rdi
callq 0x4560
jmp 0x908a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
jmp 0x8e14
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x42f0
leaq -0x121(%rbp), %rdi
callq 0x4560
jmp 0x908a
movq -0x18(%rbp), %rax
movq 0x80(%rax), %rax
movq %rax, -0x210(%rbp)
leaq 0xb750(%rip), %rsi      # 0x1458e
leaq -0x178(%rbp), %rdi
movq %rdi, -0x208(%rbp)
leaq -0xb0(%rbp), %rdx
callq 0xb100
movq -0x210(%rbp), %rdi
movq -0x208(%rbp), %rsi
callq 0xafb0
movb %dl, -0x1f9(%rbp)
movq %rax, -0x1f8(%rbp)
jmp 0x8e7a
movb -0x1f9(%rbp), %al
movq -0x1f8(%rbp), %rcx
movq %rcx, -0x188(%rbp)
movb %al, -0x180(%rbp)
leaq -0x178(%rbp), %rdi
callq 0xb0d0
movq -0x18(%rbp), %rdi
callq 0x4390
movq -0x18(%rbp), %rdi
callq 0x6c70
movq -0x18(%rbp), %rdi
callq 0x4720
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x87b0
movq -0x18(%rbp), %rdi
addq $0x78, %rdi
callq 0x90a0
jmp 0x906c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf0(%rbp)
movl %eax, -0xf4(%rbp)
leaq -0x178(%rbp), %rdi
callq 0xb0d0
jmp 0x908a
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x4390
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
cmpq $0x0, 0x88(%rax)
je 0x9028
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x88(%rax), %rax
movq %rax, -0x190(%rbp)
movl $0x30, %edi
callq 0x44f0
movq %rax, %rdi
movq %rdi, -0x218(%rbp)
xorl %esi, %esi
movl $0x30, %edx
callq 0x4290
movq -0x218(%rbp), %rdi
callq 0xaf90
movq -0x218(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x18(%rbp), %rdi
callq 0x4390
movq -0x190(%rbp), %rax
movq -0x18(%rbp), %rdi
callq *%rax
movq -0x20(%rbp), %rdi
addq $0x28, %rdi
callq 0x4720
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rdi
leaq -0x28(%rbp), %rsi
callq 0xb1e0
movq %rax, -0x198(%rbp)
movq -0x20(%rbp), %rax
movq 0x50(%rax), %rdi
callq 0xb240
movq %rax, -0x1a0(%rbp)
leaq -0x1a0(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0xb210
testb $0x1, %al
jne 0x8fdc
jmp 0x8ff6
movq -0x20(%rbp), %rdi
addq $0x28, %rdi
callq 0x4390
movq $0x0, -0x8(%rbp)
jmp 0x907d
movq -0x20(%rbp), %rdi
addq $0x28, %rdi
callq 0x4390
movq -0x18(%rbp), %rdi
callq 0x4720
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x87b0
movq -0x18(%rbp), %rdi
addq $0x78, %rdi
callq 0x90a0
jmp 0x9068
movq -0x18(%rbp), %rax
movl $0x1f7, 0x78(%rax)      # imm = 0x1F7
movq -0x18(%rbp), %rdi
callq 0x4390
movq -0x18(%rbp), %rdi
callq 0x6c70
movq -0x18(%rbp), %rdi
callq 0x4720
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x87b0
movq -0x18(%rbp), %rdi
addq $0x78, %rdi
callq 0x90a0
jmp 0x906a
jmp 0x906c
movq -0x18(%rbp), %rdi
callq 0x4390
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
movq -0xf0(%rbp), %rdi
callq 0x4830
nopw %cs:(%rax,%rax)