// File: /workspace/github_cpp_makefile_star2_O1/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 %r15
pushq %r14
pushq %rbx
subq $0x98, %rsp
movq %rdi, %rbx
cmpl $0x0, 0xc(%rdi)
jg 0x4960
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x20b0
movl %eax, 0xc(%rbx)
testl %eax, %eax
jns 0x4777
leaq -0xa0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1aa7(%rip), %rsi      # 0x61d6
leaq 0x1aa6(%rip), %rdx      # 0x61dc
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
callq 0x2a2c
leaq 0x670c(%rip), %rdi      # 0xae58
movq %r14, %rsi
callq 0x38c4
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x476f
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x442a
movl 0xc(%rbx), %esi
leaq 0x66df(%rip), %rdi      # 0xae60
movq %rbx, %rdx
callq 0x4c80
movl 0xc(%rbx), %edi
movl $0x3, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x2190
movl 0xc(%rbx), %edi
orl $0x800, %eax            # imm = 0x800
movl $0x4, %esi
movl %eax, %edx
xorl %eax, %eax
callq 0x2190
movups 0x1a71(%rip), %xmm0     # 0x6228
leaq -0x90(%rbp), %rcx
movaps %xmm0, (%rcx)
movl 0xc(%rbx), %edi
movl $0x1, %esi
movl $0x15, %edx
movl $0x10, %r8d
callq 0x2390
testl %eax, %eax
je 0x47e5
movq %rbx, %rdi
callq 0x442a
movl 0xc(%rbx), %edi
leaq -0x90(%rbp), %rcx
movl $0x1, %esi
movl $0x14, %edx
movl $0x10, %r8d
callq 0x2390
testl %eax, %eax
je 0x4810
movq %rbx, %rdi
callq 0x442a
leaq -0x1c(%rbp), %rcx
movl $0x40000, (%rcx)        # imm = 0x40000
movl 0xc(%rbx), %edi
movl $0x1, %esi
movl $0x7, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
je 0x4882
leaq -0x70(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x191d(%rip), %rsi      # 0x6162
leaq 0x1936(%rip), %rdx      # 0x6182
leaq -0x80(%rbp), %rdi
callq 0x2a2c
leaq 0x65fc(%rip), %rdi      # 0xae58
leaq -0x80(%rbp), %rsi
callq 0x38c4
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x487a
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x442a
movl 0xc(%rbx), %edi
leaq -0x1c(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
je 0x48ee
leaq -0x50(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x18d2(%rip), %rsi      # 0x6183
leaq 0x18ed(%rip), %rdx      # 0x61a5
leaq -0x60(%rbp), %rdi
callq 0x2a2c
leaq 0x6590(%rip), %rdi      # 0xae58
leaq -0x60(%rbp), %rsi
callq 0x38c4
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x48e6
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x442a
leaq -0x20(%rbp), %rcx
movl $0x1, (%rcx)
movl 0xc(%rbx), %edi
movl $0x6, %esi
movl $0x1, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
je 0x4960
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1883(%rip), %rsi      # 0x61a6
leaq 0x189a(%rip), %rdx      # 0x61c4
leaq -0x40(%rbp), %rdi
callq 0x2a2c
leaq 0x651e(%rip), %rdi      # 0xae58
leaq -0x40(%rbp), %rsi
callq 0x38c4
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x4958
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x442a
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %r14
movaps %xmm0, (%r14)
movw $0x2, (%r14)
movzwl 0x58(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x2(%r14)
movq 0x38(%rbx), %rdi
callq 0x2280
movl %eax, 0x4(%r14)
movl 0xc(%rbx), %edi
movq %r14, %rsi
movl $0x10, %edx
callq 0x2210
testl %eax, %eax
je 0x49ba
callq 0x2040
movl (%rax), %edx
leal -0x72(%rdx), %eax
cmpl $0x2, %eax
jae 0x49ce
movl $0x1, 0x30(%rbx)
jmp 0x4a09
movl 0xc(%rbx), %esi
leaq 0x649c(%rip), %rdi      # 0xae60
movq %rbx, %rdx
callq 0x4c80
jmp 0x49db
cmpl $0x6a, %edx
jne 0x49ec
movq %rbx, %rdi
callq 0x4a7c
movl $0x2, 0x30(%rbx)
movq %rbx, %rdi
callq 0x4a7c
jmp 0x4a09
leaq 0x6465(%rip), %rdi      # 0xae58
leaq 0x1a0c(%rip), %rsi      # 0x6406
xorl %eax, %eax
callq 0x3974
movq %rbx, %rdi
callq 0x442a
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x4a74
movq -0xa0(%rbp), %rsi
jmp 0x4a67
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x4a74
movq -0x30(%rbp), %rsi
jmp 0x4a67
jmp 0x4a71
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x4a74
movq -0x50(%rbp), %rsi
jmp 0x4a67
jmp 0x4a71
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x4a74
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2290
jmp 0x4a74
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2380