// File: /workspace/github_cpp_makefile_star2_O1/huanghuide[P]SimpleNetworkTunnel/InnerRunner.cpp
// Function: InnerRunner::SocketRead(int)
void InnerRunner::SocketRead(int sockFd)
{
    bool successFlag = false;

    char buf[MSG_LEN];
    int recvLen = 0;

    while (true)
    {
        recvLen = recv(mSockFd, buf, MSG_LEN, 0);

        if (recvLen > 0)
        {
            if (mOuterRunner == NULL)
            {
                mOuterRunner = new OuterRunner(this);
            }

        	if ((gRoleType == MIDDLE) || (gRoleType == SERVER))
        	{
        		for (int index = 0; index < recvLen; index++)
        		{
        			buf[index] = buf[index] ^ SIMPLE_XOR_VALUE;
        		}
        	}

            //printf("INNER: Receive message from client. SockFd %d, length %d\n", mSockFd, recvLen);
            //PrintBuf(buf, recvLen);
            
            ProcessDataMessage(buf, recvLen);
            successFlag = true;

            break;
        }
        else if (recvLen == 0)
        {
            // socket is closed normally
            successFlag = false;
            
            break;
        }
        else
        {
            if ((errno == EWOULDBLOCK) || (errno == EINTR) || (errno == EINPROGRESS)) 
            {
                usleep(1000);
                continue;
            }
            else 
            {
                gLog.Write("InnerRunner::SocketRead: socket closed abnormally. errno %d\n", errno);
                successFlag = false;
                
                break;
            }
        }
    }

    if (!successFlag)
    {
        ClearAll();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x800, %rsp            # imm = 0x800
movq %rdi, %rbx
movl 0xc(%rdi), %edi
leaq -0x820(%rbp), %rsi
movl $0x800, %edx            # imm = 0x800
xorl %ecx, %ecx
callq 0x20e0
movq %rax, %r14
testl %r14d, %r14d
setg %r12b
jg 0x3371
leaq -0x820(%rbp), %r15
testl %r14d, %r14d
je 0x33d8
callq 0x2040
movl (%rax), %edx
cmpl $0x4, %edx
je 0x3349
cmpl $0x73, %edx
je 0x3349
cmpl $0xb, %edx
jne 0x340e
movl $0x3e8, %edi            # imm = 0x3E8
callq 0x2330
movl 0xc(%rbx), %edi
movl $0x800, %edx            # imm = 0x800
movq %r15, %rsi
xorl %ecx, %ecx
callq 0x20e0
movq %rax, %r14
testl %r14d, %r14d
setg %r12b
jle 0x3326
cmpq $0x0, 0x28(%rbx)
jne 0x3394
movl $0x60, %edi
callq 0x2270
movq %rax, %r15
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4210
movq %r15, 0x28(%rbx)
leaq 0x5e5d(%rip), %rax      # 0x91f8
movl (%rax), %eax
decl %eax
cmpl $0x1, %eax
ja 0x33c0
cmpl $0x1, %r14d
movl %r14d, %eax
adcl $0x0, %eax
xorl %ecx, %ecx
xorb $-0x5b, -0x820(%rbp,%rcx)
incq %rcx
cmpq %rcx, %rax
jne 0x33b0
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x33d8
leaq -0x820(%rbp), %rsi
movl %r14d, %edx
callq 0x466a
testb $0x1, %r12b
jne 0x33fe
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x33f5
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x28(%rbx)
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
addq $0x800, %rsp            # imm = 0x800
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7a43(%rip), %rdi      # 0xae58
leaq 0x2e2d(%rip), %rsi      # 0x6249
xorl %eax, %eax
callq 0x3974
jmp 0x33d8
movq %rax, %rbx
movl $0x60, %esi
movq %r15, %rdi
callq 0x2290
movq %rbx, %rdi
callq 0x2380
nop