// File: /workspace/github_cpp_makefile_star2_O3/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 0x48ca
movl $0x2, %edi
movl $0x1, %esi
xorl %edx, %edx
callq 0x20b0
movl %eax, 0xc(%rbx)
testl %eax, %eax
jns 0x46e2
leaq -0xa0(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x1b3f(%rip), %rsi      # 0x61d6
leaq 0x1b3e(%rip), %rdx      # 0x61dc
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
callq 0x2a2e
leaq 0x67a4(%rip), %rdi      # 0xae58
movq %r14, %rsi
callq 0x387c
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x46d7
movq -0xa0(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x4398
movl 0xc(%rbx), %eax
leaq 0x6777(%rip), %rdi      # 0xae60
movl %eax, %esi
movq %rbx, %rdx
callq 0x4bdc
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 0x1b07(%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 0x474f
movq %rbx, %rdi
callq 0x4398
movl 0xc(%rbx), %edi
leaq -0x90(%rbp), %rcx
movl $0x1, %esi
movl $0x14, %edx
movl $0x10, %r8d
callq 0x2390
testl %eax, %eax
je 0x477a
movq %rbx, %rdi
callq 0x4398
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 0x47ec
leaq -0x70(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x19b3(%rip), %rsi      # 0x6162
leaq 0x19cc(%rip), %rdx      # 0x6182
leaq -0x80(%rbp), %rdi
callq 0x2a2e
leaq 0x6692(%rip), %rdi      # 0xae58
leaq -0x80(%rbp), %rsi
callq 0x387c
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x47e4
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x4398
movl 0xc(%rbx), %edi
leaq -0x1c(%rbp), %rcx
movl $0x1, %esi
movl $0x8, %edx
movl $0x4, %r8d
callq 0x2390
testl %eax, %eax
je 0x4858
leaq -0x50(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1968(%rip), %rsi      # 0x6183
leaq 0x1983(%rip), %rdx      # 0x61a5
leaq -0x60(%rbp), %rdi
callq 0x2a2e
leaq 0x6626(%rip), %rdi      # 0xae58
leaq -0x60(%rbp), %rsi
callq 0x387c
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x4850
movq -0x50(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x4398
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 0x48ca
leaq -0x30(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x1919(%rip), %rsi      # 0x61a6
leaq 0x1930(%rip), %rdx      # 0x61c4
leaq -0x40(%rbp), %rdi
callq 0x2a2e
leaq 0x65b4(%rip), %rdi      # 0xae58
leaq -0x40(%rbp), %rsi
callq 0x387c
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x48c2
movq -0x30(%rbp), %rsi
incq %rsi
callq 0x2290
movq %rbx, %rdi
callq 0x4398
leaq -0x90(%rbp), %r14
movq $0x0, 0x8(%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 0x4925
callq 0x2040
movl (%rax), %edx
leal -0x72(%rdx), %eax
cmpl $0x2, %eax
jae 0x4939
movl $0x1, 0x30(%rbx)
jmp 0x4974
movl 0xc(%rbx), %esi
leaq 0x6531(%rip), %rdi      # 0xae60
movq %rbx, %rdx
callq 0x4bdc
jmp 0x4946
cmpl $0x6a, %edx
jne 0x4957
movq %rbx, %rdi
callq 0x49e8
movl $0x2, 0x30(%rbx)
movq %rbx, %rdi
callq 0x49e8
jmp 0x4974
leaq 0x64fa(%rip), %rdi      # 0xae58
leaq 0x1aa1(%rip), %rsi      # 0x6406
xorl %eax, %eax
callq 0x392c
movq %rbx, %rdi
callq 0x4398
addq $0x98, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
cmpq %r15, %rdi
je 0x49df
movq -0xa0(%rbp), %rsi
jmp 0x49d2
movq %rax, %rbx
movq -0x40(%rbp), %rdi
cmpq %r14, %rdi
je 0x49df
movq -0x30(%rbp), %rsi
jmp 0x49d2
jmp 0x49dc
movq %rax, %rbx
movq -0x60(%rbp), %rdi
cmpq %r14, %rdi
je 0x49df
movq -0x50(%rbp), %rsi
jmp 0x49d2
jmp 0x49dc
movq %rax, %rbx
movq -0x80(%rbp), %rdi
cmpq %r14, %rdi
je 0x49df
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2290
jmp 0x49df
movq %rax, %rbx
movq %rbx, %rdi
callq 0x2380
nop