// File: /workspace/github_c_makefile_star2_O0/sszllzss[P]webSocket_Libevent_ThreadPool/websocket_common.c
// Function: ev_webSocket_recv(bufferevent*, unsigned char*, unsigned int)
int ev_webSocket_recv(struct bufferevent * bufferev, unsigned char *data, unsigned int dataMaxLen)
{
    unsigned char *webSocketPackage, *recvBuf;
    int ret, ret2 = 0;
    unsigned int retLen = 0;
    //int i;

    recvBuf = (unsigned char *)calloc(1, sizeof(char)*dataMaxLen);  memset(recvBuf, 0, dataMaxLen);
    ret = bufferevent_read(bufferev, recvBuf, dataMaxLen);
    if(ret > 0)
    {
        //------------------------------------------------------------------------------------------------------------- 和客户端的连接操作
        if(strncmp((char *)recvBuf, "GET", 3) == 0)
        {
            
            ret2 = ev_webSocket_serverLinkToClient(bufferev,(char *) recvBuf, (unsigned int)ret);
            free(recvBuf);
            if(ret2 < 0)
            {
                memset(data, 0, dataMaxLen);
                strcpy((char*)data, "connect false !\r\n");
                return strlen("connect false !\r\n");
            }
            memset(data, 0, dataMaxLen);
            strcpy((char *)data, "connect ...\r\n");
            return strlen("connect ...\r\n");
        }

        //------------------------------------------------------------------------------------------------------------- 正常数据交换

        //printf("webSocket_recv : %d\r\n", ret);
        //---------- websocket数据打包 ----------
        webSocketPackage = (unsigned char *)calloc(1, sizeof(char)*(ret + 128));  memset(webSocketPackage, 0, (ret + 128));
        ret2 = webSocket_dePackage(recvBuf, ret, webSocketPackage, (ret + 128), &retLen);
        if(ret2 == WCT_PING && retLen > 0)      // 解析为ping包, 自动回pong
        {
            ev_webSocket_send(bufferev, webSocketPackage, retLen, true, WCT_PONG);
            // 显示数据
            De_printf("webSocket_recv : PING %d\r\n%s\r\n" , retLen, webSocketPackage); 
            free(recvBuf);
            free(webSocketPackage);
            return WCT_NULL;
        }
        else if(retLen > 0 && (ret2 == WCT_TXTDATA || ret2 == WCT_BINDATA || ret2 == WCT_MINDATA))  // 解析为数据包
        {
            memcpy(data, webSocketPackage, retLen);     // 把解析得到的数据复制出去
            /*
            // 显示数据
            if(webSocketPackage[0] >= ' ' && webSocketPackage[0] <= '~')
            { 
            printf("\r\nwebSocket_recv : New Package StrFile ret2:%d/retLen:%d\r\n%s\r\n" , ret2, retLen, webSocketPackage); 
            }
            else
            {
            printf("\r\nwebSocket_recv : New Package BinFile ret2:%d/retLen:%d\r\n" , ret2, retLen); 
            for(i = 0; i < retLen; i++) printf("%.2X ", webSocketPackage[i]); printf("\r\n");
            }*/
            free(recvBuf);
            free(webSocketPackage);
            return retLen;
        }/*
            else
            {
        // 显示数据
        if(recvBuf[0] >= ' ' && recvBuf[0] <= '~') 
        printf("\r\nwebSocket_recv : ret:%d/ret2:%d/retLen:%d\r\n%s\r\n" , ret, ret2, retLen, recvBuf); 
        else 
        {
        printf("\r\nwebSocket_recv : ret:%d/ret2:%d/retLen:%d\r\n%s\r\n" , ret, ret2, retLen, recvBuf); 
        for(i = 0; i < ret; i++) printf("%.2X ", recvBuf[i]); printf("\r\n");
        }
        }*/
        free(recvBuf);
        free(webSocketPackage);
        return -ret;
    }
    else
    {
        free(recvBuf);
        return ret;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl $0x0, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, %esi
shlq $0x0, %rsi
movl $0x1, %edi
callq 0x2170
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2130
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x1c(%rbp), %eax
movl %eax, %edx
callq 0x2350
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0x491a
movq -0x30(%rbp), %rdi
leaq 0xba9(%rip), %rsi       # 0x52fb
movl $0x3, %edx
callq 0x2110
cmpl $0x0, %eax
jne 0x47db
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x34(%rbp), %edx
callq 0x4510
movl %eax, -0x38(%rbp)
movq -0x30(%rbp), %rdi
callq 0x2240
cmpl $0x0, -0x38(%rbp)
jge 0x47af
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2130
movq -0x18(%rbp), %rdi
leaq 0xb61(%rip), %rsi       # 0x52ff
callq 0x21e0
movl $0x11, -0x4(%rbp)
jmp 0x4929
movq -0x18(%rbp), %rdi
movl -0x1c(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2130
movq -0x18(%rbp), %rdi
leaq 0xb47(%rip), %rsi       # 0x5311
callq 0x21e0
movl $0xd, -0x4(%rbp)
jmp 0x4929
movl -0x34(%rbp), %eax
addl $0x80, %eax
movslq %eax, %rsi
shlq $0x0, %rsi
movl $0x1, %edi
callq 0x2170
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl -0x34(%rbp), %eax
addl $0x80, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x2130
movq -0x30(%rbp), %rdi
movl -0x34(%rbp), %esi
movq -0x28(%rbp), %rdx
movl -0x34(%rbp), %ecx
addl $0x80, %ecx
leaq -0x3c(%rbp), %r8
callq 0x31d0
movl %eax, -0x38(%rbp)
cmpl $-0x10, -0x38(%rbp)
jne 0x48b8
cmpl $0x0, -0x3c(%rbp)
jbe 0x48b8
movq -0x10(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x3c(%rbp), %edx
movl $0x1, %ecx
movl $0xfffffff1, %r8d       # imm = 0xFFFFFFF1
callq 0x4630
leaq 0x93b(%rip), %rdi       # 0x519b
leaq 0xc68(%rip), %rsi       # 0x54cf
leaq 0x950(%rip), %rdx       # 0x51be
movl $0x537, %ecx            # imm = 0x537
movb $0x0, %al
callq 0x2040
movl -0x3c(%rbp), %esi
movq -0x28(%rbp), %rdx
leaq 0xa97(%rip), %rdi       # 0x531f
movb $0x0, %al
callq 0x2040
leaq 0xa78(%rip), %rdi       # 0x530e
movb $0x0, %al
callq 0x2040
movq -0x30(%rbp), %rdi
callq 0x2240
movq -0x28(%rbp), %rdi
callq 0x2240
movl $0x0, -0x4(%rbp)
jmp 0x4929
cmpl $0x0, -0x3c(%rbp)
jbe 0x48fc
cmpl $-0x13, -0x38(%rbp)
je 0x48d0
cmpl $-0x12, -0x38(%rbp)
je 0x48d0
cmpl $-0x14, -0x38(%rbp)
jne 0x48fc
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl -0x3c(%rbp), %eax
movl %eax, %edx
callq 0x21a0
movq -0x30(%rbp), %rdi
callq 0x2240
movq -0x28(%rbp), %rdi
callq 0x2240
movl -0x3c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4929
jmp 0x48fe
movq -0x30(%rbp), %rdi
callq 0x2240
movq -0x28(%rbp), %rdi
callq 0x2240
xorl %eax, %eax
subl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x4929
movq -0x30(%rbp), %rdi
callq 0x2240
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)