// File: /workspace/github_cpp_makefile_star2_O2/huanghuide[P]SimpleNetworkTunnel/InnerInitiator.cpp
// Function: InnerInitiator::Init()
void InnerInitiator::Init()
{
    mSockFd = socket(AF_INET, SOCK_STREAM, 0);
    if (mSockFd < 0)
    {
        gLog.Write("Inner Initiator socket error!");
        exit(1);
    }

    // Set the timeout for sending and receiving
    struct timeval timeout = {3, 0};  
    
    int flags = setsockopt(mSockFd, SOL_SOCKET, SO_SNDTIMEO, (char *)&timeout, sizeof(struct timeval));
    if (flags != 0)
    {
        gLog.Write("Set socket send timeout error!");        
        exit(1); 
    }

    flags = setsockopt(mSockFd, SOL_SOCKET, SO_RCVTIMEO, (char *)&timeout, sizeof(struct timeval));
    if (flags != 0)
    {
        gLog.Write("Set socket receiving timeout error!");        
        exit(1);
    }

    // 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!");        
        exit(1);
    }

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

    // 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!");        
        exit(1);
    }


    bzero(&mAddr, sizeof(mAddr));
    
    mAddr.sin_family = AF_INET;
    mAddr.sin_port = htons(mListenPort);
    mAddr.sin_addr.s_addr = htonl(INADDR_ANY);

    // Reuse the socket
    int reuseFlag = 1;
    if (setsockopt(mSockFd, SOL_SOCKET, SO_REUSEADDR, (const char*)&reuseFlag, sizeof(int)) != 0)
    {
        gLog.Write("Cannot reuse the socket");
        
        exit(1);
    }

    // Bind the socket
    if (bind(mSockFd, (sockaddr*)&mAddr, mAddrLen) != 0)
    {
        gLog.Write("Inner Initiator bind socket error!");

        exit(1);
    }

    // Listen the socket
    if (listen(mSockFd, 256) != 0)
    {
        gLog.Write("Inner Initiator listen socket error!");

        exit(1);
    }

    // Add into runner manager
    AddSockFdIntoSet(mSockFd);   
    gRunnerManager.AddRunner(mSockFd, this);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %rbx
pushq $0x2
popq %rdi
pushq $0x1
popq %rsi
xorl %edx, %edx
callq 0x20c0
movl %eax, 0xc(%rbx)
testl %eax, %eax
js 0x2c0f
movups 0x2704(%rip), %xmm0     # 0x51e0
leaq -0x30(%rbp), %rcx
movaps %xmm0, (%rcx)
pushq $0x1
popq %rsi
pushq $0x15
popq %rdx
pushq $0x10
popq %r8
movl %eax, %edi
callq 0x23b0
testl %eax, %eax
jne 0x2c45
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
jne 0x2c7b
leaq -0x10(%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
jne 0x2cb1
movl 0xc(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
leaq -0x10(%rbp), %rcx
pushq $0x4
popq %r8
callq 0x23b0
testl %eax, %eax
jne 0x2ce7
leaq -0x14(%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
jne 0x2d1d
andq $0x0, 0x30(%rbx)
movw $0x2, 0x28(%rbx)
movzwl 0x3c(%rbx), %eax
rolw $0x8, %ax
movw %ax, 0x2a(%rbx)
andl $0x0, 0x2c(%rbx)
leaq -0x18(%rbp), %rcx
movl $0x1, (%rcx)
movl 0xc(%rbx), %edi
pushq $0x1
popq %rsi
pushq $0x2
popq %rdx
pushq $0x4
popq %r8
callq 0x23b0
testl %eax, %eax
jne 0x2d53
leaq 0x28(%rbx), %rsi
movl 0xc(%rbx), %edi
movl 0x38(%rbx), %edx
callq 0x2060
testl %eax, %eax
jne 0x2d86
movl 0xc(%rbx), %edi
movl $0x100, %esi            # imm = 0x100
callq 0x22d0
testl %eax, %eax
jne 0x2db0
movl 0xc(%rbx), %edi
callq 0x26c1
movl 0xc(%rbx), %esi
leaq 0x7273(%rip), %rdi      # 0x9e70
movq %rbx, %rdx
callq 0x45b6
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %rbp
retq
leaq 0x24a0(%rip), %rsi      # 0x50b6
leaq -0x150(%rbp), %rdi
leaq -0x30(%rbp), %rdx
callq 0x28e4
leaq 0x723b(%rip), %rdi      # 0x9e68
leaq -0x150(%rbp), %rsi
callq 0x355c
leaq -0x150(%rbp), %rdi
jmp 0x2dd8
leaq 0x2488(%rip), %rsi      # 0x50d4
leaq -0x130(%rbp), %rdi
leaq -0x10(%rbp), %rdx
callq 0x28e4
leaq 0x7205(%rip), %rdi      # 0x9e68
leaq -0x130(%rbp), %rsi
callq 0x355c
leaq -0x130(%rbp), %rdi
jmp 0x2dd8
leaq 0x2471(%rip), %rsi      # 0x50f3
leaq -0x110(%rbp), %rdi
leaq -0x10(%rbp), %rdx
callq 0x28e4
leaq 0x71cf(%rip), %rdi      # 0x9e68
leaq -0x110(%rbp), %rsi
callq 0x355c
leaq -0x110(%rbp), %rdi
jmp 0x2dd8
leaq 0x245f(%rip), %rsi      # 0x5117
leaq -0xf0(%rbp), %rdi
leaq -0x14(%rbp), %rdx
callq 0x28e4
leaq 0x7199(%rip), %rdi      # 0x9e68
leaq -0xf0(%rbp), %rsi
callq 0x355c
leaq -0xf0(%rbp), %rdi
jmp 0x2dd8
leaq 0x244a(%rip), %rsi      # 0x5138
leaq -0xd0(%rbp), %rdi
leaq -0x14(%rbp), %rdx
callq 0x28e4
leaq 0x7163(%rip), %rdi      # 0x9e68
leaq -0xd0(%rbp), %rsi
callq 0x355c
leaq -0xd0(%rbp), %rdi
jmp 0x2dd8
leaq 0x2437(%rip), %rsi      # 0x515b
leaq -0xb0(%rbp), %rdi
leaq -0x18(%rbp), %rdx
callq 0x28e4
leaq 0x712d(%rip), %rdi      # 0x9e68
leaq -0xb0(%rbp), %rsi
callq 0x355c
leaq -0xb0(%rbp), %rdi
jmp 0x2dd8
leaq 0x2420(%rip), %rsi      # 0x517a
leaq -0x90(%rbp), %rdi
leaq -0x9(%rbp), %rdx
callq 0x28e4
leaq 0x70f7(%rip), %rdi      # 0x9e68
leaq -0x90(%rbp), %rsi
callq 0x355c
leaq -0x90(%rbp), %rdi
jmp 0x2dd8
leaq 0x2405(%rip), %rsi      # 0x5192
leaq -0x70(%rbp), %rdi
leaq -0x9(%rbp), %rdx
callq 0x28e4
leaq 0x70c7(%rip), %rdi      # 0x9e68
leaq -0x70(%rbp), %rsi
callq 0x355c
leaq -0x70(%rbp), %rdi
jmp 0x2dd8
leaq 0x23fe(%rip), %rsi      # 0x51b5
leaq -0x50(%rbp), %rdi
leaq -0x9(%rbp), %rdx
callq 0x28e4
leaq 0x709d(%rip), %rdi      # 0x9e68
leaq -0x50(%rbp), %rsi
callq 0x355c
leaq -0x50(%rbp), %rdi
callq 0x2140
pushq $0x1
popq %rdi
callq 0x2310
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
jmp 0x2e49
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
jmp 0x2e49
movq %rax, %rbx
leaq -0x90(%rbp), %rdi
jmp 0x2e49
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x2e49
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
jmp 0x2e49
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
jmp 0x2e49
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
jmp 0x2e49
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
jmp 0x2e49
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0x2140
jmp 0x2e63
jmp 0x2e60
jmp 0x2e60
jmp 0x2e60
jmp 0x2e60
jmp 0x2e60
jmp 0x2e60
jmp 0x2e60
jmp 0x2e60
movq %rax, %rbx
movq %rbx, %rdi
callq 0x23a0
nop