// File: /workspace/github_c_makefile_star2_O0/sszllzss[P]webSocket_Libevent_ThreadPool/websocket_common.c
// Function: webSocket_recv(int, unsigned char*, unsigned int)
int webSocket_recv(int fd, 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 = recv(fd, recvBuf, dataMaxLen, MSG_NOSIGNAL);
    if(ret > 0)
    {
        //------------------------------------------------------------------------------------------------------------- 和客户端的连接操作
        if(strncmp((char *)recvBuf, "GET", 3) == 0)
        {
            ret2 = webSocket_serverLinkToClient(fd,(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
        {
            webSocket_send(fd, 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
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x14(%rbp), %eax
movl %eax, %esi
shlq $0x0, %rsi
movl $0x1, %edi
callq 0x2170
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2130
movl -0x8(%rbp), %edi
movq -0x28(%rbp), %rsi
movl -0x14(%rbp), %eax
movl %eax, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x20d0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
jle 0x3ec7
movq -0x28(%rbp), %rdi
leaq 0x15f6(%rip), %rsi      # 0x52fb
movl $0x3, %edx
callq 0x2110
cmpl $0x0, %eax
jne 0x3d8d
movl -0x8(%rbp), %edi
movq -0x28(%rbp), %rsi
movl -0x2c(%rbp), %edx
callq 0x3ac0
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x2240
cmpl $0x0, -0x30(%rbp)
jge 0x3d61
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2130
movq -0x10(%rbp), %rdi
leaq 0x15af(%rip), %rsi      # 0x52ff
callq 0x21e0
movl $0x11, -0x4(%rbp)
jmp 0x3ed6
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2130
movq -0x10(%rbp), %rdi
leaq 0x1595(%rip), %rsi      # 0x5311
callq 0x21e0
movl $0xd, -0x4(%rbp)
jmp 0x3ed6
movl -0x2c(%rbp), %eax
addl $0x80, %eax
movslq %eax, %rsi
shlq $0x0, %rsi
movl $0x1, %edi
callq 0x2170
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rdi
movl -0x2c(%rbp), %eax
addl $0x80, %eax
movslq %eax, %rdx
xorl %esi, %esi
callq 0x2130
movq -0x28(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq -0x20(%rbp), %rdx
movl -0x2c(%rbp), %ecx
addl $0x80, %ecx
leaq -0x34(%rbp), %r8
callq 0x31d0
movl %eax, -0x30(%rbp)
cmpl $-0x10, -0x30(%rbp)
jne 0x3e65
cmpl $0x0, -0x34(%rbp)
jbe 0x3e65
movl -0x8(%rbp), %edi
movq -0x20(%rbp), %rsi
movl -0x34(%rbp), %edx
movl $0x1, %ecx
movl $0xfffffff1, %r8d       # imm = 0xFFFFFFF1
callq 0x3be0
leaq 0x138e(%rip), %rdi      # 0x519b
leaq 0x16be(%rip), %rsi      # 0x54d2
leaq 0x13a3(%rip), %rdx      # 0x51be
movl $0x42b, %ecx            # imm = 0x42B
movb $0x0, %al
callq 0x2040
movl -0x34(%rbp), %esi
movq -0x20(%rbp), %rdx
leaq 0x14ea(%rip), %rdi      # 0x531f
movb $0x0, %al
callq 0x2040
leaq 0x14cb(%rip), %rdi      # 0x530e
movb $0x0, %al
callq 0x2040
movq -0x28(%rbp), %rdi
callq 0x2240
movq -0x20(%rbp), %rdi
callq 0x2240
movl $0x0, -0x4(%rbp)
jmp 0x3ed6
cmpl $0x0, -0x34(%rbp)
jbe 0x3ea9
cmpl $-0x13, -0x30(%rbp)
je 0x3e7d
cmpl $-0x12, -0x30(%rbp)
je 0x3e7d
cmpl $-0x14, -0x30(%rbp)
jne 0x3ea9
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rsi
movl -0x34(%rbp), %eax
movl %eax, %edx
callq 0x21a0
movq -0x28(%rbp), %rdi
callq 0x2240
movq -0x20(%rbp), %rdi
callq 0x2240
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ed6
jmp 0x3eab
movq -0x28(%rbp), %rdi
callq 0x2240
movq -0x20(%rbp), %rdi
callq 0x2240
xorl %eax, %eax
subl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x3ed6
movq -0x28(%rbp), %rdi
callq 0x2240
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nop