// File: /workspace/github_cpp_makefile_star2_O2/huanghuide[P]SimpleNetworkTunnel/OuterRunner.cpp
// Function: OuterRunner::ProcessInitStatus()
void OuterRunner::ProcessInitStatus()
{
    if (mSockFd <= 0)
    {
        mSockFd = socket(AF_INET, SOCK_STREAM, 0);
        if (mSockFd < 0)
        {
            gLog.Write("socket");
            HandleError();
        }

        gRunnerManager.AddRunner(mSockFd, this);

        // Set as non-block socket
        int flags = fcntl(mSockFd, F_GETFL, 0);
        fcntl(mSockFd, F_SETFL, flags | O_NONBLOCK);

        // Set the timeout for sending and receiving
        struct timeval timeout = {3, 0};  
        
        flags = setsockopt(mSockFd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(struct timeval));
        if (flags != 0)
        {
            HandleError();  
        }

        flags = setsockopt(mSockFd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval));
        if (flags != 0)
        {
            HandleError();  
        }

        // Set the send and recv buffer
        int bufSize = TCP_SOCK_BUF_SIZE;
        int bufLen = sizeof(int);

        flags = setsockopt(mSockFd, SOL_SOCKET, SO_SNDBUF, (char *)&bufSize, bufLen);
        if (flags != 0)
        {
            gLog.Write("Set socket sending buffer error!");        
            HandleError();  
        }

        flags = setsockopt(mSockFd, SOL_SOCKET, SO_RCVBUF, (char *)&bufSize, bufLen);
        if (flags != 0)
        {
            gLog.Write("Set socket receiving buffer error!");        
            HandleError();  
        }

        // Disable Nagle algorithm
        int enable = 1;
        flags = setsockopt(mSockFd, IPPROTO_TCP, TCP_NODELAY, (void*)&enable, sizeof(enable));
        if (flags != 0)
        {
            gLog.Write("Disable NAGLE algorithm error!");        
            HandleError();  
        }
    }

    struct sockaddr_in addr;
    
    bzero(&addr, sizeof(addr));
    addr.sin_family = AF_INET;
    addr.sin_port = htons(mDstPort);
    addr.sin_addr.s_addr = inet_addr(mDstIpAddr.c_str());

    int retConn = connect(mSockFd, (sockaddr*)&addr, sizeof(addr));
    
    if (retConn != 0)
    {
        if ((errno == EINPROGRESS) || (errno == EALREADY))
        {
            mSendStatus = CONNECTING;
        }
        else if (errno == EISCONN)
        {
            ProcessEstablishedStatus();
            mSendStatus = ESTABLISHED;

            ProcessEstablishedStatus();
        }
        else
        {
            gLog.Write("OuterRunner::ProcessConnectingStatus: errno %d\n", errno);
            HandleError();                
        }
    }
    else
    {
        gRunnerManager.AddRunner(mSockFd, this);

        mSendStatus = ESTABLISHED;

        ProcessEstablishedStatus();
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xa0, %rsp
movq %rdi, %rbx
cmpl $0x0, 0xc(%rdi)
jg 0x433e
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x20c0
movl %eax, 0xc(%rbx)
testl %eax, %eax
jns 0x41ba
leaq 0x100b(%rip), %rsi      # 0x518b
leaq -0xb0(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x28e4
leaq 0x5cd1(%rip), %rdi      # 0x9e68
leaq -0xb0(%rbp), %rsi
callq 0x355c
leaq -0xb0(%rbp), %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x3eba
movl 0xc(%rbx), %eax
leaq 0x5caf(%rip), %rdi      # 0x9e70
movl %eax, %esi
movq %rbx, %rdx
callq 0x45b6
movl 0xc(%rbx), %edi
pushq $0x3
popq %rsi
xorl %edx, %edx
xorl %eax, %eax
callq 0x21a0
movl 0xc(%rbx), %edi
orl $0x800, %eax            # imm = 0x800
pushq $0x4
popq %rsi
movl %eax, %edx
xorl %eax, %eax
callq 0x21a0
movups 0xfeb(%rip), %xmm0      # 0x51e0
leaq -0x30(%rbp), %rcx
movaps %xmm0, (%rcx)
movl 0xc(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x15
popq %rdx
pushq $0x10
popq %r8
callq 0x23b0
testl %eax, %eax
je 0x421a
movq %rbx, %rdi
callq 0x3eba
movl 0xc(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x14
popq %rdx
leaq -0x30(%rbp), %rcx
pushq $0x10
popq %r8
callq 0x23b0
testl %eax, %eax
je 0x423c
movq %rbx, %rdi
callq 0x3eba
leaq -0x1c(%rbp), %rcx
movl $0x40000, (%rcx)        # imm = 0x40000
movl 0xc(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x7
popq %rdx
pushq $0x4
popq %r8
callq 0x23b0
testl %eax, %eax
je 0x429a
leaq 0xeb4(%rip), %rsi       # 0x5117
leaq -0x90(%rbp), %rdi
leaq -0x18(%rbp), %rdx
callq 0x28e4
leaq 0x5bee(%rip), %rdi      # 0x9e68
leaq -0x90(%rbp), %rsi
callq 0x355c
leaq -0x90(%rbp), %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x3eba
movl 0xc(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
leaq -0x1c(%rbp), %rcx
pushq $0x4
popq %r8
callq 0x23b0
testl %eax, %eax
je 0x42e9
leaq 0xe7d(%rip), %rsi       # 0x5138
leaq -0x70(%rbp), %rdi
leaq -0x18(%rbp), %rdx
callq 0x28e4
leaq 0x5b99(%rip), %rdi      # 0x9e68
leaq -0x70(%rbp), %rsi
callq 0x355c
leaq -0x70(%rbp), %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x3eba
leaq -0x18(%rbp), %rcx
movl $0x1, (%rcx)
movl 0xc(%rbx), %edi
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
pushq $0x4
popq %r8
callq 0x23b0
testl %eax, %eax
je 0x433e
leaq 0xe4b(%rip), %rsi       # 0x515b
leaq -0x50(%rbp), %rdi
leaq -0x11(%rbp), %rdx
callq 0x28e4
leaq 0x5b44(%rip), %rdi      # 0x9e68
leaq -0x50(%rbp), %rsi
callq 0x355c
leaq -0x50(%rbp), %rdi
callq 0x2140
movq %rbx, %rdi
callq 0x3eba
leaq -0x30(%rbp), %r14
andq $0x0, 0x8(%r14)
movw $0x2, (%r14)
movzwl 0x58(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r14)
movq 0x38(%rbx), %rdi
callq 0x2290
movl %eax, 0x4(%r14)
movl 0xc(%rbx), %edi
pushq $0x10
popq %rdx
movq %r14, %rsi
callq 0x2220
testl %eax, %eax
je 0x4391
callq 0x2040
movl (%rax), %edx
leal -0x72(%rdx), %eax
cmpl $0x2, %eax
jae 0x43a5
movl $0x1, 0x30(%rbx)
jmp 0x43e0
movl 0xc(%rbx), %esi
leaq 0x5ad5(%rip), %rdi      # 0x9e70
movq %rbx, %rdx
callq 0x45b6
jmp 0x43b2
cmpl $0x6a, %edx
jne 0x43c3
movq %rbx, %rdi
callq 0x442c
movl $0x2, 0x30(%rbx)
movq %rbx, %rdi
callq 0x442c
jmp 0x43e0
leaq 0x5a9e(%rip), %rdi      # 0x9e68
leaq 0xfed(%rip), %rsi       # 0x53be
xorl %eax, %eax
callq 0x360c
movq %rbx, %rdi
callq 0x3eba
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x441a
jmp 0x4421
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0x441a
jmp 0x4421
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x441a
jmp 0x4421
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
callq 0x2140
jmp 0x4424
movq %rax, %rbx
movq %rbx, %rdi
callq 0x23a0